Hi, Ben
If I wanna call my protected business method in jsp code, do I have to use AspectJ (JoinPoint) Security Interceptor?
I've used AOP Alliance (MethodInvocation) Security Interceptor, it doesn't intercept my call, so I try an AspectJ interceptor according to your instruction in the reference document.
1.configure AspectJSecurityInterceptor in the Spring application context:
2.define an AspectJ aspect:Code:<bean id="positionManagerSecurity" class="net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor"> <property name="validateConfigAttributes"><value>true</value></property> <property name="authenticationManager"><ref bean="authenticationManager"/></property> <property name="accessDecisionManager"><ref local="positionAccessDecisionManager"/></property> <property name="afterInvocationManager"><ref local="afterInvocationManager"/></property> <property name="objectDefinitionSource"> <value> com.xxx.jaidwapfactory.security.SecurityPositionManager.addPosition=ROLE_USER com.xxx.jaidwapfactory.security.SecurityPositionManager.removePosition=ACL_CONTACT_ADMIN com.xxx.jaidwapfactory.security.SecurityPositionManager.getPositions=AFTER_ACL_COLLECTION_READ com.xxx.jaidwapfactory.security.SecurityPositionManager.getPosition=AFTER_ACL_READ </value> </property> </bean>
I just change the pointcut expression from yours
3.configure Spring to load the aspect:Code:package com.xxx.jaidwapfactory.security; /** * @author cookman * */ import net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor; import net.sf.acegisecurity.intercept.method.aspectj.AspectJCallback; import org.springframework.beans.factory.InitializingBean; public aspect DomainObjectInstanceSecurityAspect implements InitializingBean { private AspectJSecurityInterceptor securityInterceptor; pointcut domainObjectInstanceExecution(): execution(public * com.xxx.jaidwapfactory.security.SecurityPositionManager+.*(..)) && !within(DomainObjectInstanceSecurityAspect); Object around(): domainObjectInstanceExecution() { if (this.securityInterceptor != null) { AspectJCallback callback = new AspectJCallback() { public Object proceedWithObject() { return proceed(); } }; return this.securityInterceptor.invoke(thisJoinPoint, callback); } else { return proceed(); } } public AspectJSecurityInterceptor getSecurityInterceptor() { return securityInterceptor; } public void setSecurityInterceptor( AspectJSecurityInterceptor securityInterceptor) { this.securityInterceptor = securityInterceptor; } public void afterPropertiesSet() throws Exception { if (this.securityInterceptor == null) throw new IllegalArgumentException("securityInterceptor required"); } }
4.compile source code with aspectj iajc ant task and deploy allCode:<bean id="domainObjectInstanceSecurityAspect" class="com.xxx.jaidwapfactory.security.DomainObjectInstanceSecurityAspect" factory-method="aspectOf"> <property name="securityInterceptor"><ref bean="positionManagerSecurity"/></property> </bean>
but I get the following error msg:
Code:11:18:34,248 ERROR ContextLoader,Thread-1:114 - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'positionManager' defined in ServletContext resource [/WEB-INF/applicationContext-common-business.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unknown advisor type class net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry,which may also be target or TargetSource; nested exception is org.springframework.aop.framework.adapter.UnknownAdviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor] org.springframework.aop.framework.AopConfigException: Unknown advisor type class net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry,which may also be target or TargetSource; nested exception is org.springframework.aop.framework.adapter.UnknownAdviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor] org.springframework.aop.framework.adapter.UnknownAdviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor] at org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry.wrap(DefaultAdvisorAdapterRegistry.java:49) at org.springframework.aop.framework.ProxyFactoryBean.namedBeanToAdvisor(ProxyFactoryBean.java:454) at org.springframework.aop.framework.ProxyFactoryBean.addAdvisorOnChainCreation(ProxyFactoryBean.java:417) at org.springframework.aop.framework.ProxyFactoryBean.createAdvisorChain(ProxyFactoryBean.java:321) at org.springframework.aop.framework.ProxyFactoryBean.setBeanFactory(ProxyFactoryBean.java:193) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:271) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:193) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:240) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:230) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:304) at org.springframework.web.context.support.XmlWebApplicationContext.refresh(XmlWebApplicationContext.java:131) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:167) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:101) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:48) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3631) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4065) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:755) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:886) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:849) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1079) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1011) at org.apache.catalina.core.StandardHost.start(StandardHost.java:718) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1003) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:437) at org.apache.catalina.core.StandardService.start(StandardService.java:450) at org.apache.catalina.core.StandardServer.start(StandardServer.java:2010) at org.apache.catalina.startup.Catalina.start(Catalina.java:537) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)



. 