Acegi应用到实际项目中(1)是基于BasicProcessingFilter的基本认证,这篇改用AuthenticationProcessingFilter基于表单的认证方式。

1authenticationProcessingFilter
  处理认证请求(通常是一个登录页面的表单请求)。当身份验证成功时,AuthenticationProcessingFilter会在会话中放置一个Authentication对象,并且重定向到登录成功页面

  • authenticationFailureUrl  定义登陆失败时转向的页面
  • defaultTargetUrl  定义登陆成功时转向的页面
  • filterProcessesUrl  定义登陆请求的页面,该过滤器拦截的url,通常/j_acegi_security_check,和登录页面(login.jsp)的登录表单的action相同
  • rememberMeServices  用于在验证成功后添加cookie信息
<bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationFailureUrl" value="/login.jsp?login_error=1"/><!-- 登录失败页面 -->
<property name="defaultTargetUrl" value="/authenticate/index.jsp"/><!-- 成功登录页面 -->
<property name="filterProcessesUrl" value="/j_acegi_security_check"/>
</bean>

  和BasicProcessingFilter基本认证一样,基于表单的认证也需要通过认证管理器authenticationManager来认证用户的登录信息。

2exceptionTranslationFilter

  上篇中配置为:

<bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
<property name="authenticationEntryPoint" ref="basicProcessingFilterEntryPoint" />
</bean>

  将其修改为:

<bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
<!-- 尚未登录, 进入非法(未认证不可访问)区域 -->
<property name="authenticationEntryPoint">
<bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl" value="/login.jsp"/>
<property name="forceHttps" value="false"/>
</bean>
</property>
<!-- 登录后, 进入非授权区域 -->
<property name="accessDeniedHandler">
<bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl">
<property name="errorPage" value="/accessDenied.jsp"/>
</bean>
</property>
</bean>

  说明:

  1)authenticationEntryPoint是对认证时发生异常的处理

  • loginFormUrl:如果用户尚未登录系统,进入未经授权的区域,那么会被重定向到该属性所指定的页面,此处为/login.jsp,即登录页面
  • forceHttps:是否启用https,此处设为否false

  2)accessDeniedHandler是对授权时发生异常的处理

  • errorPage:通过认证的用户,如果进入未经授权的区域,将会被转向该属性扬指定的页面,此处为/accessDenied.jsp

3、两个日志监听器

  1) org.acegisecurity.event.authentication.LoggerListener

  用于监听各种用户认证事件,并将事件内容输出到Commons Logging中。

  源码注释:Outputs authentication-related application events to Commons Logging.All authentication events are logged at the warning level

  2) org.acegisecurity.event.authorization.LoggerListener

用于监听各种用户授权事件,并将事件内容输出到Commons Logging中。

  源码注释:Outputs interceptor-related application events to Commons Logging.

  All failures are logged at the warning level, with success events logged at the information level,and public invocation events logged at the debug level.

4、其他修改

  用户信息为:

<bean id="inMemDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">
<property name="userMap">
<value>
javaee=password,ROLE_SUPERVISOR
sam=password,ROLE_USER
qiuzj=password,ROLE_SUPERVISOR,disabled
</value>
</property>
</bean>
  Web资源与角色对应关系:
<bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
……
<property name="objectDefinitionSource">
<value><![CDATA[
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/secure/**=ROLE_SUPERVISOR
/authenticate/**=ROLE_USER,ROLE_SUPERVISOR
]]></value>
</property>
</bean>
  用户javaee可以访问所有页面 
  用户sam不能访问/secure/下的资源 
  用户qiuzj为不可用状态 
 

学习Acegi应用到实际项目中(2)的更多相关文章

  1. 学习Acegi应用到实际项目中(10)- 保护业务方法

    前面已经讲过关于保护Web资源的方式,其中包括直接在XML文件中配置和自定义实现FilterInvocationDefinitionSource接口两种方式.在实际企业应用中,保护Web资源非常重要, ...

  2. 学习Acegi应用到实际项目中(7)- 缓存用户信息

    在默认情况下,即在用户未提供自身配置文件ehcache.xml或ehcache-failsafe.xml时,EhCache会依据其自身Jar存档包含的ehcache-failsafe.xml文件所定制 ...

  3. 学习Acegi应用到实际项目中(1)

    在此,本人声明,我处于菜鸟阶段,文章的内容大部分摘自zhanjia的博客(http://zhanjia.iteye.com/category/43399),旨在学习,有很多地方,我理解不够透彻,可能存 ...

  4. 学习Acegi应用到实际项目中(12)- Run-As认证服务

    有这样一些场合,系统用户必须以其他角色身份去操作某些资源.例如,用户A要访问资源B,而用户A拥有的角色为AUTH_USER,资源B访问的角色必须为AUTH_RUN_AS_DATE,那么此时就必须使用户 ...

  5. 学习Acegi应用到实际项目中(11)- 切换用户

    在某些应用场合中,可能需要用到切换用户的功能,从而以另一用户的身份进行相关操作.这一点类似于在Linux系统中,用su命令切换到另一用户进行相关操作. 既然实际应用中有这种场合,那么我们就有必要对其进 ...

  6. 学习Acegi应用到实际项目中(9)- 实现FilterInvocationDefinition

    在实际应用中,开发者有时需要将Web资源授权信息(角色与授权资源之间的定义)存放在RDBMS中,以便更好的管理.事实上,一般的企业应用都应当如此,因为这样可以使角色和Web资源的管理更灵活,更自由.那 ...

  7. 学习Acegi应用到实际项目中(8)- 扩展UserDetailsService接口

    一个能为DaoAuthenticationProvider提供存取认证库的的类,它必须要实现UserDetailsService接口: public UserDetails loadUserByUse ...

  8. 学习Acegi应用到实际项目中(5)

    实际企业应用中,用户密码一般都会进行加密处理,这样才能使企业应用更加安全.既然密码的加密如此之重要,那么Acegi(Spring Security)作为成熟的安全框架,当然也我们提供了相应的处理方式. ...

  9. 学习Acegi应用到实际项目中(4)

    此节介绍:ConcurrentSessionFilter. 在Acegi 1.x版本中,控制并发HttpSession和Remember-Me认证服务不能够同时启用,它们之间存在冲突问题. 在一些应用 ...

随机推荐

  1. PV、IV、UV

    PV  访问量 UV 独立访客 IV 独立ip数 qps 流量

  2. input输入完成后监听

    clearTimeout(serachtimer); serachtimer=setTimeout(function(){ xxxxxxx //这里写处理的方法 },1000)

  3. bresenham 算法生成直线

    struct Point{ Point() { posx = 0; posy = 0; } Point(int x, int y) { posx = x; posy = y; } int posx; ...

  4. centos6.5部署redmine3.2

    ruby 2.1 + rails 4.2+ mysql 5.6 +centos6.5 + rvm 1.29 1.基本的软件环境 yum -y install libyaml-devel zlib-de ...

  5. laravel表单操作

    $request->all()//获取所有参数if($request->isMethod('GET')){判断是否是GET请求}$res = $request->is('studen ...

  6. leetcode1029

    class Solution(object): def twoCitySchedCost(self, costs: 'List[List[int]]') -> int: costs = sort ...

  7. ligbox 插件介绍

    浏览器支持情况:一般情况都支持.最好是jQuery v1.x + lightbox.js,这样的组合IE6,IE7,IE8也支持! 1 light插件的下载地址:https://pan.baidu.c ...

  8. js中子窗口调用父窗口中的变量、函数

  9. docker镜像加速器

    目前国内比较靠谱的镜像加速器网址:https://www.daocloud.io/mirror

  10. c# devexpress 多文档界面

    学习记录 https://blog.csdn.net/qq_25473787/article/details/81208894?utm_source=blogxgwz0