I am using Spring 3 and implemented MVC using simpleUrlMapping. I am having CustomerController
class. In CustomerController
I am having three methods:
The above actions are getting called using method name resolver.
My requirement over here depending upon the logged in user and privilege I want to protect the corresponding method calls.
Delete customer method should be called by the privilege user and not by all the user.
I am using Spring Security as well. Is there any way to protect the delete customer method with Spring security?
options:
@RequestMapping
public void deleteCustomer(HttpServletRequest request) {
if(request.isUserInRole("ROLE_ADMIN"){
// do deletion
};
}
or use @EnableGlobalMethodSecurity
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping
public void deleteCustomer(HttpServletRequest request) {