2
2
3
3
import com .codingapi .springboot .security .configurer .HttpSecurityConfigurer ;
4
4
import com .codingapi .springboot .security .controller .VersionController ;
5
+ import com .codingapi .springboot .security .dto .request .LoginRequest ;
5
6
import com .codingapi .springboot .security .filter .*;
6
7
import com .codingapi .springboot .security .jwt .Jwt ;
8
+ import com .codingapi .springboot .security .jwt .Token ;
7
9
import com .codingapi .springboot .security .properties .SecurityJwtProperties ;
8
10
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
9
11
import org .springframework .boot .context .properties .ConfigurationProperties ;
24
26
import org .springframework .web .servlet .config .annotation .CorsRegistry ;
25
27
import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
26
28
29
+ import javax .servlet .http .HttpServletRequest ;
30
+ import javax .servlet .http .HttpServletResponse ;
31
+
27
32
@ Configuration
28
33
@ EnableWebSecurity
29
34
public class AutoConfiguration {
@@ -53,28 +58,45 @@ public PasswordEncoder passwordEncoder() {
53
58
return PasswordEncoderFactories .createDelegatingPasswordEncoder ();
54
59
}
55
60
61
+ @ Bean
62
+ @ ConditionalOnMissingBean
63
+ public AuthenticationTokenFilter authenticationTokenFilter () {
64
+ return (request , response , chain ) -> {
65
+
66
+ };
67
+ }
68
+
56
69
57
70
@ Bean
58
71
@ ConditionalOnMissingBean
59
- public SecurityLoginHandler securityLoginHandler (){
60
- return (request , response , handler ) -> {
72
+ public SecurityLoginHandler securityLoginHandler () {
73
+ return new SecurityLoginHandler () {
74
+ @ Override
75
+ public void preHandle (HttpServletRequest request , HttpServletResponse response , LoginRequest handler ) throws Exception {
76
+
77
+ }
78
+
79
+ @ Override
80
+ public void postHandle (HttpServletRequest request , HttpServletResponse response , LoginRequest handler , Token token ) {
81
+
82
+ }
61
83
};
62
84
}
63
85
64
86
65
87
@ Bean
66
88
@ ConditionalOnMissingBean
67
- public SecurityFilterChain filterChain (HttpSecurity security , Jwt jwt ,SecurityLoginHandler loginHandler ,
68
- SecurityJwtProperties properties ) throws Exception {
89
+ public SecurityFilterChain filterChain (HttpSecurity security , Jwt jwt , SecurityLoginHandler loginHandler ,
90
+ SecurityJwtProperties properties , AuthenticationTokenFilter authenticationTokenFilter ) throws Exception {
69
91
//disable basic auth
70
92
security .httpBasic ().disable ();
71
93
72
94
//before add addCorsMappings to enable cors.
73
95
security .cors ();
74
- if (properties .isDisableCsrf () ) {
96
+ if (properties .isDisableCsrf ()) {
75
97
security .csrf ().disable ();
76
98
}
77
- security .apply (new HttpSecurityConfigurer (jwt ,loginHandler ,properties ));
99
+ security .apply (new HttpSecurityConfigurer (jwt , loginHandler , properties , authenticationTokenFilter ));
78
100
security
79
101
.exceptionHandling ()
80
102
.authenticationEntryPoint (new MyUnAuthenticationEntryPoint ())
@@ -125,7 +147,7 @@ public WebMvcConfigurer corsConfigurer(SecurityJwtProperties securityJwtProperti
125
147
return new WebMvcConfigurer () {
126
148
@ Override
127
149
public void addCorsMappings (CorsRegistry registry ) {
128
- if (securityJwtProperties .isDisableCors ()) {
150
+ if (securityJwtProperties .isDisableCors ()) {
129
151
registry .addMapping ("/**" )
130
152
.allowedHeaders ("*" )
131
153
.allowedMethods ("*" )
@@ -149,7 +171,7 @@ public SecurityJwtProperties securityJwtProperties() {
149
171
150
172
@ Bean
151
173
@ ConditionalOnMissingBean
152
- public VersionController versionController (Environment environment ){
174
+ public VersionController versionController (Environment environment ) {
153
175
return new VersionController (environment );
154
176
}
155
177
0 commit comments