|
|
@ -32,100 +32,100 @@ import java.util.Arrays; |
|
|
|
@EnableGlobalMethodSecurity(prePostEnabled = true) |
|
|
|
@EnableGlobalMethodSecurity(prePostEnabled = true) |
|
|
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
|
|
|
|
|
|
|
|
|
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; |
|
|
|
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; |
|
|
|
private final UserDetailsService jwtUserDetailsService; |
|
|
|
private final UserDetailsService jwtUserDetailsService; |
|
|
|
private final JwtRequestFilter jwtRequestFilter; |
|
|
|
private final JwtRequestFilter jwtRequestFilter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String[] PERMITTED_URL = { |
|
|
|
private final String[] PERMITTED_URL = { |
|
|
|
"/api/acnt/**", |
|
|
|
"/api/acnt/**", |
|
|
|
"/api/ctr/cntrl/id/**", |
|
|
|
"/api/ctr/cntrl/id/**", |
|
|
|
"/api/server/**", |
|
|
|
"/api/server/**", |
|
|
|
"/api/comn/file/download", |
|
|
|
"/api/comn/file/download", |
|
|
|
"/api/comn/file/download/**", |
|
|
|
"/api/comn/file/download/**", |
|
|
|
// 외부 연동
|
|
|
|
// 외부 연동
|
|
|
|
"/api/external/laanc/**", |
|
|
|
"/api/external/laanc/**", |
|
|
|
"/api/external/dos/**", |
|
|
|
"/api/external/dos/**", |
|
|
|
"/api/laanc/flight/plan", |
|
|
|
"/api/laanc/flight/plan", |
|
|
|
// TEST
|
|
|
|
// TEST
|
|
|
|
"/api/v1/utm", |
|
|
|
"/api/v1/utm", |
|
|
|
/* swagger v2 */ |
|
|
|
/* swagger v2 */ |
|
|
|
"/v2/api-docs", |
|
|
|
"/v2/api-docs", |
|
|
|
"/swagger-resources", |
|
|
|
"/swagger-resources", |
|
|
|
"/swagger-resources/**", |
|
|
|
"/swagger-resources/**", |
|
|
|
"/configuration/ui", |
|
|
|
"/configuration/ui", |
|
|
|
"/configuration/security", |
|
|
|
"/configuration/security", |
|
|
|
// "/swagger-ui.html",
|
|
|
|
// "/swagger-ui.html",
|
|
|
|
"/webjars/**", |
|
|
|
"/webjars/**", |
|
|
|
/* swagger v3 */ |
|
|
|
/* swagger v3 */ |
|
|
|
"/v3/api-docs/**", |
|
|
|
"/v3/api-docs/**", |
|
|
|
// "/swagger-ui/**",
|
|
|
|
// "/swagger-ui/**",
|
|
|
|
/* swagger spring doc */ |
|
|
|
/* swagger spring doc */ |
|
|
|
"/api-docs", |
|
|
|
"/api-docs", |
|
|
|
"/api-docs/**", |
|
|
|
"/api-docs/**", |
|
|
|
"/swagger-ui-custom.html", |
|
|
|
"/swagger-ui-custom.html", |
|
|
|
"/v3/api-docs/**", |
|
|
|
"/v3/api-docs/**", |
|
|
|
"/swagger-ui/**", |
|
|
|
"/swagger-ui/**", |
|
|
|
"/swagger-ui.html" |
|
|
|
"/swagger-ui.html" |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { |
|
|
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { |
|
|
|
// configure AuthenticationManager so that it knows from where to load
|
|
|
|
// configure AuthenticationManager so that it knows from where to load
|
|
|
|
// user for matching credentials
|
|
|
|
// user for matching credentials
|
|
|
|
// Use BCryptPasswordEncoder
|
|
|
|
// Use BCryptPasswordEncoder
|
|
|
|
auth.userDetailsService(jwtUserDetailsService).passwordEncoder(passwordEncoder()); |
|
|
|
auth.userDetailsService(jwtUserDetailsService).passwordEncoder(passwordEncoder()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
@Primary |
|
|
|
@Primary |
|
|
|
public CorsConfigurationSource corsConfigurationSource() { |
|
|
|
public CorsConfigurationSource corsConfigurationSource() { |
|
|
|
CorsConfiguration configuration = new CorsConfiguration(); |
|
|
|
CorsConfiguration configuration = new CorsConfiguration(); |
|
|
|
configuration.setAllowedOrigins(Arrays.asList("*")); |
|
|
|
configuration.setAllowedOrigins(Arrays.asList("*")); |
|
|
|
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE","OPTIONS")); |
|
|
|
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); |
|
|
|
configuration.setAllowedHeaders(Arrays.asList("x-timezone","Accept-Language","Accept","X-Requested-With", "Content-Type", "Authorization", "X-XSRF-token")); |
|
|
|
configuration.setAllowedHeaders(Arrays.asList("x-timezone", "Accept-Language", "Accept", "X-Requested-With", "Content-Type", "Authorization", "X-XSRF-token")); |
|
|
|
configuration.setAllowCredentials(false); |
|
|
|
configuration.setAllowCredentials(false); |
|
|
|
configuration.setMaxAge(3600L); |
|
|
|
configuration.setMaxAge(3600L); |
|
|
|
|
|
|
|
|
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
|
|
|
source.registerCorsConfiguration("/**", configuration); |
|
|
|
source.registerCorsConfiguration("/**", configuration); |
|
|
|
|
|
|
|
|
|
|
|
return source; |
|
|
|
return source; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public PasswordEncoder passwordEncoder() { |
|
|
|
public PasswordEncoder passwordEncoder() { |
|
|
|
return new BCryptPasswordEncoder(); |
|
|
|
return new BCryptPasswordEncoder(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public AuthenticationManager authenticationManagerBean() throws Exception { |
|
|
|
public AuthenticationManager authenticationManagerBean() throws Exception { |
|
|
|
return super.authenticationManagerBean(); |
|
|
|
return super.authenticationManagerBean(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void configure(HttpSecurity httpSecurity) throws Exception { |
|
|
|
protected void configure(HttpSecurity httpSecurity) throws Exception { |
|
|
|
// We don't need CSRF for this example
|
|
|
|
// We don't need CSRF for this example
|
|
|
|
httpSecurity.csrf().disable() |
|
|
|
httpSecurity.csrf().disable() |
|
|
|
.cors(cors -> corsConfigurationSource()) |
|
|
|
.cors(cors -> corsConfigurationSource()) |
|
|
|
// dont authenticate this particular request
|
|
|
|
// dont authenticate this particular request
|
|
|
|
.authorizeRequests() |
|
|
|
.authorizeRequests() |
|
|
|
.antMatchers(HttpMethod.OPTIONS,"/api/**").permitAll() |
|
|
|
.antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll() |
|
|
|
.antMatchers(HttpMethod.GET,"/ping").permitAll() |
|
|
|
.antMatchers(HttpMethod.GET, "/ping").permitAll() |
|
|
|
.antMatchers("/swagger-ui/**").permitAll() |
|
|
|
.antMatchers("/swagger-ui/**").permitAll() |
|
|
|
.antMatchers(PERMITTED_URL).permitAll() |
|
|
|
.antMatchers(PERMITTED_URL).permitAll() |
|
|
|
// all other requests need to be authenticated
|
|
|
|
// all other requests need to be authenticated
|
|
|
|
.anyRequest().authenticated().and() |
|
|
|
.anyRequest().authenticated().and() |
|
|
|
// make sure we use stateless session; session won't be used to
|
|
|
|
// make sure we use stateless session; session won't be used to
|
|
|
|
// store user's state.
|
|
|
|
// store user's state.
|
|
|
|
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement() |
|
|
|
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement() |
|
|
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); |
|
|
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); |
|
|
|
|
|
|
|
|
|
|
|
// Add a filter to validate the tokens with every request
|
|
|
|
// Add a filter to validate the tokens with every request
|
|
|
|
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class); |
|
|
|
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |