You cannot call a private method, but you can call a method in another spring bean. In my application, I have @Component named permissionEvaluator. Then I refer to @PreAuthorize as follows:
@PreAuthorize("@permissionEvaluator.canViewImageSet( #imageSet, principal )") @RequestMapping(value="/image", method=RequestMethod.GET ) public String getImage( @RequestParam(value="imageSet", required=false) ImageSet imageSet ) {
PermissionEvaluatorImpl looks like this:
@Component(value="permissionEvaluator") public class PermissionEvaluatorImpl implements PermissionEvaluator { public PermissionEvaluatorImpl() {} public boolean canViewImageSet( ImageSet imageSet, UserDetailsAdapter user ) {
and PermissionEvaluator is my own interface, which is nothing special, just whatever methods I have to evaluate.
source share