I have a problem to implement security in my application ... I have custom authentication and use @PreAuthorize to handle my user authorization. This works fine. Now I want to implement Access Control for each user, which means in my application when two users, 'Admin' and 'John', could call method
@RequestMapping(value = "/load/{id}", method = RequestMethod.GET)
@ResponseBody
public StudentYearViewModel load(@PathVariable long id) {
return ModelMapper.map(iStudentService.loadByEntityId(id), StudentViewModel.class);
}
'Admin' can use this method for all Student instances but 'John' can see only his classmate! All users could call this method (@PreAuthorize is not suitable) but their Access is limited HOW do it?? Now have general way?
is ACL best Way?(has best example?)
HDIV framework could help me solve my problem??
what is best solution???
You want to look at
@PostFilterand@PreFilter. They work pretty much like@PreAuthorize, but can remove results from lists. You also want to assign different roles to your users, assuming you are not doing that already.Global rules, like admin being able to see everything, you can implement by writing a concrete implementation of
PermissionEvaluator. You then add that to theMethodSecurityExpressionHandlerTime for a simple example.
This code was written in a text editor. It may not compile and is only here to show the steps needed
A very simplistic
PermissionEvaluatorThen configure method security
Now we can use our filter on a method
hasPermissionin the@PostFilterACL will invokehasPermissioninMyPermissionEvaluator.filterObjectrefers to the individual items in the list. Wherever you code returns false, it will remove the item from the list.