---
title: "OpenJweb平台中acegi的配置"
author: "cjc"
date: "2008-04-07T09:06:00Z"
tags: []
slug: "openjweb-acegi"
draft: false
lastmod: "2008-04-07T09:06:00Z"
id: 446893
url: "https://cjc.iteye.com/blog/446893"
---

说明:

URL的授权写到了数据库里了,所以更改URL授权的时候不需要更改配置文件

&lt;?xml version="1.0" encoding="GB2312"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)  
[http://www.springframework.org/schema/beans/spring-beans-2.0.xsd](http://www.springframework.org/schema/beans/spring-beans-2.0.xsd)"&gt;

&lt;bean id="concurrentSessionFilter"  
class="org.acegisecurity.concurrent.ConcurrentSessionFilter"&gt;  
&lt;property name="sessionRegistry" ref="sessionRegistry"&gt;&lt;/property&gt;  
&lt;property name="expiredUrl"&gt;  
&lt;value&gt;/timeout.jsp&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
&lt;bean id="sessionRegistry"  
class="org.acegisecurity.concurrent.SessionRegistryImpl" /&gt;  
&lt;bean id="concurrentSessionController"  
class="org.acegisecurity.concurrent.ConcurrentSessionControllerImpl"&gt;  
&lt;property name="maximumSessions" value="10"&gt;&lt;/property&gt;  
&lt;property name="sessionRegistry" ref="sessionRegistry"&gt;&lt;/property&gt;  
&lt;property name="exceptionIfMaximumExceeded" value="true"&gt;&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="logoutFilter"  
class="org.acegisecurity.ui.logout.LogoutFilter"&gt;  
&lt;constructor-arg value="/login.jsp" /&gt;  
&lt;constructor-arg&gt;  
&lt;list&gt;  
&lt;bean  
class="org.acegisecurity.ui.logout.SecurityContextLogoutHandler" /&gt;  
&lt;/list&gt;  
&lt;/constructor-arg&gt;  
&lt;/bean&gt;

&lt;bean id="dataSource"  
class="org.springframework.jndi.JndiObjectFactoryBean"&gt;  
&lt;property name="jndiName"&gt;  
&lt;!--tomcat--&gt;  
&lt;value&gt;java:comp/env/jdbc/mysql&lt;/value&gt;  
&lt;!--websphere--&gt;  
&lt;!--&lt;value&gt;jdbc/mysql&lt;/value&gt;--&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="filterChainProxy"  
class="org.acegisecurity.util.FilterChainProxy"&gt;  
&lt;property name="filterInvocationDefinitionSource"&gt;  
&lt;value&gt;  
CONVERT\_URL\_TO\_LOWERCASE\_BEFORE\_COMPARISON  
PATTERN\_TYPE\_APACHE\_ANT  
/\*\*=httpSessionContextIntegrationFilter,logoutFilter,concurrentSessionFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor  
&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
&lt;!--  
/\*\*=httpSessionContextIntegrationFilter,logoutFilter,concurrentSessionFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor  
\--&gt;  
&lt;bean id="httpSessionContextIntegrationFilter"  
class="org.acegisecurity.context.HttpSessionContextIntegrationFilter" /&gt;

&lt;bean id="authenticationProcessingFilter"  
class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"&gt;  
&lt;property name="authenticationManager"  
ref="authenticationManager" /&gt;  
&lt;property name="authenticationFailureUrl"  
value="/login.jsp" /&gt;  
&lt;property name="defaultTargetUrl" value="/index.jsp" /&gt;  
&lt;property name="filterProcessesUrl"  
value="/j\_acegi\_security\_check" /&gt;  
&lt;/bean&gt;  
&lt;bean id="securityContextHolderAwareRequestFilter"  
class="org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter" /&gt;  
&lt;bean id="exceptionTranslationFilter"  
class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;  
&lt;property name="authenticationEntryPoint"&gt;  
&lt;bean  
class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"&gt;  
&lt;!-- &lt;property name="loginFormUrl" value="/index.jsp"/&gt;--&gt;  
&lt;property name="loginFormUrl" value="/timeout.jsp" /&gt;  
&lt;property name="forceHttps" value="false" /&gt;  
&lt;/bean&gt;  
&lt;/property&gt;  
&lt;property name="accessDeniedHandler"&gt;  
&lt;bean  
class="org.acegisecurity.ui.AccessDeniedHandlerImpl"&gt;  
&lt;property name="errorPage" value="/accessdenied.jsp" /&gt;  
&lt;/bean&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
&lt;bean id="filterInvocationInterceptor"  
class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;  
&lt;property name="authenticationManager"  
ref="authenticationManager" /&gt;  
&lt;!--&lt;property name="alwaysReauthenticate" value="true"/&gt;--&gt;  
&lt;property name="accessDecisionManager"&gt;  
&lt;bean class="org.acegisecurity.vote.AffirmativeBased"&gt;  
&lt;property name="allowIfAllAbstainDecisions"  
value="false" /&gt;  
&lt;property name="decisionVoters"&gt;  
&lt;list&gt;  
&lt;ref bean="roleVoter" /&gt;  
&lt;bean  
class="org.acegisecurity.vote.AuthenticatedVoter" /&gt;  
&lt;/list&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
&lt;/property&gt;  
&lt;property name="objectDefinitionSource" ref="rdbmsFilterInvocationDefinitionSource" /&gt;  
&lt;/bean&gt;

&lt;bean id="rdbmsFilterInvocationDefinitionSource"  
class="org.apache.easframework.security.RdbmsFilterInvocationDefinitionSource"&gt;  
&lt;property name="dataSource" ref="dataSource" /&gt;  
&lt;property name="webresdbCache" ref="userCacheBackend" /&gt;  
&lt;!--&lt;property name="webresdbCache" ref="webresCacheBackend" /&gt;--&gt;  
&lt;/bean&gt;  
&lt;!--  
&lt;bean id="webresCacheBackend"  
class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;  
&lt;property name="cacheManager"&gt;  
&lt;ref local="cacheManager"/&gt;  
&lt;/property&gt;  
&lt;property name="cacheName"&gt;  
&lt;value&gt;webresdbCache&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
\--&gt;

&lt;bean id="authenticationManager"  
class="org.acegisecurity.providers.ProviderManager"&gt;  
&lt;property name="providers"&gt;  
&lt;list&gt;  
&lt;!-- &lt;ref local="mybean"/&gt; --&gt;  
&lt;ref local="daoAuthenticationProvider" /&gt;  
&lt;ref local="anonymousAuthenticationProvider" /&gt;  
&lt;/list&gt;  
&lt;/property&gt;  
&lt;property name="sessionController"  
ref="concurrentSessionController" /&gt;  
&lt;/bean&gt;

&lt;bean id="anonymousProcessingFilter"  
class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter"&gt;  
&lt;property name="key"&gt;  
&lt;value&gt;foobar&lt;/value&gt;  
&lt;/property&gt;  
&lt;property name="userAttribute"&gt;  
&lt;value&gt;anonymousUser,AUTH\_ANONYMOUS&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="daoAuthenticationProvider"  
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;  
&lt;property name="userDetailsService" ref="jdbcDaoImpl" /&gt;  
&lt;!-- 注释掉下面的chache是因为导致权限更改不能立即生效 --&gt;  
&lt;!--&lt;property name="userCache"&gt;&lt;ref local="userCache"/&gt;&lt;/property&gt;--&gt;  
&lt;!--if you do not want encode password --&gt;  
&lt;property name="passwordEncoder" ref="passwordEncoder" /&gt;  
&lt;/bean&gt;  
&lt;bean id="passwordEncoder"  
class="org.acegisecurity.providers.encoding.Md5PasswordEncoder" /&gt;

&lt;bean id="loggerListener"  
class="org.acegisecurity.event.authentication.LoggerListener" /&gt;

&lt;bean id="jdbcDaoImpl"  
class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"&gt;  
&lt;property name="dataSource"&gt;  
&lt;ref bean="dataSource" /&gt;  
&lt;/property&gt;  
&lt;property name="usersByUsernameQuery"&gt;  
&lt;value&gt;  
SELECT user\_id, user\_password,1 FROM eas\_login\_user  
WHERE user\_id=?  
&lt;/value&gt;  
&lt;!--&lt;value&gt;SELECT user\_sAccount, User\_sPassword,User\_nIsEnabled FROM Sys\_user WHERE User\_sAccount=?&lt;/value&gt;--&gt;  
&lt;/property&gt;  
&lt;property name="authoritiesByUsernameQuery"&gt;  
&lt;value&gt; select distinct a.user\_id,b.auth\_code from eas\_login\_user a ,eas\_auth b,eas\_roleauth\_rel c ,eas\_roleorg\_rel d  
where a.user\_id=? and b.obj\_id=c.auth\_id and c.role\_id = d.role\_id and a.is\_enabled=1 and d.org\_id=a.obj\_id and d.org\_id in  
( select org\_id from eas\_org\_node where tree\_code in  
(select eas\_org\_node.tree\_code from eas\_org\_node,eas\_login\_user where eas\_login\_user.user\_id=a.user\_id and eas\_login\_user.obj\_id=eas\_org\_node.obj\_id))  
&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="anonymousAuthenticationProvider"  
class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider"&gt;  
&lt;property name="key"&gt;  
&lt;value&gt;foobar&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="userCacheBackend"  
class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;  
&lt;property name="cacheManager"&gt;  
&lt;ref local="cacheManager" /&gt;  
&lt;/property&gt;  
&lt;property name="cacheName"&gt;  
&lt;value&gt;userCache&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="userCache"  
class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache"&gt;  
&lt;property name="cache"&gt;  
&lt;ref local="userCacheBackend" /&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="cacheManager"  
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;  
&lt;property name="configLocation"&gt;  
&lt;value&gt;classpath:ehcache.xml&lt;/value&gt;  
&lt;!--&lt;value&gt;classpath:com/iss/config/ehcache.xml&lt;/value&gt; --&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="methodCache"  
class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;  
&lt;property name="cacheManager"&gt;  
&lt;ref local="cacheManager" /&gt;  
&lt;/property&gt;  
&lt;property name="cacheName"&gt;  
&lt;value&gt;szairCache&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="transactionManager"  
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;  
&lt;property name="dataSource"&gt;  
&lt;ref local="dataSource" /&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="jdbcTemplate"  
class="org.springframework.jdbc.core.JdbcTemplate"&gt;  
&lt;property name="dataSource"&gt;  
&lt;ref bean="dataSource" /&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="businessAccessDecisionManager"  
class="org.acegisecurity.vote.AffirmativeBased"&gt;  
&lt;property name="allowIfAllAbstainDecisions"&gt;  
&lt;value&gt;false&lt;/value&gt;  
&lt;/property&gt;  
&lt;property name="decisionVoters"&gt;  
&lt;list&gt;  
&lt;ref bean="roleVoter" /&gt;  
&lt;/list&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="customEditorConfigurer"  
class="org.springframework.beans.factory.config.CustomEditorConfigurer"&gt;  
&lt;property name="customEditors"&gt;  
&lt;map&gt;  
&lt;entry  
key="org.acegisecurity.intercept.method.MethodDefinitionSource"&gt;  
&lt;bean  
class="org.apache.easframework.core.acegi.DataSourceMethodDefinitionSourceEditor"&gt;  
&lt;property name="jdbcTemplate"&gt;  
&lt;ref bean="jdbcTemplate" /&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
&lt;/entry&gt;  
&lt;/map&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="contactManagerSecurity"  
class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;  
&lt;property name="authenticationManager"&gt;  
&lt;ref bean="authenticationManager" /&gt;  
&lt;/property&gt;  
&lt;property name="accessDecisionManager"&gt;  
&lt;ref bean="businessAccessDecisionManager" /&gt;  
&lt;/property&gt;  
&lt;property name="objectDefinitionSource"&gt;  
&lt;value&gt;  
select auth.auth\_code,auth.auth\_resource from eas\_auth  
auth where auth.auth\_type='METHOD' and auth.auth\_code  
like 'AUTH\_METHOD\_%'  
&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter"&gt;  
&lt;property name="rolePrefix"&gt;  
&lt;value&gt;AUTH\_&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
&lt;!--  
&lt;bean id="DWRSecure" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;  
&lt;property name="target" ref=  
&lt;/bean&gt;--&gt;

&lt;/beans&gt;