Created
January 7, 2018 14:34
-
-
Save slmanju/4ca3c2abb1ba0c1565006fc9297647a4 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
protected void configure(HttpSecurity http) throws Exception { | |
// disabling csrf since this is REST | |
http.csrf().disable(); | |
// handle unauthorized access | |
http.exceptionHandling().authenticationEntryPoint(new UnauthorizedHandler()); | |
// no need to have a user session | |
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); | |
// disable form login | |
http.httpBasic().disable(); | |
http.formLogin().disable(); | |
http.logout().disable(); | |
// permit access to token endpoint | |
http.authorizeRequests().antMatchers("/token").permitAll(); | |
// secure all requests | |
http.authorizeRequests().anyRequest().authenticated(); | |
http.cors(); | |
// custom token based authentication | |
http.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment