|
--- untitled (Previous) |
|
+++ /home/sublime/workspace/java/spring/src/main/java/com/criticalblue/approov/jwt/WebSecurityConfig.java |
|
@@ -1,6 +1,7 @@ |
|
package com.criticalblue.approov.jwt; |
|
|
|
import com.criticalblue.approov.jwt.authentication.*; |
|
+import org.springframework.core.annotation.Order; |
|
import org.springframework.security.config.annotation.web.builders.WebSecurity; |
|
import org.springframework.security.config.http.SessionCreationPolicy; |
|
import org.springframework.web.cors.CorsConfiguration; |
|
@@ -19,11 +20,13 @@ |
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
|
private static ApproovConfig approovConfig = ApproovConfig.getInstance(); |
|
-// sd |
|
+ |
|
@Bean |
|
CorsConfigurationSource corsConfigurationSource() { |
|
CorsConfiguration configuration = new CorsConfiguration(); |
|
configuration.setAllowedMethods(Arrays.asList("GET")); |
|
+ configuration.addAllowedHeader("Authorization"); |
|
+ configuration.addAllowedHeader("Approov-Token"); |
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
|
source.registerCorsConfiguration("/**", configuration); |
|
return source; |
|
@@ -34,23 +37,86 @@ |
|
web.ignoring().antMatchers("/error"); |
|
} |
|
|
|
- @Override |
|
- protected void configure(HttpSecurity http) throws Exception { |
|
+ @Configuration |
|
+ @Order(1) |
|
+ public static class ApproovWebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
|
- http.cors(); |
|
+ @Override |
|
+ protected void configure(HttpSecurity http) throws Exception { |
|
|
|
- http |
|
- .httpBasic().disable() |
|
- .formLogin().disable() |
|
- .logout().disable() |
|
- .csrf().disable() |
|
- .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); |
|
+ http.cors(); |
|
|
|
- http |
|
- .authorizeRequests() |
|
- .antMatchers(HttpMethod.GET, "/").permitAll() |
|
- .antMatchers(HttpMethod.GET, "/hello").permitAll() |
|
- .antMatchers(HttpMethod.GET, "/shapes").permitAll() |
|
- .antMatchers(HttpMethod.GET, "/forms").permitAll(); |
|
+ http |
|
+ .httpBasic().disable() |
|
+ .formLogin().disable() |
|
+ .logout().disable() |
|
+ .csrf().disable() |
|
+ .authenticationProvider(new ApproovAuthenticationProvider(approovConfig)) |
|
+ .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); |
|
+ |
|
+ http |
|
+ .securityContext() |
|
+ .securityContextRepository(new ApproovSecurityContextRepository(approovConfig, false)) |
|
+ .and() |
|
+ .exceptionHandling() |
|
+ .authenticationEntryPoint(new ApproovAuthenticationEntryPoint()) |
|
+ .and() |
|
+ .antMatcher("/v2/shapes") |
|
+ .authorizeRequests() |
|
+ .antMatchers(HttpMethod.GET, "/v2/shapes").authenticated(); |
|
+ } |
|
+ } |
|
+ |
|
+ @Configuration |
|
+ @Order(2) |
|
+ public static class ApproovTokenBindingWebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
+ |
|
+ @Override |
|
+ protected void configure(HttpSecurity http) throws Exception { |
|
+ |
|
+ http.cors(); |
|
+ |
|
+ http |
|
+ .httpBasic().disable() |
|
+ .formLogin().disable() |
|
+ .logout().disable() |
|
+ .csrf().disable() |
|
+ .authenticationProvider(new ApproovAuthenticationProvider(approovConfig)) |
|
+ .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); |
|
+ |
|
+ http |
|
+ .securityContext() |
|
+ .securityContextRepository(new ApproovSecurityContextRepository(approovConfig, true)) |
|
+ .and() |
|
+ .exceptionHandling() |
|
+ .authenticationEntryPoint(new ApproovAuthenticationEntryPoint()) |
|
+ .and() |
|
+ .antMatcher("/v2/forms") |
|
+ .authorizeRequests() |
|
+ .antMatchers(HttpMethod.GET, "/v2/forms").authenticated(); |
|
+ } |
|
+ } |
|
+ |
|
+ @Configuration |
|
+ @Order(3) |
|
+ public static class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
+ |
|
+ @Override |
|
+ protected void configure(HttpSecurity http) throws Exception { |
|
+ |
|
+ http.cors(); |
|
+ |
|
+ http |
|
+ .httpBasic().disable() |
|
+ .formLogin().disable() |
|
+ .logout().disable() |
|
+ .csrf().disable() |
|
+ .authenticationProvider(new ApproovAuthenticationProvider(approovConfig)) |
|
+ .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); |
|
+ |
|
+ http |
|
+ .authorizeRequests() |
|
+ .antMatchers(HttpMethod.GET, "/**").permitAll(); |
|
+ } |
|
} |
|
} |