UPDATE (17.04.2012): So what I have as result.
root-context.xml:
<context:annotation-config/>
<context:component-scan base-package="com.grsnet.qvs.controller.web"/>
<security:global-method-security pre-post-annotations="enabled" />
<bean id="permissionManager" class="com.grsnet.qvs.auth.PermissionManager"/>
PermissionManager.java
package com.grsnet.qvs.auth;
import com.grsnet.qvs.model.Benutzer;
public class PermissionManager {
public PermissionManager() {}
public boolean hasPermissionU01(Object principal, Integer permissionLevel) {
return ((Benutzer)principal).getPermission().getU_01() >= permissionLevel;
}
}
Controller:
@PreAuthorize("@permissionManager.hasPermissionU01(principal, 1)")
@RequestMapping(value = "/u01", method = RequestMethod.GET)
public String listU01(HttpServletRequest request, Map<String, Object> map) throws Exception {
setGridFilters(map);
return "u01panel";
}
I set break point in PermissionManager.hasPermissionU01. it seems my security annotation just ignored.
What is the reason? Where is my mistake?
Thanks.
END OF UPDATE
After hours of googling I have to ask here. I have
- Spring MVC app
- CustomUserDetailService
Custom UserDetails class
public class Benutzer extends User implements UserDetails { ... private Permission permission = null; ... }
Permissions class, not very good realized, but I have to use it.
public class Permission { ... private Integer u_01 = 0; ... }
Controller
@Controller public class U01Controller { @RequestMapping(value = "/u01", method = RequestMethod.GET) public String listU01(HttpServletRequest request, Map<String, Object> map) throws Exception {
My task is to secure the controller at whole and to secure a methods inside. I would like to write some like this:
@PreAuthorize("principal.permission.u_01>0")
public class U01Controller {
and
@RequestMapping(value = "/u01", method = RequestMethod.GET)
@PreAuthorize("principal.permission.u_01=2")
public String listU01(HttpServletRequest request, Map<String, Object> map) throws Exception {
It seems ACL uses UserDetails interface to gain access to a principal. Is it probably to make some type cast inside ACL?
@PreAuthorize("(com.grsnet.qvs.model.Benutzer)principal.permission.u_01=2")
Thanks in advance.