22
22
import com .navercorp .pinpoint .login .basic .service .JwtRequestFilter ;
23
23
import com .navercorp .pinpoint .login .basic .service .PreAuthenticationCheckFilter ;
24
24
import com .navercorp .pinpoint .login .basic .service .SaveJwtTokenAuthenticationSuccessHandler ;
25
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
25
26
import org .springframework .context .annotation .Bean ;
26
27
import org .springframework .context .annotation .Configuration ;
27
28
import org .springframework .context .annotation .Import ;
28
- import org .springframework .context .annotation .Profile ;
29
29
import org .springframework .security .authentication .AuthenticationManager ;
30
+ import org .springframework .security .authentication .AuthenticationProvider ;
30
31
import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
32
+ import org .springframework .security .config .annotation .authentication .configuration .AuthenticationConfiguration ;
31
33
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
32
34
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
33
- import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
34
35
import org .springframework .security .config .http .SessionCreationPolicy ;
36
+ import org .springframework .security .core .Authentication ;
37
+ import org .springframework .security .core .AuthenticationException ;
35
38
import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
36
39
import org .springframework .security .crypto .password .PasswordEncoder ;
40
+ import org .springframework .security .web .SecurityFilterChain ;
37
41
import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
38
42
import org .springframework .security .web .authentication .ui .DefaultLoginPageGeneratingFilter ;
39
43
40
44
import java .util .Objects ;
41
45
46
+ import static org .springframework .security .web .util .matcher .AntPathRequestMatcher .antMatcher ;
47
+
42
48
/**
43
49
* @author Taejin Koo
44
50
*/
45
51
@ Configuration
46
52
@ EnableWebSecurity
47
53
@ Import (BasicLoginConfiguration .class )
48
- @ Profile ( "basicLogin" )
49
- public class PinpointBasicLoginConfig extends WebSecurityConfigurerAdapter {
54
+ @ ConditionalOnProperty ( name = "pinpoint.modules.web.login" , havingValue = "basicLogin" )
55
+ public class PinpointBasicLoginConfig {
50
56
51
57
private final BasicLoginService basicLoginService ;
52
58
53
59
public PinpointBasicLoginConfig (BasicLoginService basicLoginService ) {
54
60
this .basicLoginService = Objects .requireNonNull (basicLoginService , "basicLoginService" );
55
61
}
56
62
57
- @ Override
58
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
63
+
64
+ @ Bean
65
+ public AuthenticationManager authenticationManager (HttpSecurity http ) throws Exception {
66
+ AuthenticationManagerBuilder auth = http .getSharedObject (AuthenticationManagerBuilder .class );
67
+
59
68
auth .eraseCredentials (false );
60
69
auth .userDetailsService (basicLoginService .getUserDetailsService ());
70
+ return auth .build ();
61
71
}
62
72
63
- @ Override
64
- protected void configure (HttpSecurity http ) throws Exception {
73
+ @ Bean
74
+ public SecurityFilterChain configure (HttpSecurity http ) throws Exception {
65
75
// for common
66
76
http
67
77
.csrf ().disable ()
@@ -76,28 +86,23 @@ protected void configure(HttpSecurity http) throws Exception {
76
86
.deleteCookies (BasicLoginConstants .PINPOINT_JWT_COOKIE_NAME );
77
87
78
88
// for admin
79
- http .authorizeRequests ().antMatchers ( "/admin/**" ).hasRole ("ADMIN" )
89
+ http .authorizeHttpRequests ().requestMatchers ( antMatcher ( "/admin/**" ) ).hasRole ("ADMIN" )
80
90
.and ()
81
91
.exceptionHandling ()
82
92
.accessDeniedPage (BasicLoginConstants .URI_NOT_AUTHORIZED );
83
93
84
94
// for user
85
- http .authorizeRequests ().anyRequest ().authenticated ();
95
+ http .authorizeHttpRequests ().anyRequest ().authenticated ();
86
96
87
97
http .addFilterBefore (new JwtRequestFilter (basicLoginService ), UsernamePasswordAuthenticationFilter .class );
88
98
89
99
http .addFilterBefore (new PreAuthenticationCheckFilter (), DefaultLoginPageGeneratingFilter .class );
100
+ return http .build ();
90
101
}
91
102
92
103
@ Bean
93
104
public PasswordEncoder passwordEncoder () {
94
105
return new BCryptPasswordEncoder ();
95
106
}
96
107
97
- @ Override
98
- @ Bean
99
- public AuthenticationManager authenticationManagerBean () throws Exception {
100
- return super .authenticationManagerBean ();
101
- }
102
-
103
- }
108
+ }
0 commit comments