和数据库的配置:srping-acegi-db.zip
http://www.java8.net/spring/2009-01/123235950511201_8.html
http://www.iteye.com/topic/43341 (可以控制方法的权限)
1.Error creating bean with name 'filterChainProxy' defined in URL [file:/F:/apache-tomcat-6.0.20/webapps/spring-acegi/WEB-INF/classes/applicationContext-security.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.security.intercept.web.FilterInvocationDefinitionSource] for property 'filterInvocationDefinitionSource';
<bean id="filterChainProxy"
class="org.springframework.security.util.FilterChainProxy">
<!--
<security:filter-chain-map path-type="ant">
<security:filter-chain pattern="/**" filters="httpSessionContextIntegrationFilter,logoutFilter, authenticationProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor"/>
</security:filter-chain-map>
-->
<property name="filterInvocationDefinitionSource">
<value><![CDATA[
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/**=httpSessionContextIntegrationFilter,logoutFilter, authenticationProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor]]
//这红色的内容在一行上
>
</value>
</property>
</bean>
5.Error creating bean with name 'testAcegi' defined in ServletContext resource [/WEB-INF/classes/applicationContext-security.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
6.方法拦截:
<bean id="methodSecurityInterceptor" class="org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager2"/>
</property>
<property name="accessDecisionManager">
<ref bean="accessDecisionManager"/>
</property>
<property name="objectDefinitionSource"> <!-- 对代理的类的方法开始配置权限
<value>com.test.comm.admin.service.impl.SysUsersService.insert=ROLE_BACAL</value>
-->
<value>com.method.TestAcegi.Role=ROLE_USER</value>
</property>
</bean>
<bean id="testAcegi" class="com.method.TestAcegi"/>
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>testAcegi</value><!-- 要代理的Bean的id -->
</list>
</property>
<property name="interceptorNames">
<list>
<value>methodSecurityInterceptor</value><!-- 代理为... -->
</list>
</property>
</bean>
需要加asm-2.2.3.jar 还有 cglib-nodep-2.1.3.jar(使用BeanNameAutoProxyCreator必须加这两个包)