Acegi安全系統(tǒng)擴展 ----- Acegi ACL使用
4.1 基本概念在google中搜索'acl'會找到很多相關的介紹,而且涉及的范圍也特別廣泛。ACL是(Access Control List)的縮寫,顧名思義,ACL是‘訪問控制列表’的意思。通俗點說,ACL保存了所有用戶或角色對資源的訪問權限。最典型的ACL實現(xiàn)是流行操作系統(tǒng)(window, unix)的文件訪問控制系統(tǒng),精確定義了某個用戶或角色對某個特定文件的讀、寫、執(zhí)行等權限,更通俗的例子是可以定義某個管理員只能管一部分的訂單,而另一個管理員只能管另一部分的。 4.2 Acegi ACL配置Acegi好早就實現(xiàn)了ACL(好像是0.5),但是使用起來確實有點麻煩,所以用的不是太廣泛。這里簡單的說明一下使用方法,希望有更多的朋友來試試。 <bean id="aclBeanReadVoter" class="org.acegisecurity.vote.BasicAclEntryVoter">
<property name="processConfigAttribute"> <value>ACL_READ</value> </property> <property name="processDomainObjectClass"> <value>org.springside.modules.security.acl.domain.AclDomainAware</value> </property> <property name="aclManager"> <ref local="aclManager"/> </property> <property name="requirePermission"> <list> <ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/> <ref local="org.acegisecurity.acl.basic.SimpleAclEntry.READ"/> </list> </property> </bean>
其實整個過程看下來比較清晰,下面來看一下AclManager如何配置。 <!-- ========= ACCESS CONTROL LIST LOOKUP MANAGER DEFINITIONS ========= -->
<bean id="aclManager" class="org.acegisecurity.acl.AclProviderManager"> <property name="providers"> <list> <ref local="basicAclProvider"/> </list> </property> </bean> <bean id="basicAclProvider" class="org.acegisecurity.acl.basic.BasicAclProvider"> <property name="basicAclDao"> <ref local="basicAclExtendedDao"/> </property> </bean> <bean id="basicAclExtendedDao" class="org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl"> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean>
這樣讀取和刪除的時候Acegi就能很好的完成攔截工作,但是讀取一個List的時候,如何才能把該用戶不能操作的domainObject剔除掉呢?這就需要afterInvocationManager來完成這個工作。下面來看下配置: <!-- ============== "AFTER INTERCEPTION" AUTHORIZATION DEFINITIONS =========== -->
<bean id="afterInvocationManager" class="org.acegisecurity.afterinvocation.AfterInvocationProviderManager"> <property name="providers"> <list> <ref local="afterAclCollectionRead"/> </list> </property> </bean> <!-- Processes AFTER_ACL_COLLECTION_READ configuration settings --> <bean id="afterAclCollectionRead" class="org.acegisecurity.afterinvocation.BasicAclEntryAfterInvocationCollectionFilteringProvider"> <property name="aclManager"> <ref local="aclManager"/> </property> <property name="requirePermission"> <list> <ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/> <ref local="org.acegisecurity.acl.basic.SimpleAclEntry.READ"/> </list> </property> </bean>
4.3 使用RuleEngine設置的ACL規(guī)則在SpringSide里使用了RuleEngine來設置ACL規(guī)則,具體規(guī)則見
CREATE TABLE acl_object_identity (
id IDENTITY NOT NULL, object_identity VARCHAR_IGNORECASE(250) NOT NULL, parent_object INTEGER, acl_class VARCHAR_IGNORECASE(250) NOT NULL, CONSTRAINT unique_object_identity UNIQUE(object_identity), FOREIGN KEY (parent_object) REFERENCES acl_object_identity(id) ); CREATE TABLE acl_permission ( id IDENTITY NOT NULL, acl_object_identity INTEGER NOT NULL, recipient VARCHAR_IGNORECASE(100) NOT NULL, mask INTEGER NOT NULL, CONSTRAINT unique_recipient UNIQUE(acl_object_identity, recipient), FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id) ); |
posted on 2007-06-27 15:13 junky 閱讀(464) 評論(0) 編輯 收藏 所屬分類: security