菜鸟-手把手教你把Acegi应用到实际项目中(2)
上一篇是基于BasicProcessingFilter的基本认证,这篇我们改用AuthenticationProcessingFilter基于表单的认证方式。
1、authenticationProcessingFilter
处理认证请求(通常是一个登录页面的表单请求)。当身份验证成功时,AuthenticationProcessingFilter会在会话中放置一个Authentication对象,并且重定向到登录成功页面
l authenticationFailureUrl定义登陆失败时转向的页面
l defaultTargetUrl定义登陆成功时转向的页面
l filterProcessesUrl定义登陆请求的页面,该过滤器拦截的url,通常/j_acegi_security_check,和登录页面(login.jsp)的登录表单的action相
同
l 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来认证用户的登录信息。
2、exceptionTranslationFilter
上一篇中配置为:
<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是对认证时发生异常的处理
l loginFormUrl:如果用户尚未登录系统,进入未经授权的区域,那么会被重定向到该属性所指定的页面,此处为/login.jsp,即登录页面
l forceHttps:是否启用https,此处设为否false
2)accessDeniedHandler是对授权时发生异常的处理
l 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>
剩下的补在评论中
- 例子源码Acegi1.rar (7.3 KB)
- 下载次数: 626
菜鸟-手把手教你把Acegi应用到实际项目中(2)的更多相关文章
- 菜鸟-手把手教你把Acegi应用到实际项目中(8)-扩展UserDetailsService接口
一个能为DaoAuthenticationProvider提供存取认证库的的类,它必须要实现UserDetailsService接口: public UserDetails loadUserByUse ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(10)-保护业务方法
前面已经讲过关于保护Web资源的方式,其中包括直接在XML文件中配置和自定义实现FilterInvocationDefinitionSource接口两种方式.在实际企业应用中,保护Web资源显得非常重 ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(1.1)
相信不少朋友们对于学习Acegi的过程是比较痛苦的,而且可能最初一个例子都没能真正运行起来.即使能运行起来,对于里面那么多的配置,更搞不清楚为什么要那么配,多配一个和少配一个究竟有什么区别? 最终头都 ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(11)-切换用户
在某些应用场合中,我们可能需要用到切换用户的功能,从而以另一用户的身份进行相关操作.这一点类似于在Linux系统中,用su命令切换到另一用户进行相关操作. 既然实际应用中有这种场合,那么我们 ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(12)-Run-As认证服务
有这样一些场合,系统用户必须以其他角色身份去操作某些资源.例如,用户A要访问资源B,而用户A拥有的角色为AUTH_USER,资源B访问的角色必须为AUTH_RUN_AS_DATE,那么此时就必须使用户 ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(7)-缓存用户信息
首先讲讲EhCache.在默认情况下,即在用户未提供自身配置文件ehcache.xml或ehcache-failsafe.xml时,EhCache会依据其自身Jar存档包含的ehcache-fails ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(5)
在实际企业应用中,用户密码一般都会进行加密处理,这样才能使企业应用更加安全.既然密码的加密如此之重要,那么Acegi(Spring Security)作为成熟的安全框架,当然也我们提供了相应的处理方式 ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(4)
今天就讲个ConcurrentSessionFilter. 在Acegi 1.x版本中,控制并发HttpSession和Remember-Me认证服务不能够同时启用,它们之间存在冲突问题,这是该版本的 ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(6)
在企业应用中,用户的用户名.密码和角色等信息一般存放在RDBMS(关系数据库)中.前面几节我们采用的是InMemoryDaoImpl,即基于内存的存放方式.这节我们将采用RDBMS存储用户信息. Us ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(1.2)
7) daoAuthenticationProvider 进行简单的基于数据库的身份验证.DaoAuthenticationProvider获取数据库中的账号密码并进行匹配,若成功则在通过用户身份的同 ...
随机推荐
- Android Studio 单元测试
测试的种类 按岗位划分 黑盒测试:测试逻辑业务 白盒测试:测试逻辑方法 按测试粒度分 方法测试:function test 单元测试:unit test 集成测试:integration test 系 ...
- Httpservlet cannot be resolved to a type的原因与解决方法
刚开始学习Servlet,在Eclipse中新建了一个Servlet,不过页面上报错: Httpservlet cannot be resolved to a type,显然是Eclipse找不到相应 ...
- 用c#读取文件内容中文是乱码的解决方法:
用c#读取文件内容中文是乱码的解决方法: //方法1: StreamReader din = new StreamReader(@"C:\1.txt", System.Text.E ...
- MySQL时间戳和时间格式转换函数
MySQL时间戳和时间格式转换函数:unix_timestamp and from_unixtime unix_timestamp将时间转化成时间戳格式.from_unixtime将时间戳转化成时间格 ...
- docker的例子
定制镜像 做个测试服务器,testServer代码如下 package main import ( "net/http" ) func main() { http.Handle(& ...
- 请使用-Xlint:deprecation重新编译
[已解决]Android Studio编译OsmAnd出现警告:GeoPointParserUtil.java使用或覆盖了已过时的 API.有关详细信息请使用-Xlint:deprecation重新编 ...
- Platform Invoke
PInvoke 允许managed code 来调用在DLL中实施的unmanged function. Platform invoke relies on metadata to locate ex ...
- c# 存档修改 读取 写入
内涵图
- JAVA 边界布局管理器
//边界布局管理器 import java.awt.*; import javax.swing.*; public class Jiemian1 extends JFrame{ //定义组件 JBut ...
- ndk的一些概念
什么场景应用ndk 1.代码的包含,apk的java层代码容易被反编译,c/c++被反编译难度非常大 2.NDK中调用 第三方C/C++库,因为大部分的开源库都是c/c++编写,比如opencv,op ...