14 |
14 |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
15 |
15 |
import org.springframework.security.config.http.SessionCreationPolicy;
|
16 |
16 |
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
17 |
import org.springframework.security.web.SecurityFilterChain;
|
|
18 |
import org.springframework.security.web.access.channel.ChannelProcessingFilter;
|
17 |
19 |
import org.springframework.web.client.RestTemplate;
|
|
20 |
import org.springframework.web.cors.CorsConfiguration;
|
|
21 |
import org.springframework.web.cors.CorsConfigurationSource;
|
|
22 |
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
23 |
|
|
24 |
import java.util.Arrays;
|
18 |
25 |
|
19 |
26 |
@Configuration
|
20 |
27 |
@EnableWebSecurity(debug = true)
|
... | ... | |
63 |
70 |
@Override
|
64 |
71 |
protected void configure(HttpSecurity httpSecurity) throws Exception {
|
65 |
72 |
httpSecurity
|
|
73 |
.cors().configurationSource(corsConfigurationSource())
|
|
74 |
.and()
|
66 |
75 |
.csrf().disable()
|
67 |
76 |
.authorizeRequests()
|
68 |
77 |
.mvcMatchers("/v2/user/register", "/v2/user/login", "/v2/user/refresh", "/v2/user/logout").permitAll()
|
69 |
78 |
.anyRequest().authenticated()
|
70 |
79 |
.and()
|
71 |
80 |
.sessionManagement()
|
72 |
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
73 |
|
.and();
|
|
81 |
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
|
|
82 |
}
|
|
83 |
|
|
84 |
@Bean
|
|
85 |
public CorsConfigurationSource corsConfigurationSource() {
|
|
86 |
CorsConfiguration configuration = new CorsConfiguration();
|
|
87 |
configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000"));
|
|
88 |
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
|
|
89 |
configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token"));
|
|
90 |
configuration.setExposedHeaders(Arrays.asList("x-auth-token"));
|
|
91 |
configuration.setAllowCredentials(true);
|
|
92 |
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
93 |
source.registerCorsConfiguration("/**", configuration);
|
|
94 |
return source;
|
74 |
95 |
}
|
75 |
96 |
|
76 |
97 |
}
|
#10426 - refactor, párování na reactjs, povolení cors