热卖商品
新闻详情
Acegi安全系统介绍 (二)
来自 : www.uml.org.cn/zjjs/2008121...
发布时间:2021-03-25
1publicclassResourceCache{
2publicResourceDetailsgetAuthorityFromCache(StringresString){
3
4}
5publicvoidputAuthorityInCache(ResourceDetailsresourceDetails){
6
7}
8publicvoidremoveAuthorityFromCache(StringresString){
9
10}
11publicListgetUrlResStrings(){
12
13}
14publicListgetFunctions(){
15
16}
17}
public StringgetResString();
public StringgetResType();
public GrantedAuthority[]getAuthorities();
}
2 private ResourceCacheresourceCache;
3 private UserCacheuserCache;
4
5 /***/ /** *修改User时更改userCache */
6 public void modifyUserInCache(Useruser,StringorgUsername) {
7
8 }
9 /***/ /** *修改Resource时更改resourceCache */
public void modifyResourceInCache(Resourceresource,StringorgResourcename) {
}
/***/ /** *修改权限时同时修改userCache和resourceCache */
public void modifyPermiInCache(Permissionpermi,StringorgPerminame) {
}
/***/ /** *User授予角色时更改userCache */
public void authRoleInCache(Useruser) {
}
/***/ /** *Role授予权限时更改userCache和resourceCache */
public void authPermissionInCache(Rolerole) {
}
/***/ /** *Permissioni授予资源时更改resourceCache */
public void authResourceInCache(Permissionpermi) {
}
/***/ /** *初始化userCache */
public void initUserCache() {
}
/***/ /** *初始化resourceCache */
public void initResourceCache() {}
/***/ /** *获取所有的url资源 */
public ListgetUrlResStrings() {
}
/***/ /** *获取所有的Funtion资源 */
public ListgetFunctions() {
}
/***/ /** *根据资源串获取资源 */
public ResourceDetailsgetAuthorityFromCache(StringresString) {
}
}
2 property name = authenticationManager
3 ref bean = authenticationManager
4 property
5 property name = accessDecisionManager
6 ref local = businessAccessDecisionManager
7 property
8 property name = afterInvocationManager
9 ref local = afterInvocationManager
property
property name = objectDefinitionSource
value
sample.contact.ContactManager.create=ROLE_USER
sample.contact.ContactManager.getAllRecipients=ROLE_USER
sample.contact.ContactManager.getAll=ROLE_USER,AFTER_ACL_COLLECTION_READ
sample.contact.ContactManager.getById=ROLE_USER,AFTER_ACL_READ
sample.contact.ContactManager.delete=ACL_CONTACT_DELETE
sample.contact.ContactManager.deletePermission=ACL_CONTACT_ADMIN
sample.contact.ContactManager.addPermission=ACL_CONTACT_ADMIN
value
property
bean
2publicResourceDetailsgetAuthorityFromCache(StringresString){
3
4}
5publicvoidputAuthorityInCache(ResourceDetailsresourceDetails){
6
7}
8publicvoidremoveAuthorityFromCache(StringresString){
9
10}
11publicListgetUrlResStrings(){
12
13}
14publicListgetFunctions(){
15
16}
17}
而ResourceCache 是对ResourceDetails 类进行缓存管理
public interface ResourceDetails extends Serializable {public StringgetResString();
public StringgetResType();
public GrantedAuthority[]getAuthorities();
}
GrantedAuthority 就是权限信息,在Acegi 的 sample 里GrantedAuthority 的信息如ROLE_USER, ROLE_SUPERVISOR, ACL_CONTACT_DELETE, ACL_CONTACT_ADMIN等等,网上也有很多例子把角色作为GrantedAuthority ,但事实上看看ACL 就知道, Acegi本身根本就没有角色这个概念,GrantedAuthority 包含的信息应该是权限,对于非ACL的权限用 AUTH_ 开头更为合理, 如SpringSide里的 AUTH_ADMIN_LOGIN, AUTH_BOOK_MANAGE 等等。
3.2.2 管理缓存
使用AcegiCacheManager对userCache和resourceCache进行统一缓存管理。当在后台对用户信息进行修改或赋权的时候, 在更新数据库同时就会调用acegiCacheManager相应方法, 从数据库中读取数据并替换cache中相应部分,使cache与数据库同步
1 public class AcegiCacheManager extends BaseService {2 private ResourceCacheresourceCache;
3 private UserCacheuserCache;
4
5 /***/ /** *修改User时更改userCache */
6 public void modifyUserInCache(Useruser,StringorgUsername) {
7
8 }
9 /***/ /** *修改Resource时更改resourceCache */
public void modifyResourceInCache(Resourceresource,StringorgResourcename) {
}
/***/ /** *修改权限时同时修改userCache和resourceCache */
public void modifyPermiInCache(Permissionpermi,StringorgPerminame) {
}
/***/ /** *User授予角色时更改userCache */
public void authRoleInCache(Useruser) {
}
/***/ /** *Role授予权限时更改userCache和resourceCache */
public void authPermissionInCache(Rolerole) {
}
/***/ /** *Permissioni授予资源时更改resourceCache */
public void authResourceInCache(Permissionpermi) {
}
/***/ /** *初始化userCache */
public void initUserCache() {
}
/***/ /** *初始化resourceCache */
public void initResourceCache() {}
/***/ /** *获取所有的url资源 */
public ListgetUrlResStrings() {
}
/***/ /** *获取所有的Funtion资源 */
public ListgetFunctions() {
}
/***/ /** *根据资源串获取资源 */
public ResourceDetailsgetAuthorityFromCache(StringresString) {
}
}
3.3 资源权限定义扩展
Acegi给出的sample里,资源权限对照关系是配置在xml中的,试想一下如果你的企业安全应用有500个用户,100个角色权限的时候,维护这个xml将是个繁重无比的工作,如何动态更改用户权限更是个头痛的问题
1 bean = contactManagerSecurity class = org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor2 property name = authenticationManager
3 ref bean = authenticationManager
4 property
5 property name = accessDecisionManager
6 ref local = businessAccessDecisionManager
7 property
8 property name = afterInvocationManager
9 ref local = afterInvocationManager
property
property name = objectDefinitionSource
value
sample.contact.ContactManager.create=ROLE_USER
sample.contact.ContactManager.getAllRecipients=ROLE_USER
sample.contact.ContactManager.getAll=ROLE_USER,AFTER_ACL_COLLECTION_READ
sample.contact.ContactManager.getById=ROLE_USER,AFTER_ACL_READ
sample.contact.ContactManager.delete=ACL_CONTACT_DELETE
sample.contact.ContactManager.deletePermission=ACL_CONTACT_ADMIN
sample.contact.ContactManager.addPermission=ACL_CONTACT_ADMIN
value
property
bean
本文链接: http://acegi0.immuno-online.com/view-724516.html
发布于 : 2021-03-25
阅读(0)
最新动态
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
公司介绍
品牌分类
联络我们