17
17
package org .apache .seata .console .config ;
18
18
19
19
import org .apache .seata .common .util .StringUtils ;
20
- import org .apache .seata .console .filter .JwtAuthenticationTokenFilter ;
20
+ import org .apache .seata .console .filter .ConsoleAuthenticationTokenFilter ;
21
21
import org .apache .seata .console .security .CustomUserDetailsServiceImpl ;
22
22
import org .apache .seata .console .security .JwtAuthenticationEntryPoint ;
23
23
import org .apache .seata .console .utils .JwtTokenUtils ;
24
24
import org .springframework .beans .factory .annotation .Autowired ;
25
+ import org .springframework .beans .factory .annotation .Qualifier ;
25
26
import org .springframework .context .annotation .Bean ;
26
27
import org .springframework .context .annotation .Configuration ;
28
+ import org .springframework .core .annotation .Order ;
27
29
import org .springframework .core .env .Environment ;
28
30
import org .springframework .security .authentication .AuthenticationManager ;
29
- import org .springframework .security .config .BeanIds ;
30
31
import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
31
- import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
32
32
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
33
33
import org .springframework .security .config .annotation .web .builders .WebSecurity ;
34
34
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
44
44
*
45
45
*/
46
46
@ Configuration (proxyBeanMethods = false )
47
- @ EnableGlobalMethodSecurity ( prePostEnabled = true )
48
- public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
47
+ @ Order ( 2 )
48
+ public class ConsoleSecurityConfig extends WebSecurityConfigurerAdapter {
49
49
50
50
/**
51
51
* The constant AUTHORIZATION_HEADER.
52
52
*/
53
53
public static final String AUTHORIZATION_HEADER = "Authorization" ;
54
54
55
+ /**
56
+ * The constant REFRESH_TOKEN.
57
+ */
58
+ public static final String REFRESH_TOKEN = "refresh_token" ;
59
+
55
60
/**
56
61
* The constant AUTHORIZATION_TOKEN.
57
62
*/
58
63
public static final String AUTHORIZATION_TOKEN = "access_token" ;
59
64
65
+ /**
66
+ * The constant ACCESS_TOKEN_NEAR_EXPIRATION.
67
+ */
68
+ public static final String ACCESS_TOKEN_NEAR_EXPIRATION = "Access_token_near_expiration" ;
69
+
60
70
/**
61
71
* The constant SECURITY_IGNORE_URLS_SPILT_CHAR.
62
72
*/
@@ -68,18 +78,21 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
68
78
public static final String TOKEN_PREFIX = "Bearer " ;
69
79
70
80
@ Autowired
81
+ @ Qualifier ("consoleUserDetailsService" )
71
82
private CustomUserDetailsServiceImpl userDetailsService ;
72
83
73
84
@ Autowired
85
+ @ Qualifier ("consoleJwtAuthenticationEntryPoint" )
74
86
private JwtAuthenticationEntryPoint unauthorizedHandler ;
75
87
76
88
@ Autowired
89
+ @ Qualifier ("consoleJwtTokenUtils" )
77
90
private JwtTokenUtils tokenProvider ;
78
91
79
92
@ Autowired
80
93
private Environment env ;
81
94
82
- @ Bean (name = BeanIds . AUTHENTICATION_MANAGER )
95
+ @ Bean ("consoleAuthenticationManager" )
83
96
@ Override
84
97
public AuthenticationManager authenticationManagerBean () throws Exception {
85
98
return super .authenticationManagerBean ();
@@ -92,7 +105,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
92
105
93
106
@ Override
94
107
public void configure (WebSecurity web ) {
95
- String ignoreURLs = env .getProperty ("seata.security .ignore.urls" , "/**" );
108
+ String ignoreURLs = env .getProperty ("console .ignore.urls" , "/**" );
96
109
for (String ignoreURL : ignoreURLs .trim ().split (SECURITY_IGNORE_URLS_SPILT_CHAR )) {
97
110
web .ignoring ().antMatchers (ignoreURL .trim ());
98
111
}
@@ -110,9 +123,9 @@ protected void configure(HttpSecurity http) throws Exception {
110
123
csrf .ignoringAntMatchers (csrfIgnoreUrls .trim ().split (SECURITY_IGNORE_URLS_SPILT_CHAR ));
111
124
}
112
125
csrf .csrfTokenRepository (CookieCsrfTokenRepository .withHttpOnlyFalse ());
113
- // don't disable csrf, jwt may be implemented based on cookies
114
- http .addFilterBefore (new JwtAuthenticationTokenFilter (tokenProvider ),
115
- UsernamePasswordAuthenticationFilter .class );
126
+ // don't disable csrf, jwt may be implemented based on cookies
127
+ http .antMatcher ( "/api/v1/**" ). addFilterBefore (new ConsoleAuthenticationTokenFilter (tokenProvider ),
128
+ UsernamePasswordAuthenticationFilter .class );
116
129
117
130
// disable cache
118
131
http .headers ().cacheControl ();
@@ -123,7 +136,6 @@ protected void configure(HttpSecurity http) throws Exception {
123
136
*
124
137
* @return the password encoder
125
138
*/
126
- @ Bean
127
139
public PasswordEncoder passwordEncoder () {
128
140
return new BCryptPasswordEncoder ();
129
141
}
0 commit comments