⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第一個acegi 程式 - 表單網頁.htm

📁 acegi+spring最新的分析
💻 HTM
📖 第 1 页 / 共 3 页
字号:
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">            
&lt;value&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
PATTERN_TYPE_APACHE_ANT</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
/protected/**=ROLE_SUPERVISOR,ROLE_USER</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/value&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/property&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;/bean&gt;</SPAN><BR></DIV><BR>FilterSecurityInteceprot需要参考至验证管理员取得验证讯息,以对使用者进行验证,而是否授权则必须以投票的方式来决定,Acegi的解决方案有几种:<BR>
<OL>
  <LI>如果有一个同意就通过 
  <LI>如果都同意就通过 
  <LI>如果都不反对就通过 
</LI></OL><BR>例如若希望/protected/下可以被使用者(USER)或管理者(SUPERVISOR)存取,采第一个方案的话则使用AffirmativeBased实作,只要有一票通过,就允许存取:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;!-- 授权管理员 --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;bean id="accessDecisionManager" 
class="org.acegisecurity.vote.AffirmativeBased"&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;!-- 是否全部弃权时视为通过 --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="allowIfAllAbstainDecisions" value="false" /&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="decisionVoters"&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;list&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;bean class="org.acegisecurity.vote.RoleVoter" /&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/list&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/property&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;/bean&gt; 
</SPAN><BR></DIV><BR>RoleVoter对使用者群组中,有ROLE_作为前置文件的进投票,您也可以在设定RoleVoter实例时,使用其rolePrefix来改变前置文字;DecisionManager收集票数,然后决定结果。<BR><BR>在所有的Filter被呼叫之前,通常会有个HttpSessionContextIntegrationFilter,它会建立Security 
Context物件,后续的Filter会将安全相关讯息储存于其中,也可以取得当中的安全相关讯息:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&lt;bean 
id="httpSessionContextIntegrationFilter"</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; 
class="org.acegisecurity.context.HttpSessionContextIntegrationFilter" 
/&gt;</SPAN><BR></DIV><BR>Acegi是基于Filter 
Chain来完成请求的检查、验证、授权等动作,所以要将以上的Filter串在一起了:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp; 
&nbsp; &lt;!-- Filter Chain --&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;bean id="filterChainProxy" 
class="org.acegisecurity.util.FilterChainProxy"&gt;&nbsp;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;property name="filterInvocationDefinitionSource"&gt;&nbsp;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;value&gt;&nbsp;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
PATTERN_TYPE_APACHE_ANT&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
/**=</SPAN><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">httpSessionContextIntegrationFilter,</SPAN><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">authenticationProcessingFilter,<BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp;exceptionTranslationFilter,filterSecurityInterceptor</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/value&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/property&gt;&nbsp; </SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;/bean&gt;</SPAN><BR></DIV><BR><SPAN 
style="COLOR: rgb(255,0,0)">由于排版的关系,将Filter的串连作了换行,实际上</SPAN><SPAN 
style="FONT-WEIGHT: bold; COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">authenticationProcessingFilter,exceptionTranslationFilter</SPAN><SPAN 
style="COLOR: rgb(255,0,0); FONT-FAMILY: Courier New,Courier,monospace">是连在一起不能换行的,请在设定时特别注意。</SPAN><BR><BR>所完成的acegi-config.xml完整档案如下所示:<BR>
<UL>
  <LI>acegi-config.xml </LI></UL><PRE>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&gt;<BR>&lt;beans&gt;<BR>    &lt;!-- 验证处理,使用表单 --&gt;<BR>    &lt;bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"&gt;  <BR>        &lt;!-- 验证管理员,处理验证资讯提供者  --&gt;<BR>        &lt;property name="authenticationManager" ref="authenticationManager"/&gt;  <BR>        &lt;!-- 验证失败URL --&gt;<BR>        &lt;property name="authenticationFailureUrl" value="/acegilogin.jsp"/&gt;  <BR>        &lt;!-- 验证成功预设URL --&gt;<BR>        &lt;property name="defaultTargetUrl" value="/protected/loginsuccess.jsp"/&gt;  <BR>        &lt;!-- 验证处理的提交位址 --&gt;<BR>        &lt;property name="filterProcessesUrl" value="/j_acegi_security_check"/&gt;  <BR>    &lt;/bean&gt;<BR><BR>    &lt;!-- 验证管理员,管理验证资讯提供者 --&gt;<BR>   &lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;  <BR>      &lt;property name="providers"&gt;&lt;!-- 可有多个提供者,其中一个验证通过即可以了 --&gt;  <BR>         &lt;list&gt;  <BR>            &lt;ref local="daoAuthenticationProvider"/&gt;  <BR>         &lt;/list&gt;  <BR>      &lt;/property&gt;  <BR>   &lt;/bean&gt;<BR><BR>   &lt;!-- 验证提供者,指定使用记忆体来源中的验证资讯 --&gt;<BR>   &lt;bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;  <BR>        &lt;property name="userDetailsService" ref="inMemoryDaoImpl"/&gt;<BR>   &lt;/bean&gt; <BR>     <BR>   &lt;bean id="inMemoryDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl"&gt;<BR>        &lt;property name="userMap"&gt;    <BR>            &lt;value&gt;    <BR>                caterpillar=123456,ROLE_SUPERVISOR<BR>                user1=user1pwd,ROLE_USER<BR>                user2=user2pwd,disabled,ROLE_USER     <BR>            &lt;/value&gt;    <BR>        &lt;/property&gt;    <BR>    &lt;/bean&gt;     <BR>    <BR>    &lt;!-- 发生验证错误或权限错误时的处理 --&gt;<BR>    &lt;bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;  <BR>        &lt;property name="authenticationEntryPoint"&gt;  <BR>            &lt;bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"&gt;  <BR>                &lt;property name="loginFormUrl" value="/acegilogin.jsp"/&gt;  <BR>                &lt;property name="forceHttps" value="false"/&gt;  <BR>            &lt;/bean&gt;  <BR>        &lt;/property&gt;  <BR>        &lt;property name="accessDeniedHandler"&gt;  <BR>            &lt;bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl"&gt;  <BR>                &lt;property name="errorPage" value="/protected/accessDenied.jsp"/&gt;  <BR>            &lt;/bean&gt;  <BR>        &lt;/property&gt;  <BR>    &lt;/bean&gt;    <BR><BR>    &lt;!-- FilterSecurityInterceptor 对 URI 进行保护 --&gt;<BR>    &lt;bean id="filterSecurityInterceptor"<BR>          class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;<BR>        &lt;!-- 验证管理员 --&gt;<BR>        &lt;property name="authenticationManager" ref="authenticationManager" /&gt;<BR>        &lt;!-- 授权管理员 --&gt;<BR>        &lt;property name="accessDecisionManager" ref="accessDecisionManager" /&gt;<BR>        &lt;property name="objectDefinitionSource"&gt;<BR>            &lt;value&gt;<BR>                CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON<BR>                PATTERN_TYPE_APACHE_ANT<BR>                /protected/**=ROLE_SUPERVISOR,ROLE_USER<BR>            &lt;/value&gt;<BR>        &lt;/property&gt;<BR>    &lt;/bean&gt;<BR>    <BR>    &lt;!-- 授权管理员 --&gt;<BR>    &lt;bean id="accessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased"&gt;<BR>         &lt;!-- 是否全部弃权时视为通过 --&gt;<BR>         &lt;property name="allowIfAllAbstainDecisions" value="false" /&gt;<BR>         &lt;property name="decisionVoters"&gt;<BR>             &lt;list&gt;<BR>                 &lt;bean class="org.acegisecurity.vote.RoleVoter" /&gt;<BR>             &lt;/list&gt;<BR>         &lt;/property&gt;<BR>    &lt;/bean&gt;        <BR><BR>    &lt;bean id="httpSessionContextIntegrationFilter"<BR>	  class="org.acegisecurity.context.HttpSessionContextIntegrationFilter" /&gt;<BR>&nbsp;<BR>    &lt;!-- Filter Chain --&gt;<BR>     &lt;bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy"&gt;  <BR>       &lt;property name="filterInvocationDefinitionSource"&gt;  <BR>          &lt;value&gt;  <BR>            CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON <BR>            PATTERN_TYPE_APACHE_ANT <BR>            /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,<BR>                 exceptionTranslationFilter,filterSecurityInterceptor<BR>         &lt;/value&gt; <BR>      &lt;/property&gt; <BR>    &lt;/bean&gt;    <BR>&lt;/beans&gt;   </PRE><BR><BR><BR></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -