Created
December 6, 2017 19:19
-
-
Save ugurcemozturk/55206628b38d3912890288d74aa93d3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EnableWebSecurity | |
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | |
private UserDetailsService userDetailsService; | |
@Autowired | |
private BCryptPasswordEncoder bCryptPasswordEncoder; | |
public WebSecurityConfig(UserDetailsService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) { | |
this.userDetailsService = userDetailsService; | |
this.bCryptPasswordEncoder = bCryptPasswordEncoder; | |
} | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.cors().and().csrf().disable().authorizeRequests() | |
.antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll() | |
.anyRequest().authenticated() | |
.and() | |
.addFilter(new JWTAuthenticationFilter(authenticationManager())) | |
.addFilter(new JWTAuthorizationFilter(authenticationManager())) | |
// this disables session creation on Spring Security | |
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); | |
} | |
@Override | |
public void configure(AuthenticationManagerBuilder auth) throws Exception { | |
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder); | |
auth.inMemoryAuthentication() | |
.withUser("cem") | |
.password("pass") | |
.roles("ADMIN"); | |
} | |
@Bean | |
CorsConfigurationSource corsConfigurationSource() { | |
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | |
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues()); | |
return source; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment