|
@@ -15,6 +15,13 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
|
|
|
+import org.springframework.web.cors.CorsConfiguration;
|
|
|
|
|
+import org.springframework.web.cors.CorsConfigurationSource;
|
|
|
|
|
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
|
|
|
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
|
|
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
|
|
|
|
|
|
|
@@ -28,14 +35,25 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void configure(HttpSecurity http) throws Exception {
|
|
protected void configure(HttpSecurity http) throws Exception {
|
|
|
|
|
+ http.cors();
|
|
|
http.csrf().disable();
|
|
http.csrf().disable();
|
|
|
http.sessionManagement().sessionCreationPolicy(STATELESS);
|
|
http.sessionManagement().sessionCreationPolicy(STATELESS);
|
|
|
- http.authorizeRequests().antMatchers("/api/v*/registration/**", "/api/v*/users/token/refresh/**").permitAll();
|
|
|
|
|
|
|
+ http.authorizeRequests().antMatchers("/api/v*/registration/**", "/api/v*/users/token/refresh/**", "/api/v*/plants/no-auth").permitAll();
|
|
|
http.authorizeRequests().antMatchers("/api/v*/**").hasAnyAuthority("USER");
|
|
http.authorizeRequests().antMatchers("/api/v*/**").hasAnyAuthority("USER");
|
|
|
http.addFilter(new CustomAuthenticationFilter(authenticationManagerBean()));
|
|
http.addFilter(new CustomAuthenticationFilter(authenticationManagerBean()));
|
|
|
http.addFilterBefore(new CustomAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class);
|
|
http.addFilterBefore(new CustomAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ CorsConfigurationSource corsConfigurationSource() {
|
|
|
|
|
+ CorsConfiguration configuration = new CorsConfiguration();
|
|
|
|
|
+ configuration.setAllowedOrigins(Collections.singletonList("http://localhost:3000"));
|
|
|
|
|
+ configuration.setAllowedMethods(Arrays.asList("GET","POST"));
|
|
|
|
|
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
|
|
+ source.registerCorsConfiguration("/**", configuration);
|
|
|
|
|
+ return source;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Bean
|
|
@Bean
|
|
|
@Override
|
|
@Override
|
|
|
public AuthenticationManager authenticationManagerBean() throws Exception {
|
|
public AuthenticationManager authenticationManagerBean() throws Exception {
|
|
@@ -43,7 +61,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
|
|
|
|
|
+ protected void configure(AuthenticationManagerBuilder auth){
|
|
|
auth.authenticationProvider(daoAuthenticationProvider());
|
|
auth.authenticationProvider(daoAuthenticationProvider());
|
|
|
}
|
|
}
|
|
|
@Bean
|
|
@Bean
|