3131import org .springframework .context .annotation .Configuration ;
3232import org .springframework .context .annotation .Profile ;
3333import org .springframework .core .convert .converter .Converter ;
34- import org .springframework .http .HttpMethod ;
3534import org .springframework .security .config .annotation .method .configuration .EnableMethodSecurity ;
3635import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
37- import org .springframework .security .config .annotation .web .configuration .WebSecurityCustomizer ;
3836import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
3937import org .springframework .security .core .GrantedAuthority ;
4038import org .springframework .security .oauth2 .jwt .Jwt ;
4442import org .springframework .security .oauth2 .server .resource .authentication .JwtGrantedAuthoritiesConverter ;
4543import org .springframework .security .oauth2 .server .resource .web .authentication .BearerTokenAuthenticationFilter ;
4644import org .springframework .security .web .SecurityFilterChain ;
45+ import org .springframework .web .servlet .config .annotation .CorsRegistry ;
4746import org .springframework .web .servlet .config .annotation .ResourceHandlerRegistry ;
4847import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
49- import org .springframework .web .servlet .mvc .method .annotation .RequestMappingHandlerMapping ;
5048
5149import java .text .ParseException ;
5250import java .util .Collection ;
5351import java .util .Map ;
52+ import java .util .stream .Stream ;
5453
5554import static de .unijena .bioinf .ms .middleware .security .Authorities .*;
5655
5756@ EnableMethodSecurity
5857@ Configuration
5958public class SecurityConfig {
6059 @ Bean
61- public WebMvcConfigurer corsConfigurer () {
60+ @ Profile ("local" )
61+ public WebMvcConfigurer corsConfigurerLocal () {
6262 return new WebMvcConfigurer () {
6363 @ Override
6464 public void addResourceHandlers (ResourceHandlerRegistry registry ) {
@@ -69,15 +69,28 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
6969 registry .addResourceHandler ("/sirius_java_integrated/**" )
7070 .addResourceLocations ("classpath:/templates/sirius_java_integrated/" );
7171 }
72+ //disable Cross-Origin Resource Sharing (CORS) checks
73+ @ Override
74+ public void addCorsMappings (CorsRegistry registry ) {
75+ registry .addMapping ("/**" ).allowedOriginPatterns ("http://localhost:[*]" , "http://127.0.0.1:[*]" );
76+ }
7277 };
7378 }
7479
80+ @ Bean
81+ @ Profile ("web" )
82+ public WebMvcConfigurer corsConfigurerWeb () {
83+ // todo implement to use as real web api.
84+ throw new UnsupportedOperationException ("Not supported yet!" );
85+ }
86+
7587 @ Bean
7688 SecurityFilterChain securityFilterChain (JwtDecoder jwtDecoder ,
7789 SiriusGuiHandshake siriusGuiHandshake , ExplorerHandshake explorerHandshake ,
7890 HttpSecurity http ) throws Exception
7991 {
80- // disable CSRF
92+ // todo review to use as real web api!
93+ // disable CSRF (Cross-Site Request Forgery) checks
8194 http .csrf (AbstractHttpConfigurer ::disable )
8295 // This is the line that disables anonymous authentication
8396 .anonymous (AbstractHttpConfigurer ::disable )
0 commit comments