Give Anonymous access to handlers using @Secured in Spring



If you have implemented Spring Role based security and you are securing your controller methods using @Secured annotation.
You may face one problem where you need to give User restricted access(Logged In User) as well as Anonymous user access(without login) to a handler in your controller.

I have implemeted this solution like

@Secured({ROLE_CONSUMER_NAME,"IS_AUTHENTICATED_ANONYMOUSLY"})
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody APIResponse login()
{
// Your Logic
}

Hope this will be helpful to you. Please like if you find this useful and comment for any further clarification.