今天看到appfuse2.0.2里acegi的配置文件非常奇怪,到appfuse官网查看原来将appfuse2.0.2包含的acegi1.0升级到了acegi2.0 ,同1.0比起变化很大,名称也改为spring security2.0.下面是简单配置使用步骤
1、第一件事是把下面的filter声明添加到 web.xml 文件中:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.配置信息都放到application-security.xml里(名称可改),要加上命名空间
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">
...
</beans:beans>
3、其次为路径,地址增加权限。
<intercept-url pattern="/**" access="ROLE_USER" />
这表示,我们要保护应用程序中的所有URL,只有拥有 ROLE_USER角色的用户才能访问。
例如:
<http auto-config="true" lowercase-comparisons="false">
<!--intercept-url pattern="/images/*" filters="none"/>
<intercept-url pattern="/styles/*" filters="none"/>
<intercept-url pattern="/scripts/*" filters="none"/-->
<intercept-url pattern="/admin/*" access="ROLE_ADMIN"/>
<intercept-url pattern="/passwordHint.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
<intercept-url pattern="/signup.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
<intercept-url pattern="/a4j.res/*.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
<!-- APF-737, OK to remove line below if you're not using JSF -->
<intercept-url pattern="/**/*.html*" access="ROLE_ADMIN,ROLE_USER"/>
<form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?error=true" login-processing-url="/j_security_check"/>
<remember-me user-service-ref="userDao" key="e37f4b31-0c45-11dd-bd0b-0800200c9a66"/>
</http>
4、 指定数据库 和 密码加密
<authentication-provider user-service-ref="userDao">
<password-encoder ref="passwordEncoder"/>
</authentication-provider>
5、方法授权
<global-method-security>
<protect-pointcut expression="execution(* *..service.UserManager.getUsers(..))" access="ROLE_ADMIN"/>
<protect-pointcut expression="execution(* *..service.UserManager.removeUser(..))" access="ROLE_ADMIN"/>
</global-method-security>
6、Session控制
Acegi2.0 的session 控制真是简单,只能用简单得一米来形容J
首先在web.xml 中加个Listener:
<listener>
<listener-class>
org.springframework.security.ui.session.HttpSessionEventPublisher
</listener-class>
</listener>
然后在application-security.xml 中配置规则:
<http>
<concurrent-session-control max-sessions="1" />
</http>
或
<http>
<concurrent-session-control max-sessions="1" exception-if-maximum-exceeded="true" />
</http>
解释说明:两个配置都只允许用户登录一次,exception-if-maximum-exceeded 默认为false,此值表示:
用户第二次登录时,前一次的登录信息都被清空。当exception-if-maximum-exceeded="true"时系统会拒
绝第二次登录。
分享到:
相关推荐
有兴趣的欢迎来群:41229007 共同学习
此为spring security 2.0的最新中文指南 希望大家多看看,为你的spring筑上一个安全的长城
Formerly the Acegi Security System for Spring, Spring Security provides powerful and flexible security solutions for enterprise applications developed using the Spring Framework. It is a stable and ...
Acegi学习笔记--Acegi详解Acegi学习笔记--Acegi详解Acegi学习笔记--Acegi详解Acegi学习笔记--Acegi详解Acegi学习笔记--Acegi详解
通过此PPT可进行Acegi的配置,最新Spring security2.0的安全构建JAVA系统
Struts2.0+spring2.0+hibernate3.1 ACEGI应用示例
Acegi学习笔记(JAVA系统安全编程时用到),我就用到了Acegi,真的太牛了。
ACEGI ACEGI学习指南 ACEGI例子,标准的组合,例子可以正常运行
acegi-security 1.0.2.jar
acegi,acegi,acegi
1、一个Acegi的例子,可以运行 2、一个很好的学Acegi的网址,0基础学习Acegi,强烈推荐 3、有什么问题可以发邮件heroshen@126.com讨论
acegi学习整理合集 很全 工作中搜集整理的
anegi pdf 学习 ReferenceDocumentation
前段时间复习了spring怎么做权限的技术,spring acegi 学习心得.记下来勉励自己.
里边包括了 Acegi安全系统介绍.doc、Acegi使用.pdf、acegi学习笔记.doc、实战acegi.pdf、以及自己整理的 acegi的认证过滤器.rar
acegi学习笔记
acegi配置,让你更好的合理的了解acegi是什么
Spring+acegi+ext2.0+mysql 开发 acegi做权限控制 ext2.0做前台显示 spring 做控制层 mysql 做数据库
Acegi文档 spring acegi 详细文档