Skip to content

Instantly share code, notes, and snippets.

@arnabmitra
Created July 3, 2016 19:55
Show Gist options
  • Save arnabmitra/1f93fd777d0eb7de6ef5f3eadcce9098 to your computer and use it in GitHub Desktop.
Save arnabmitra/1f93fd777d0eb7de6ef5f3eadcce9098 to your computer and use it in GitHub Desktop.
@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Inject
private CustomAccessDeniedHandler accessDeniedHandler;
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/health").permitAll().anyRequest().authenticated()
//allow all swagger resources,jersey and spring boot
.antMatchers("/something*").permitAll()
.and()
.addFilterAfter(somefilter, AbstractPreAuthenticatedProcessingFilter.class).exceptionHandling().accessDeniedHandler(accessDeniedHandler);
}
}
In the filter
catch (AccessDeniedException accessDeniedException) {
((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied:"+accessDeniedException.getLocalizedMessage());
chain.doFilter(request, response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment