JAVA CONFIG
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
...
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId(this.resource.getResourceId());
resources.accessDeniedHandler((request, response, e) -> {
RpcPayload result = new RpcPayload();
result.setSuccess(false);
result.setMessage(e.getMessage());
result.setException(e.getClass().toString());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.getWriter()
.write(objectMapper.writeValueAsString(result));
});
resources.authenticationEntryPoint((request, response, e) -> {
RpcPayload result = new RpcPayload();
result.setSuccess(false);
result.setMessage(e.getMessage());
result.setException(e.getClass().toString());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.getWriter()
.write(objectMapper.writeValueAsString(result));
});
}
...
}