Skip to content

Commit a553864

Browse files
committed
add HttpSecurityCustomer
1 parent 1476fef commit a553864

File tree

25 files changed

+108
-39
lines changed

25 files changed

+108
-39
lines changed

example/example-app/example-app-cmd-domain/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-app</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-app/example-app-cmd-meta/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-app</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-app/example-app-query/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-app</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-example</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<packaging>pom</packaging>

example/example-domain/example-domain-leave/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-domain</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-domain/example-domain-user/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-domain</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-domain/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-example</artifactId>
8-
<version>3.4.3</version>
8+
<version>3.4.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

example/example-infra/example-infra-flow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>example-infra</artifactId>
8-
<version>3.4.3</version>
8+
<version>3.4.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

example/example-infra/example-infra-jpa/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>example-infra</artifactId>
8-
<version>3.4.3</version>
8+
<version>3.4.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

example/example-infra/example-infra-security/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-infra</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-infra/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-example</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<packaging>pom</packaging>

example/example-interface/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-example</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
</parent>
1111

1212
<artifactId>example-interface</artifactId>

example/example-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.4.3</version>
8+
<version>3.4.4</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</parent>
2020

2121
<artifactId>springboot-example</artifactId>
22-
<version>3.4.3</version>
22+
<version>3.4.4</version>
2323

2424
<name>springboot-example</name>
2525
<description>springboot-example project for Spring Boot</description>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>3.4.3</version>
15+
<version>3.4.4</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>

springboot-starter-data-authorization/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-parent</artifactId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-data-authorization</artifactId>

springboot-starter-data-fast/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.4.3</version>
8+
<version>3.4.4</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-flow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>

springboot-starter-security/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.4.3</version>
9+
<version>3.4.4</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter-security/src/main/java/com/codingapi/springboot/security/AutoConfiguration.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.codingapi.springboot.security.configurer.HttpSecurityConfigurer;
44
import com.codingapi.springboot.security.controller.VersionController;
5+
import com.codingapi.springboot.security.customer.DefaultHttpSecurityCustomer;
6+
import com.codingapi.springboot.security.customer.HttpSecurityCustomer;
57
import com.codingapi.springboot.security.dto.request.LoginRequest;
68
import com.codingapi.springboot.security.dto.response.LoginResponse;
79
import com.codingapi.springboot.security.filter.*;
@@ -21,6 +23,7 @@
2123
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2224
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
2325
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
26+
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
2427
import org.springframework.security.core.userdetails.User;
2528
import org.springframework.security.core.userdetails.UserDetails;
2629
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -89,28 +92,24 @@ public AuthenticationTokenFilter authenticationTokenFilter() {
8992
};
9093
}
9194

92-
9395
@Bean
9496
@ConditionalOnMissingBean
95-
public SecurityFilterChain filterChain(HttpSecurity security, TokenGateway tokenGateway, SecurityLoginHandler loginHandler,
96-
CodingApiSecurityProperties properties, AuthenticationTokenFilter authenticationTokenFilter) throws Exception {
97-
//disable basic auth
98-
security.httpBasic(AbstractHttpConfigurer::disable);
99-
100-
//before add addCorsMappings to enable cors.
101-
security.cors(httpSecurityCorsConfigurer -> {
102-
if (properties.isDisableCors()) {
103-
httpSecurityCorsConfigurer.disable();
104-
}
105-
});
106-
107-
security.csrf(httpSecurityCsrfConfigurer -> {
108-
if (properties.isDisableCsrf()) {
109-
httpSecurityCsrfConfigurer.disable();
110-
}
111-
});
97+
public HttpSecurityCustomer httpSecurityCustomer(CodingApiSecurityProperties properties){
98+
return new DefaultHttpSecurityCustomer(properties);
99+
}
112100

113101

102+
@Bean
103+
@ConditionalOnMissingBean
104+
public SecurityFilterChain filterChain(HttpSecurity security,
105+
HttpSecurityCustomer httpSecurityCustomer,
106+
TokenGateway tokenGateway,
107+
SecurityLoginHandler loginHandler,
108+
CodingApiSecurityProperties properties,
109+
AuthenticationTokenFilter authenticationTokenFilter) throws Exception {
110+
httpSecurityCustomer.customize(security);
111+
112+
//authentication filter
114113
security.with(new HttpSecurityConfigurer(tokenGateway, loginHandler, properties, authenticationTokenFilter), Customizer.withDefaults());
115114
security.exceptionHandling(httpSecurityExceptionHandlingConfigurer ->
116115
httpSecurityExceptionHandlingConfigurer.authenticationEntryPoint(new MyUnAuthenticationEntryPoint())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.codingapi.springboot.security.customer;
2+
3+
import com.codingapi.springboot.security.properties.CodingApiSecurityProperties;
4+
import lombok.AllArgsConstructor;
5+
import org.springframework.security.config.Customizer;
6+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7+
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
8+
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
9+
10+
@AllArgsConstructor
11+
public class DefaultHttpSecurityCustomer implements HttpSecurityCustomer {
12+
13+
private final CodingApiSecurityProperties properties;
14+
15+
@Override
16+
public void customize(HttpSecurity security) throws Exception {
17+
18+
//disable basic auth
19+
if (properties.isDisableBasicAuth()) {
20+
security.httpBasic(AbstractHttpConfigurer::disable);
21+
}
22+
23+
//disable frame options
24+
if (properties.isDisableFrameOptions()) {
25+
security.headers(new Customizer<HeadersConfigurer<HttpSecurity>>() {
26+
@Override
27+
public void customize(HeadersConfigurer<HttpSecurity> httpSecurityHeadersConfigurer) {
28+
httpSecurityHeadersConfigurer.frameOptions(new Customizer<HeadersConfigurer<org.springframework.security.config.annotation.web.builders.HttpSecurity>.FrameOptionsConfig>() {
29+
@Override
30+
public void customize(HeadersConfigurer<HttpSecurity>.FrameOptionsConfig frameOptionsConfig) {
31+
frameOptionsConfig.disable();
32+
}
33+
});
34+
}
35+
});
36+
}
37+
38+
//before add addCorsMappings to enable cors.
39+
security.cors(httpSecurityCorsConfigurer -> {
40+
if (properties.isDisableCors()) {
41+
httpSecurityCorsConfigurer.disable();
42+
}
43+
});
44+
45+
security.csrf(httpSecurityCsrfConfigurer -> {
46+
if (properties.isDisableCsrf()) {
47+
httpSecurityCsrfConfigurer.disable();
48+
}
49+
});
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.codingapi.springboot.security.customer;
2+
3+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
4+
5+
public interface HttpSecurityCustomer {
6+
7+
void customize(HttpSecurity security) throws Exception;
8+
9+
}

springboot-starter-security/src/main/java/com/codingapi/springboot/security/properties/CodingApiSecurityProperties.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public class CodingApiSecurityProperties {
3939
private String aseIv = "QUNYRkdIQEVEUyNYQ1phcw==";
4040

4141

42+
/**
43+
* 禁用Basic Auth
44+
*/
45+
private boolean disableBasicAuth = true;
46+
47+
/**
48+
* 禁用FrameOptions
49+
*/
50+
private boolean disableFrameOptions = true;
51+
4252
/**
4353
* 启用禁用CSRF
4454
*/

springboot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>3.4.3</version>
8+
<version>3.4.4</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
------------------------------------------------------
2-
CodingApi SpringBoot-Starter 3.4.3
2+
CodingApi SpringBoot-Starter 3.4.4
33
springboot version (${spring-boot.version})
44
------------------------------------------------------

0 commit comments

Comments
 (0)