|
|
|
|
@ -17,11 +17,16 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
|
|
import org.springframework.security.web.SecurityFilterChain;
|
|
|
|
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
|
|
|
import org.springframework.web.cors.CorsConfiguration;
|
|
|
|
|
import org.springframework.web.cors.CorsConfigurationSource;
|
|
|
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
|
|
|
|
|
|
import kr.re.etri.autoflow.security.jwt.AuthEntryPointJwt;
|
|
|
|
|
import kr.re.etri.autoflow.security.jwt.AuthTokenFilter;
|
|
|
|
|
import kr.re.etri.autoflow.security.services.UserDetailsServiceImpl;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
//@EnableWebSecurity
|
|
|
|
|
@EnableMethodSecurity
|
|
|
|
|
@ -29,31 +34,31 @@ import kr.re.etri.autoflow.security.services.UserDetailsServiceImpl;
|
|
|
|
|
//jsr250Enabled = true,
|
|
|
|
|
//prePostEnabled = true) // by default
|
|
|
|
|
public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
|
|
|
|
|
@Autowired
|
|
|
|
|
UserDetailsServiceImpl userDetailsService;
|
|
|
|
|
@Autowired
|
|
|
|
|
UserDetailsServiceImpl userDetailsService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AuthEntryPointJwt unauthorizedHandler;
|
|
|
|
|
@Autowired
|
|
|
|
|
private AuthEntryPointJwt unauthorizedHandler;
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public AuthTokenFilter authenticationJwtTokenFilter() {
|
|
|
|
|
return new AuthTokenFilter();
|
|
|
|
|
}
|
|
|
|
|
@Bean
|
|
|
|
|
public AuthTokenFilter authenticationJwtTokenFilter() {
|
|
|
|
|
return new AuthTokenFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
// public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
|
|
|
|
|
// authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public DaoAuthenticationProvider authenticationProvider() {
|
|
|
|
|
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
|
|
|
|
|
@Bean
|
|
|
|
|
public DaoAuthenticationProvider authenticationProvider() {
|
|
|
|
|
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
|
|
|
|
|
|
|
|
|
|
authProvider.setUserDetailsService(userDetailsService);
|
|
|
|
|
authProvider.setPasswordEncoder(passwordEncoder());
|
|
|
|
|
authProvider.setUserDetailsService(userDetailsService);
|
|
|
|
|
authProvider.setPasswordEncoder(passwordEncoder());
|
|
|
|
|
|
|
|
|
|
return authProvider;
|
|
|
|
|
}
|
|
|
|
|
return authProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Bean
|
|
|
|
|
// @Override
|
|
|
|
|
@ -61,15 +66,15 @@ public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
|
|
|
|
|
// return super.authenticationManagerBean();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
|
|
|
|
|
return authConfig.getAuthenticationManager();
|
|
|
|
|
}
|
|
|
|
|
@Bean
|
|
|
|
|
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
|
|
|
|
|
return authConfig.getAuthenticationManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public PasswordEncoder passwordEncoder() {
|
|
|
|
|
return new BCryptPasswordEncoder();
|
|
|
|
|
}
|
|
|
|
|
@Bean
|
|
|
|
|
public PasswordEncoder passwordEncoder() {
|
|
|
|
|
return new BCryptPasswordEncoder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
// protected void configure(HttpSecurity http) throws Exception {
|
|
|
|
|
@ -83,38 +88,50 @@ public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
|
|
|
|
|
// http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
|
|
http.csrf(AbstractHttpConfigurer::disable)
|
|
|
|
|
.exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
|
|
|
|
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
|
|
|
.authorizeHttpRequests(auth ->
|
|
|
|
|
auth.requestMatchers("/api/auth/**").permitAll()
|
|
|
|
|
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
|
|
|
|
|
.requestMatchers("/api/test/**").permitAll()
|
|
|
|
|
.anyRequest().authenticated()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
http.authenticationProvider(authenticationProvider());
|
|
|
|
|
|
|
|
|
|
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
|
|
|
|
|
|
|
|
|
|
return http.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 임시 설정
|
|
|
|
|
// @Bean
|
|
|
|
|
// public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
|
|
// http.csrf(AbstractHttpConfigurer::disable)
|
|
|
|
|
// .exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
|
|
|
|
|
// .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
|
|
|
// .authorizeHttpRequests(auth ->
|
|
|
|
|
// auth.anyRequest().permitAll() // 모든 요청 허용
|
|
|
|
|
// );
|
|
|
|
|
// .exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
|
|
|
|
|
// .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
|
|
|
// .authorizeHttpRequests(auth ->
|
|
|
|
|
// auth.requestMatchers("/api/auth/**").permitAll()
|
|
|
|
|
// .requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
|
|
|
|
|
// .requestMatchers("/api/test/**").permitAll()
|
|
|
|
|
// .anyRequest().authenticated()
|
|
|
|
|
// );
|
|
|
|
|
//
|
|
|
|
|
// http.authenticationProvider(authenticationProvider());
|
|
|
|
|
//
|
|
|
|
|
// http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
|
|
|
|
|
//
|
|
|
|
|
// return http.build();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//임시 설정
|
|
|
|
|
@Bean
|
|
|
|
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
|
|
http.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
|
|
|
|
.csrf(AbstractHttpConfigurer::disable)
|
|
|
|
|
.exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
|
|
|
|
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
|
|
|
.authorizeHttpRequests(auth ->
|
|
|
|
|
auth.anyRequest().permitAll() // 모든 요청 허용
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
http.authenticationProvider(authenticationProvider());
|
|
|
|
|
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
|
|
|
|
|
|
|
|
|
|
return http.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
CorsConfigurationSource corsConfigurationSource() {
|
|
|
|
|
CorsConfiguration configuration = new CorsConfiguration();
|
|
|
|
|
configuration.setAllowedOrigins(Arrays.asList("*"));
|
|
|
|
|
configuration.setAllowedMethods(Arrays.asList("*"));
|
|
|
|
|
configuration.setAllowedHeaders(Arrays.asList("*"));
|
|
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
|
|
source.registerCorsConfiguration("/**", configuration);
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|