Created
July 3, 2016 19:55
-
-
Save arnabmitra/1f93fd777d0eb7de6ef5f3eadcce9098 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
@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