?? acegi 的配置(2)-applicationcontext-acegi-security_xml - 懶散狂徒的專欄 - csdnblog.htm
字號:
<LI class=listitem><A
href="http://blog.csdn.net/anyoneking/category/301693.aspx">心情驛站</A></LI></UL>
<H3 class=listtitle>相冊</H3><!--category title-->
<UL class=list>
<LI class=listitem><A
href="http://blog.csdn.net/anyoneking/Gallery/309180.aspx">大學舍友</A>
<LI class=listitem><A
href="http://blog.csdn.net/anyoneking/Gallery/339746.aspx">家</A>
<LI class=listitem><A
href="http://blog.csdn.net/anyoneking/Gallery/309558.aspx">青海-塔爾寺</A>
<LI class=listitem><A
href="http://blog.csdn.net/anyoneking/Gallery/308364.aspx">象象-相冊</A>
<LI class=listitem><A
href="http://blog.csdn.net/anyoneking/Gallery/313985.aspx">重慶-銅梁</A>
<LI class=listitem><A
href="http://blog.csdn.net/anyoneking/Gallery/289832.aspx">重慶-武隆</A></LI></UL>
<H3 class=listtitle>BLOG類</H3>
<UL class=list>
<LI class=listitem><A href="http://www.blogjava.net/max/category/16130.html"
target=_blank>Max On Java(struts2.0)</A>
<LI class=listitem><A href="http://blog.chinaunix.net/u/22374/"
target=_blank>伏羲狂徒</A>
<LI class=listitem><A href="http://www.smatrix.org/bbs/"
target=_self>安全矩陣論壇</A>
<LI class=listitem><A
href="http://blog.csdn.net/hongbo781202/category/24820.aspx"
target=_blank>工作流</A>
<LI class=listitem><A href="http://blog.csdn.net/daryl715"
target=_blank>我的世界我的夢</A>
<LI class=listitem><A href="http://hexun.com/lvaiping/default.html"
target=_blank>象象的小窩</A></LI></UL>
<H3 class=listtitle>Web技術類</H3>
<UL class=list>
<LI class=listitem><A href="http://blog.csdn.net/HuDon"
target=_self>ACEGI學習</A>
<LI class=listitem><A href="http://www.chinaitlab.com/www/techspecial/struts/"
target=_blank>Struts</A>
<LI class=listitem><A href="http://www.blogjava.net/max"
target=_blank>STRUTS2</A>
<LI class=listitem><A href="http://tag.csdn.net/tag/struts2.xml"
target=_blank>struts2文檔</A>
<LI class=listitem><A
href="http://www.blogjava.net/rickhunter/articles/103481.html"
target=_self>struts-spring-hibernate</A>
<LI class=listitem><A href="http://www.w3pop.com/tech/"
target=_blank>網絡技術系統知識庫</A>
<LI class=listitem><A href="http://www.blogjava.net/calvin"
target=_self>花錢的年華(Spring)</A></LI></UL>
<H3 class=listtitle>工具書下載</H3>
<UL class=list>
<LI class=listitem><A href="http://man.lupaworld.com/"
target=_blank>手冊中心(linux和Java)</A></LI></UL>
<H3 class=listtitle>存檔</H3>
<UL class=list>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/11.aspx">2007年11月(4)</A>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/10.aspx">2007年10月(17)</A>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/09.aspx">2007年09月(14)</A>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/08.aspx">2007年08月(22)</A>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/07.aspx">2007年07月(34)</A>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/06.aspx">2007年06月(10)</A>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/05.aspx">2007年05月(17)</A>
<LI><A
href="http://blog.csdn.net/anyoneking/archive/2007/04.aspx">2007年04月(55)</A></LI></UL><SPAN
id=Anthem_RecentComments_ltlComments__><SPAN id=RecentComments_ltlComments>
<H3 class=listtitle>最近評論</H3>
<UL class=list>
<LI class=listitem>erway:<A title=點擊查看《回復:dwr配置文件dwr.xml詳解》
href="http://blog.csdn.net/anyoneking/archive/2007/10/31/1859749.aspx#739597">尊敬的老師:您好!<BR><BR>很榮幸能在CSDN上認識您,也非常高興您對Groony感興趣。<BR><BR>我是人民郵電出版社圖靈公司的編輯楊福川,圖靈公司最近引進了《Groovy
in
Action》一書,希望您能幫忙翻譯。如果您對翻譯此書感興趣,敬請您收到留言后與我聯系,謝謝。<BR><BR>我的聯系方式如下:<BR><BR>E-mail:yangfc……</A>
<LI class=listitem>efan101:<A title=點擊查看《回復:DB2常用命令大全》
href="http://blog.csdn.net/anyoneking/archive/2007/08/03/1723860.aspx#727031">初學者最愛!頂一下</A>
<LI class=listitem>efan101:<A title=點擊查看《回復:db2字符串的有關函數和具體用法》
href="http://blog.csdn.net/anyoneking/archive/2007/08/02/1722934.aspx#727030">非常有用,頂!</A>
<LI class=listitem>bibi:<A title=點擊查看《回復:db2字符串的有關函數和具體用法》
href="http://blog.csdn.net/anyoneking/archive/2007/08/02/1722934.aspx#725189">CHARINDEX函數是DB2里的嗎?</A>
<LI class=listitem>figo:<A title=點擊查看《回復:ACEGI標簽及其擴展》
href="http://blog.csdn.net/anyoneking/archive/2007/08/21/1752951.aspx#722756">yue
lai yue fu zai</A></LI></UL></SPAN></SPAN><BR><BR></DIV>
<DIV id=main>
<DIV class=Tag>
<SCRIPT language=javascript
src="Acegi 的配置(2)-applicationContext-acegi-security_xml - 懶散狂徒的專欄 - CSDNBlog.files/urltag.aspx"></SCRIPT>
<DIV style="CLEAR: both"></DIV></DIV><SPAN class=PreAndNext
id=viewpost.ascx_PreviousAndNextEntriesUp>
<DIV align=center><A
href="http://blog.csdn.net/anyoneking/archive/2007/08/17/1748509.aspx">上一篇: acegi安全系統標準配置指南草案</A> | <A
href="http://blog.csdn.net/anyoneking/archive/2007/08/17/1748317.aspx">下一篇: Acegi
的配置(1)-web.xml</A></DIV></SPAN><BR>
<SCRIPT>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</SCRIPT>
<DIV class=post>
<DIV class=postTitle>
<SCRIPT
src="Acegi 的配置(2)-applicationContext-acegi-security_xml - 懶散狂徒的專欄 - CSDNBlog.files/vote.js"></SCRIPT>
<A href="http://blog.csdn.net/anyoneking/archive/2007/08/17/1748490.aspx"><IMG
height=13
src="Acegi 的配置(2)-applicationContext-acegi-security_xml - 懶散狂徒的專欄 - CSDNBlog.files/zhuan.gif"
width=15 border=0> Acegi
的配置(2)-applicationContext-acegi-security.xml</A>
<SCRIPT
src="Acegi 的配置(2)-applicationContext-acegi-security_xml - 懶散狂徒的專欄 - CSDNBlog.files/count.htm"></SCRIPT>
</DIV>
<DIV class=postText>
<H2>在applicationContext-acegi-security.xml中</H2>1.FILTER CHAIN
<P> FilterChainProxy會按順序來調用這些filter,使這些 filter能享用Spring ioc的功能,
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON定義了url比較前先轉為小寫,
PATTERN_TYPE_APACHE_ANT定義了使用Apache ant的匹配模式 </P><PRE> <bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy"><BR> <property name="filterInvocationDefinitionSource"><BR> <value><BR> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON<BR> PATTERN_TYPE_APACHE_ANT<BR> /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,<BR>basicProcessingFilter,rememberMeProcessingFilter,anonymousProcessingFilter,<BR> exceptionTranslationFilter,filterInvocationInterceptor<BR> </value><BR> </property><BR> </bean></PRE>2.基礎認證
<P>1) <STRONG>authenticationManager</STRONG><BR> 起到認
證管理的作用,它將驗證的功能委托給多個Provider,并通過遍歷Providers,
以保證獲取不同來源的身份認證,若某個Provider能成功確認當前用戶的身份,authenticate()方法會返回一個完整的包含用戶授權信息的
Authentication對象,否則會拋出一個AuthenticationException。<BR>Acegi提供了不同的AuthenticationProvider的實現,如:<BR>
DaoAuthenticationProvider
從數據庫中讀取用戶信息驗證身份<BR>
AnonymousAuthenticationProvider
匿名用戶身份認證<BR>
RememberMeAuthenticationProvider
已存cookie中的用戶信息身份認證<BR>
AuthByAdapterProvider 使用容器的適配器驗證身份<BR>
CasAuthenticationProvider 根據Yale中心認證服務驗證身份,
用于實現單點登陸<BR>
JaasAuthenticationProvider
從JASS登陸配置中獲取用戶信息驗證身份<BR>
RemoteAuthenticationProvider
根據遠程服務驗證用戶身份<BR>
RunAsImplAuthenticationProvider
對身份已被管理器替換的用戶進行驗證<BR>
X509AuthenticationProvider
從X509認證中獲取用戶信息驗證身份<BR>
TestingAuthenticationProvider 單元測試時使用</P>
<P>
每個認證者會對自己指定的證明信息進行認證,如DaoAuthenticationProvider僅對UsernamePasswordAuthenticationToken這個證明信息進行認證。</P><PRE><bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"><BR> <property name="providers"><BR> <list><BR> <ref local="daoAuthenticationProvider"/><BR> <ref local="anonymousAuthenticationProvider"/><BR> <ref local="rememberMeAuthenticationProvider"/><BR> </list><BR> </property><BR></bean></PRE>
<P><BR>2) <STRONG>daoAuthenticationProvider</STRONG><BR>
進行簡單的基于數據庫的身份驗證。DaoAuthenticationProvider獲取數據庫中的賬號密碼并進行匹配,若成功則在通過用戶身份的同
時返回一個包含授權信息的Authentication對象,否則身份驗證失敗,拋出一個AuthenticatiionException。</P><PRE> <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"><BR> <property name="userDetailsService" ref="jdbcDaoImpl"/><BR> <property name="userCache" ref="userCache"/><BR> <property name="passwordEncoder" ref="passwordEncoder"/><BR> </bean></PRE>
<P><BR>3) <STRONG>passwordEncoder</STRONG>
<BR> 使用加密器對用戶輸入的明文進行加密。Acegi提供了三種加密器:<BR>PlaintextPasswordEncoder—默認,不加密,返回明文.<BR>ShaPasswordEncoder—哈希算法(SHA)加密<BR>Md5PasswordEncoder—消息摘要(MD5)加密</P><PRE><bean id="passwordEncoder" class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"/></PRE>
<P><BR>4) <STRONG>jdbcDaoImpl</STRONG> <BR> 用于在數據中獲取用戶信息。
acegi提供了用戶及授權的表結構,但是您也可以自己來實現。通過usersByUsernameQuery這個SQL得到你的(用戶ID,密碼,狀態
信息);通過authoritiesByUsernameQuery這個SQL得到你的(用戶ID,授權信息)</P><PRE> <bean id="jdbcDaoImpl" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"><BR> <property name="dataSource" ref="dataSource"/><BR> <property name="usersByUsernameQuery"><BR> <value>select loginid,passwd,1 from users where loginid = ?</value><BR> </property><BR> <property name="authoritiesByUsernameQuery"><BR> <value>select u.loginid,p.name from users u,roles r,permissions p,user_role ur,role_permis rp where u.id=ur.user_id and r.id=ur.role_id and p.id=rp.permis_id and<BR> r.id=rp.role_id and p.status='1' and u.loginid=?</value><BR> </property><BR></bean></PRE>
<P>5) <STRONG>userCache & resourceCache</STRONG>
<BR> 緩存用戶和資源相對應的權限信息。每當請求一個受保護資源時,daoAuthenticationProvider就會被調用以獲取用戶授權信息。如果每次都從數據庫獲取的話,那代價很高,對于不常改變的用戶和資源信息來說,最好是把相關授權信息緩存起來。(詳見
<A href="http://www.springside.org.cn/docs/reference/Acegi4.htm">2.6.3
資源權限定義擴展</A> )<BR>userCache提供了兩種實現: NullUserCache和EhCacheBasedUserCache,
NullUserCache實際上就是不進行任何緩存,EhCacheBasedUserCache是使用Ehcache來實現緩功能。</P><PRE> <bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean"><BR> <property name="cacheManager" ref="cacheManager"/><BR> <property name="cacheName" value="userCache"/><BR> </bean><BR> <bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache" autowire="byName"><BR> <property name="cache" ref="userCacheBackend"/><BR> </bean><BR> <bean id="resourceCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean"><BR> <property name="cacheManager" ref="cacheManager"/><BR> <property name="cacheName" value="resourceCache"/><BR> </bean><BR> <bean id="resourceCache" class="org.springside.modules.security.service.acegi.cache.ResourceCache" autowire="byName"><BR> <property name="cache" ref="resourceCacheBackend"/><BR> </bean></PRE>
<P><BR>6) <STRONG>basicProcessingFilter</STRONG> <BR>
用于處理HTTP頭的認證信息,如從Spring遠程協議(如Hessian和Burlap)或普通的瀏覽器如IE,Navigator的HTTP頭中
獲取用戶信息,將他們轉交給通過authenticationManager屬性裝配的認證管理器。如果認證成功,會將一個Authentication
對象放到會話中,否則,如果認證失敗,會將控制轉交給認證入口點(通過authenticationEntryPoint屬性裝配)</P><PRE> <bean id="basicProcessingFilter" class="org.acegisecurity.ui.basicauth.BasicProcessingFilter"><BR> <property name="authenticationManager" ref="authenticationManager"/><BR> <property name="authenticationEntryPoint" ref="basicProcessingFilterEntryPoint"/><BR> </bean></PRE>
<P>7) <STRONG>basicProcessingFilterEntryPoint</STRONG>
<BR> 通過向瀏覽器發送一個HTTP401(未授權)消息,提示用戶登錄。<BR>處理基于HTTP的授權過程,
在當驗證過程出現異常后的"去向",通常實現轉向、在response里加入error信息等功能。</P><PRE> <bean id="basicProcessingFilterEntryPoint" class="org.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint"><BR> <property name="realmName" value="SpringSide Realm"/><BR></bean></PRE>
<P>8) <STRONG>authenticationProcessingFilterEntryPoint</STRONG> <BR>
當拋出AccessDeniedException時,將用戶重定向到登錄界面。屬性loginFormUrl配置了一個登錄表單的URL,當需要用戶
登錄時,authenticationProcessingFilterEntryPoint會將用戶重定向到該URL</P><PRE> <bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"><BR> <property name="loginFormUrl"><BR> <value>/security/login.jsp</value><BR> </property><BR> <property name="forceHttps" value="false"/><BR></bean></PRE>
<H2>2.2.3 HTTP安全請求</H2>
<P>1) <STRONG>httpSessionContextIntegrationFilter</STRONG><BR> 每次request前
HttpSessionContextIntegrationFilter從Session中獲取Authentication對象,在request完 后,
又把Authentication對象保存到Session中供下次request使用,此filter必須其他Acegi
filter前使用,使之能跨越多個請求。</P><PRE><bean id="httpSessionContextIntegrationFilter" class="org.acegisecurity.context.HttpSessionContextIntegrationFilter"></bean><BR> <bean id="httpRequestAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased"><BR> <property name="allowIfAllAbstainDecisions" value="false"/><BR> <property name="decisionVoters"><BR> <list><BR> <ref bean="roleVoter"/><BR> </list><BR> </property><BR></bean></PRE>
<P><BR>2) <STRONG>httpRequestAccessDecisionManager</STRONG><BR>
經過投票機制來決定是否可以訪問某一資源(URL或方法)。allowIfAllAbstainDecisions為false時如果有一個或以上的
decisionVoters投票通過,則授權通過。可選的決策機制有ConsensusBased和UnanimousBased</P><PRE> <bean id="httpRequestAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased"><BR> <property name="allowIfAllAbstainDecisions" value="false"/><BR> <property name="decisionVoters"><BR> <list><BR> <ref bean="roleVoter"/><BR> </list><BR> </property><BR> </bean></PRE>
<P><BR>3)
<STRONG>roleVoter</STRONG><BR> 必須是以rolePrefix設定的value開頭的權限才能進行投票,如AUTH_ ,
ROLE_</P><PRE> <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter"><BR> <property name="rolePrefix" value="AUTH_"/><BR> </bean></PRE>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -