Junky's IT Notebook

          統(tǒng)計

          留言簿(8)

          積分與排名

          WebSphere Studio

          閱讀排行榜

          評論排行榜

          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),但是使用起來確實有點麻煩,所以用的不是太廣泛。這里簡單的說明一下使用方法,希望有更多的朋友來試試。

          首先要理解Acegi里面Voter的概念,ACL正是在一個Voter上擴展起來的。現(xiàn)來看一下AclVoter的配置。

              <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>
          1. ACL_READ指的是這個Voter對哪些SecurityConfig起作用,我們可以把ACL_READ配置在想要攔截的Method上。比方說我們要攔截readOrder這個方法,以實現(xiàn)ACL控制,可以這樣配置。
            orderManager.readOrder=ACL_READ
          2. processDomainObjectClass指出哪些DomainObject是要進行ACL校驗的。
          3. aclManager是一個比較重要的概念,主要負責在權限列表中根據(jù)用戶和DomainObject取得acl列表。
          4. requirePermission指出要進行這個操作必須具備的acl權限,比方說read操作就必須有ADMINISTRATION或READ兩個權限。

          其實整個過程看下來比較清晰,下面來看一下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>


          很明顯ACLManager繼承了Acegi的一貫風格,Provider可以提供多種取得ACL訪問列表的途徑,默認的是用basicAclProvider在數(shù)據(jù)庫中取得。既然提到了數(shù)據(jù)庫,那我們就來看一下Acegi默認提供的ACL在數(shù)據(jù)庫里的保存表結構:

          1. acl_object_identity表存放了所有受保護的domainObject的信息。其中object_identity字段保存了domainObject的class和id,默認的保存格式是:domainClass:domainObjectId。
          2. acl_permission 就是ACL權限列表了,recipient 是用戶或角色信息,mask表示了這個用戶或角色對這個domainObject的訪問權限。注意這些信息的保存格式都是可以根據(jù)自己的需要改變的。

          這樣讀取和刪除的時候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>


          afterAclCollectionRead會在攔截的方法執(zhí)行結束的時候執(zhí)行。主要的作用就是在返回的List中挨個檢查domainObject的操作權限,然后根據(jù)requirePermission來剔除不符合的domainObject。

          4.3 使用RuleEngine設置的ACL規(guī)則

          在SpringSide里使用了RuleEngine來設置ACL規(guī)則,具體規(guī)則見
          bookstore-sample\resources\rules\drl

           

          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

          主站蜘蛛池模板: 贵德县| 酒泉市| 临沂市| 扎囊县| 新郑市| 八宿县| 景泰县| 白银市| 吴忠市| 泾阳县| 和硕县| 五指山市| 梁平县| 定陶县| 元江| 昆明市| 汉川市| 盘锦市| 繁昌县| 稻城县| 顺昌县| 文山县| 武夷山市| 沁水县| 普定县| 五台县| 赤壁市| 花莲市| 乌拉特前旗| 东乌| 渭源县| 游戏| 台安县| 东乌珠穆沁旗| 中方县| 连江县| 江油市| 宿迁市| 融水| 云阳县| 安徽省|