常言笑的家

          Spring, Hibernate, Struts, Ajax, RoR

          Acegi 使用 Acl(1)

          首先要配置一個(gè)filter,這個(gè)filter用一個(gè)代理bean寫(xiě)在了spring里面,其實(shí)根正常的filter沒(méi)有任何區(qū)別。

          代碼
          1<bean id="securityEnforcementFilter"   
          2    class="org.acegisecurity.intercept.web.SecurityEnforcementFilter">   
          3    <property name="filterSecurityInterceptor">   
          4        <ref local="filterInvocationInterceptor" />   
          5    </property>   
          6    <property name="authenticationEntryPoint">   
          7        <ref local="authenticationProcessingFilterEntryPoint" />   
          8    </property>   
          9</bean>  

           

          "filterInvocationInterceptor" 是一個(gè)攔截器,說(shuō)是攔截器,其實(shí)就是在filter里面執(zhí)行一下他的攔截方法,這里可沒(méi)有什么aop.
          authenticationEntryPoint 交驗(yàn)失敗的時(shí)候轉(zhuǎn)到的地方,為什么說(shuō)是地方,因?yàn)橥ㄟ^(guò)配置可以轉(zhuǎn)到其它的url甚至其它的協(xié)議下(http 轉(zhuǎn)到 https等等)
           
          代碼
           1<bean id="authenticationProcessingFilterEntryPoint"   
           2    class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">   
           3    <property name="loginFormUrl">   
           4        <value>/error.security</value>   
           5    </property>   
           6    <property name="forceHttps">   
           7        <value>false</value>   
           8    </property>   
           9</bean>  
          10

           

          這個(gè)就是失敗的時(shí)候轉(zhuǎn)到的地方,我們可以配置url和是否使用https

           

          代碼
           1<bean id="filterInvocationInterceptor"   
           2    class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">   
           3    <property name="authenticationManager">   
           4        <ref bean="authenticationManager" />   
           5    </property>   
           6    <property name="accessDecisionManager">   
           7        <ref local="httpRequestAccessDecisionManager" />   
           8    </property>   
           9    <property name="objectDefinitionSource">   
          10        <value>   
          11            CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON    
          12            PATTERN_TYPE_APACHE_ANT    
          13            /index.jsp=ROLE_ANONYMOUS,ROLE_USER    
          14            /j_acegi_switch_user=ROLE_SUPERVISOR   
          15            /login.security=ROLE_ANONYMOUS,ROLE_USER                /test.do=ROLE_CODER   
          16            /**.do*=ROLE_USER    
          17        </value>   
          18    </property>   
          19</bean>  

           

          這個(gè)就是前面提到的攔截器。簡(jiǎn)單解釋一下:
          authenticationManager 在acegi里面的主要作用就是管理維護(hù)用戶的權(quán)限角色等信息,比方說(shuō)想要用戶的ROLE就要在這里面拿了。里面配置了多種全縣的來(lái)源,可以從DAO里面來(lái)(就是數(shù)據(jù)庫(kù)里面),可以是cookies里面的,也可以是匿名的權(quán)限,每種權(quán)限都以一種Provider的形式提供:

          代碼
           1<bean id="authenticationManager"   
           2    class="org.acegisecurity.providers.ProviderManager">   
           3    <property name="providers">   
           4        <list>   
           5            <ref local="daoAuthenticationProvider" />   
           6            <ref local="anonymousAuthenticationProvider" />   
           7            <ref local="rememberMeAuthenticationProvider" />   
           8        </list>   
           9    </property>   
          10</bean>

           

          objectDefinitionSource在acegi里面就是配置權(quán)限信息,說(shuō)明哪一個(gè)url需要什么權(quán)限才能訪問(wèn),acegi默認(rèn)用<value>來(lái)表示,其實(shí)這正是acegi的不足之處,還好能夠補(bǔ)救。我來(lái)說(shuō)明一下:
          我們知道在spring里面<value>標(biāo)簽比較特殊,spring首先找到這個(gè)屬性的類型,然后把value里面的內(nèi)容以String的類型取出來(lái)(Spring做了一下包裝,為TypedString)。然后根據(jù)這個(gè)屬性的類型找他的Editer,然后用Editer來(lái)處理String為需要的類型。但是我們不希望用String來(lái)表達(dá)url,很明顯url里面有=就不會(huì)玩了。我們可以把這個(gè)信息寫(xiě)到數(shù)據(jù)庫(kù)里面,然后讀取,這里面不說(shuō)了以前有一位高手已經(jīng)解釋過(guò)了。

          接下來(lái)就是httpRequestAccessDecisionManager了,AccessDecisionManager在acegi里面是決策者,就是根據(jù)你所擁有的權(quán)限和訪問(wèn)URL需要的權(quán)限來(lái)決定你到底能不能訪問(wèn)。

           

          代碼
           1<bean id="httpRequestAccessDecisionManager"   
           2    class="org.acegisecurity.vote.AffirmativeBased">   
           3    <property name="allowIfAllAbstainDecisions">   
           4        <value>false</value>   
           5    </property>   
           6    <property name="decisionVoters">   
           7        <list>   
           8            <ref bean="roleVoter" />   
           9        </list>   
          10    </property>   
          11</bean>  

           

          決策者里面是投票者,這個(gè)上面已經(jīng)解釋過(guò)了,一個(gè)投票者校驗(yàn)一種權(quán)限。整個(gè)流程已經(jīng)說(shuō)完了。

          posted on 2006-12-16 22:27 常言笑 閱讀(217) 評(píng)論(0)  編輯  收藏 所屬分類: JAVA/J2EE

          My Links

          Blog Stats

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 济南市| 林西县| 雷山县| 铜川市| 伊宁市| 新闻| 苏尼特右旗| 广昌县| 班玛县| 永丰县| 和硕县| 平原县| 城口县| 朝阳市| 鲁甸县| 封丘县| 会理县| 宿松县| 巴塘县| 商丘市| 当阳市| 资源县| 广元市| 贡嘎县| 太白县| 徐闻县| 东莞市| 鄂托克前旗| 景宁| 临江市| 屏东县| 晋宁县| 华池县| 咸宁市| 花莲县| 固镇县| 临沧市| 五原县| 宜阳县| 清原| 伊宁市|