我想使用 Spring Security 来管理用户、组和权限。
我想使用 ACL 来保护我的域对象,但我找不到将组分配给 acl 的方法。
例如:
我有用户和组。每个组可以拥有以下证券:
- 管理论坛(可以是类似的角色ROLE_FORUM_MANAGER
)
- 编辑特定论坛(特定论坛上的 acl)。
此外,组是由具有角色的用户定义的ROLE_PERMISSION_MANAGER
。但该用户定义的所有组只能由该用户编辑和管理。因此组附加到用户。确切地说,假设用户创建了一个google组:该用户只能为他创建的组管理权限组。这样他就可以创建组来管理自己的谷歌组的特定论坛。
我该怎么做?
我阅读了 spring security 文档和以下教程(所以请不要将我发送到这些链接):http://grzegorzborkowski.blogspot.com/2008/10/spring-security-acl-very-basic-tutorial.html http://grzegorzborkowski.blogspot.com/2008/10/spring-security-acl-very-basic-tutorial.html
http://blog.denksoft.com/?page_id=20 http://blog.denksoft.com/?page_id=20
检查 Spring Security 3.0,您也许可以通过使用 Spring 表达式语言来完全避免使用 ACL。
例如,为了编辑论坛,您将有一个像这样的安全方法:
@PreAuthorize("hasRole('ROLE_FORUM_MANAGER') and hasPermission(#forum,'update'))
public void updateForum(Forum forum) {
//some implementation
}
然后,您可以在自定义权限评估器中实现 hasPermission 方法,例如:
public class ForumPermissionEvaluator implements PermissionEvaluator {
public boolean hasPermission(Authentication authentication,
Object domainObject, Object permission) {
//implement
}
public boolean hasPermission(Authentication authentication,
Serializable targetId, String targetType, Object permission) {
//implement
}
}
最后,在应用程序配置中将其连接在一起:
<beans:bean id="expressionHandler"
class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<beans:property name="permissionEvaluator" ref="permissionEvaluator"/>
</beans:bean>
<beans:bean id="permissionEvaluator"
class="x.y.z.ForumPermissionEvaluator" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)