0
点赞
收藏
分享

微信扫一扫

Acegi-security-samples-tutorial-1.0.7.zip 实例学习笔记


eclipse环境下新建一个web project项目AcegiTest,把Acegi-security-samples-tutorial-1.0.7.zip 中的代码放入项目中的对应目录下:


Acegi-security-samples-tutorial-1.0.7.zip 实例学习笔记_bean

IE地址栏输入:http://localhost/AcegiTest/

转到index.jsp  页面: 


主页

任何人可浏览此页面。

安全页面

超级安全页面

 


(1)点“安全页面”则进入登录页面acegilogin.jsp:

当peter登录是则显示:

抱歉,您登录失败,请重新登录!
原因: User is disabled

当其他用户登录时则进入安全页面,点“退出”转到主页,再点其他链接则自动转到登录页面。

 

(2)点“超级安全页面”则进入登录页面acegilogin.jsp:

当peter登录是则显示:

抱歉,您登录失败,请重新登录!
原因: User is disabled

当普通用户登录时则显示:

对不起,您无权访问!

org.acegisecurity.AccessDeniedException: Access is denied

Authentication object as a String: org.acegisecurity.providers.UsernamePasswordAuthenticationToken@6178e6d6: Username: org.acegisecurity.userdetails.User@bc43000: Username: scott; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Password: [PROTECTED]; Authenticated: true; Details: org.acegisecurity.ui.WebAuthenticationDetails@fffe3f86: RemoteIpAddress: 127.0.0.1; SessionId: 936492B5C00BF262EF5DBC490C64C190; Granted Authorities: ROLE_USER

当超级用户登录时,则转到非常安全页面。

实现该功能主要是:

<bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"> 
  
       <property name="authenticationManager" ref="authenticationManager"/> 
  
       <property name="accessDecisionManager"> 
  
           <bean class="org.acegisecurity.vote.AffirmativeBased"> 
  
              <property name="allowIfAllAbstainDecisions" value="false"/> 
  
              <property name="decisionVoters"> 
  
                  <list> 
  
                     <bean class="org.acegisecurity.vote.RoleVoter"/> 
  
                     <bean class="org.acegisecurity.vote.AuthenticatedVoter"/> 
  
                  </list> 
  
              </property> 
  
           </bean> 
  
       </property> 
  
       <property name="objectDefinitionSource"> 
  
           <value><![CDATA[ 
  
              CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON 
  
              PATTERN_TYPE_APACHE_ANT 
  
              /secure/extreme/**=ROLE_SUPERVISOR 
  
              /secure/**=IS_AUTHENTICATED_REMEMBERED 
  
              /**=IS_AUTHENTICATED_ANONYMOUSLY 
  
           ]]></value> 
  
       </property> 
  
    </bean>

后面章节我将对其中的代码进行解析。

举报

相关推荐

0 条评论