Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.devsuperiror.dsdeliver.config;
- import java.util.Arrays;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.env.Environment;
- import org.springframework.security.config.annotation.web.builders.HttpSecurity;
- 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.web.cors.CorsConfiguration;
- import org.springframework.web.cors.CorsConfigurationSource;
- import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
- @Configuration
- @EnableWebSecurity
- public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- private Environment env;
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- if (Arrays.asList(env.getActiveProfiles()).contains("test")) {
- http.headers().frameOptions().disable();
- }
- http.cors().and().csrf().disable();
- http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
- http.authorizeRequests().anyRequest().permitAll();
- }
- @Bean
- CorsConfigurationSource corsConfigurationSource() {
- CorsConfiguration configuration = new CorsConfiguration().applyPermitDefaultValues();
- configuration.setAllowedMethods(Arrays.asList("POST", "GET", "PUT", "DELETE", "OPTIONS"));
- final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
- source.registerCorsConfiguration("/**", configuration);
- return source;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement