最近两星期在学习acegi,过程中感谢JavaEye,SpringSide和在网上提供acegi学习心得的网友们。
为了加深自己的认识,准备写下一些DEMO,希望可以给准备学习acegi的同学一些帮助。
作为安全服务离不开认证和授权这两个主要组成部分。而这篇文章就是针对acegi的认证服务。
学习Acegi-认证(authentication)
代码环境基于:
JDK1.5
acegi1.0.3
spring2.0
IDE基于:
Eclipse3.2+MyEclipse5.0.1
面向人员:
熟悉Eclipse+MyEclipse开发但刚开始了解acegi的人员。如果你是高手请指出文章不足之处。
1.建立一个MyEclipse的WebProject,把下列jar文件拷贝到项目的WEB-INF/lib目录:
acegi-security-1.0.3.jar
spring2.0.jar
commons-codec-1.3.jar
费话说一句(占些字数):这是因为代码运行需要这些包的支持。
2.修改WEB-INF下的web.xml文件,内容如下:
< web – app version = " 2.4 "xmlns = " http://java.sun.com/xml/ns/j2ee "
xmlns:xsi = ” http://www.w3.org/2001/XMLSchema-instance ”
xsi:schemaLocation = ” http://java.sun.com/xml/ns/j2ee
http: // java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>
acegi Example of liuyxit
<!–
定义应用的上下文参数,用于ContextLoaderListener
–>
contextConfigLocation
classpath:spring / applicationContext.xml
Acegi Filter Chain Proxy
org.acegisecurity.util.FilterToBeanProxy
targetClass
org.acegisecurity.util.FilterChainProxy
Acegi Filter Chain Proxy
/*
<!–
装载应用软件的Spring上下文
要由WebapplicationContextUtils.getWebApplicationnContext(servletContext)得到.
–>
org.springframework.web.context.ContextLoaderListener
其中FilterChainProxy实现了filter接口,它主要是实例化FilterChainProxy,并把所有动作交由FilterChainProxy处理。这样简化了web.xml的配置,并且充分利用了Spring IOC管理Bean的优势。
3.在src目录右键新建一个resource folder,在下面再建立acegi和spring目录
在spring目录中创建applicationContext.xml文件,内容:
< beans xmlns = " http://www.springframework.org/schema/beans "
xmlns:xsi = ” http://www.w3.org/2001/XMLSchema-instance ”
xmlns:aop = ” http://www.springframework.org/schema/aop ”
xmlns:tx = ” http://www.springframework.org/schema/tx ”
xsi:schemaLocation = ” http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http: // www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http: // www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.0.xsd ”
default – autowire = ” byName “default – lazy – init = ” true ” >
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/** =authenticationProcessingFilter,exceptionTranslationFilter
liuyxit=123,ROLE_SUPERVISOR
user1=user1,ROLE_USER
user2=user2,disabled,ROLE_USER
更多免费相关学习经验请访问:Tore_m_1206686_21115_1_1.html”>http://www.shangxueba.com/sTore_m_1206686_21115_1_1.html
到底通向了什么样的远方呢?