|
|
@@ -1,6 +1,6 @@
|
|
|
package com.izouma.nineth.security;
|
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
@@ -13,6 +13,7 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
|
|
+import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
|
@@ -22,22 +23,24 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
|
|
@EnableConfigurationProperties({JwtConfig.class})
|
|
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
|
- @Autowired
|
|
|
- private JwtAuthenticationEntryPoint unauthorizedHandler;
|
|
|
+ private final JwtAuthenticationEntryPoint unauthorizedHandler;
|
|
|
+ private final UserDetailsService userDetailsService;
|
|
|
+ private final JwtAuthorizationTokenFilter authenticationTokenFilter;
|
|
|
+ private final String tokenHeader;
|
|
|
|
|
|
- @Autowired
|
|
|
- private JwtUserDetailsService jwtUserDetailsService;
|
|
|
-
|
|
|
- // Custom JWT based security filter
|
|
|
- @Autowired
|
|
|
- JwtAuthorizationTokenFilter authenticationTokenFilter;
|
|
|
-
|
|
|
- @Value("${jwt.header}")
|
|
|
- private String tokenHeader;
|
|
|
+ public WebSecurityConfig(JwtAuthenticationEntryPoint unauthorizedHandler,
|
|
|
+ @Qualifier("jwtUserDetailsService") UserDetailsService userDetailsService,
|
|
|
+ JwtAuthorizationTokenFilter authenticationTokenFilter,
|
|
|
+ @Value("${jwt.header}") String tokenHeader) {
|
|
|
+ this.unauthorizedHandler = unauthorizedHandler;
|
|
|
+ this.userDetailsService = userDetailsService;
|
|
|
+ this.authenticationTokenFilter = authenticationTokenFilter;
|
|
|
+ this.tokenHeader = tokenHeader;
|
|
|
+ }
|
|
|
|
|
|
- @Autowired
|
|
|
- public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
|
|
- auth.userDetailsService(jwtUserDetailsService)
|
|
|
+ @Override
|
|
|
+ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
|
+ auth.userDetailsService(userDetailsService)
|
|
|
.passwordEncoder(passwordEncoderBean());
|
|
|
}
|
|
|
|