这两天尝试整合一下Acegi、Spring和Struts。配置文件如下:
web.xml文件内容详细:
Acegi Sample Application
contextConfigLocation
/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-acegi.xml
log4jConfigLocation
/WEB-INF/classes/log4j.properties
Acegi Filter Chain Proxy
net.sf.acegisecurity.util.FilterToBeanProxy
targetClass
net.sf.acegisecurity.util.FilterChainProxy
Acegi Filter Chain Proxy
/*
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.Log4jConfigListener
action
org.apache.struts.action.ActionServlet
config
/WEB-INF/struts-config.xml
debug
3
detail
3
0
action
*.do
spring的配置文件我分为两个:
一个是applicationContext.xml,配置了spring整合Hibernate的部分,包括Datasource和DAO部分,内容如下:
http://www.springframework.org/dtd/spring-beans.dtd">
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
com.mysql.jdbc.Driver
jdbc:mysql://localhost/lcdis
root
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
com/laf/bo/Example.hbm.xml
org.hibernate.dialect.MySQLDialect
true
true
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
PROPAGATION_REQUIRED,readOnly,-BusinessException
PROPAGATION_REQUIRED,-BusinessException
PROPAGATION_REQUIRED,-BusinessException
PROPAGATION_REQUIRED,-BusinessException
class="com.laf.bd.BusinessServiceImpl">
另外一个.xml,配置了Acegi相关内容:
http://www.springframework.org/dtd/spring-beans.dtd">
class="net.sf.acegisecurity.util.FilterChainProxy">
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/**=httpSessionContextIntegrationFilter,authenticationProcessingFilter, securityEnforcementFilter
class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
/login.jsp
/
/j_acegi_security_check.do
class="net.sf.acegisecurity.providers.ProviderManager">
class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider">
class="net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl">
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
class="org.springframework.cache.ehcache.EhCacheFactoryBean">
userCache
class="net.sf.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
class="net.sf.acegisecurity.providers.encoding.Md5PasswordEncoder">
class="net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter">
foobar
anonymousUser,ROLE_ANONYMOUS
class="net.sf.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
foobar
class="net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter">
net.sf.acegisecurity.context.security.SecureContextImpl
class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter">
class="net.sf.acegisecurity.vote.AffirmativeBased">
false
class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor">
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/index.jsp=ROLE_SUPERVISOR
/hello.jsp=ROLE_TELLER
/*.do=ROLE_TELLER
class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
/login.jsp
false
注意两处颜色不同的部分配置,是Acegi需要配合struts的内容。
Spring的配置我这里就不详细描述,这里主要谈谈对Acegi的看法。
我用的是Acegi0.8.3,目前是最新版。可以到项目主页下载:http://acegisecurity.sourceforge.net/
各位也看到了,Acegi的配置还是比较复杂,要了解几个主要的类,如下图:
如果嫌麻烦,就直接拷贝过去使用就可以了。只要修改objectDefinitionSource部分的权限配置就行。
再附上登录页面login.jsp的片断:
粗浅研究,首次涂鸦,希望有些可以供人参考之处,上面内容有很多写的不够详尽,各位看官可以留言,或发邮件共同探讨。
posted on 2005-10-27 00:06
风萧萧 阅读(1850)
评论(5) 编辑 收藏 所属分类:
原创