Skip to content

Instantly share code, notes, and snippets.

@slmanju
Created January 7, 2018 14:34
Show Gist options
  • Save slmanju/4ca3c2abb1ba0c1565006fc9297647a4 to your computer and use it in GitHub Desktop.
Save slmanju/4ca3c2abb1ba0c1565006fc9297647a4 to your computer and use it in GitHub Desktop.
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