aaron8tang
Dec 1st, 2004, 11:32 PM
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:
<bean id="positionManagerSecurity" class="net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor">
<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.SecurityPositionMa nager.addPosition=ROLE_USER
com.xxx.jaidwapfactory.security.SecurityPositionMa nager.removePosition=ACL_CONTACT_ADMIN
com.xxx.jaidwapfactory.security.SecurityPositionMa nager.getPositions=AFTER_ACL_COLLECTION_READ
com.xxx.jaidwapfactory.security.SecurityPositionMa nager.getPosition=AFTER_ACL_READ
</value>
</property>
</bean>
2.define an AspectJ aspect:
I just change the pointcut expression from yours:)
package com.xxx.jaidwapfactory.security;
/**
* @author cookman
*
*/
import net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor;
import net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJCallback;
import org.springframework.beans.factory.InitializingBean ;
public aspect DomainObjectInstanceSecurityAspect implements InitializingBean {
private AspectJSecurityInterceptor securityInterceptor;
pointcut domainObjectInstanceExecution():
execution(public * com.xxx.jaidwapfactory.security.SecurityPositionMa nager+.*(..)) && !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");
}
}
3.configure Spring to load the aspect:
<bean id="domainObjectInstanceSecurityAspect"
class="com.xxx.jaidwapfactory.security.DomainObjectInstan ceSecurityAspect"
factory-method="aspectOf">
<property name="securityInterceptor"><ref bean="positionManagerSecurity"/></property>
</bean>
4.compile source code with aspectj iajc ant task and deploy all
but I get the following error msg:
11:18:34,248 ERROR ContextLoader,Thread-1:114 - Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: 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.AopConfigExcepti on: Unknown advisor type class net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor; 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.UnknownA dviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.Asp ectJSecurityInterceptor]
org.springframework.aop.framework.AopConfigExcepti on: Unknown advisor type class net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor; 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.UnknownA dviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.Asp ectJSecurityInterceptor]
org.springframework.aop.framework.adapter.UnknownA dviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.Asp ectJSecurityInterceptor]
at org.springframework.aop.framework.adapter.DefaultA dvisorAdapterRegistry.wrap(DefaultAdvisorAdapterRe gistry.java:49)
at org.springframework.aop.framework.ProxyFactoryBean .namedBeanToAdvisor(ProxyFactoryBean.java:454)
at org.springframework.aop.framework.ProxyFactoryBean .addAdvisorOnChainCreation(ProxyFactoryBean.java:4 17)
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.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:271)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:230)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:304)
at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:167)
at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:101)
at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 48)
at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3631)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4065)
at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:755)
at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:886)
at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:849)
at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1079)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1011)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1003)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:437)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2010)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:409)
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:
<bean id="positionManagerSecurity" class="net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor">
<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.SecurityPositionMa nager.addPosition=ROLE_USER
com.xxx.jaidwapfactory.security.SecurityPositionMa nager.removePosition=ACL_CONTACT_ADMIN
com.xxx.jaidwapfactory.security.SecurityPositionMa nager.getPositions=AFTER_ACL_COLLECTION_READ
com.xxx.jaidwapfactory.security.SecurityPositionMa nager.getPosition=AFTER_ACL_READ
</value>
</property>
</bean>
2.define an AspectJ aspect:
I just change the pointcut expression from yours:)
package com.xxx.jaidwapfactory.security;
/**
* @author cookman
*
*/
import net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor;
import net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJCallback;
import org.springframework.beans.factory.InitializingBean ;
public aspect DomainObjectInstanceSecurityAspect implements InitializingBean {
private AspectJSecurityInterceptor securityInterceptor;
pointcut domainObjectInstanceExecution():
execution(public * com.xxx.jaidwapfactory.security.SecurityPositionMa nager+.*(..)) && !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");
}
}
3.configure Spring to load the aspect:
<bean id="domainObjectInstanceSecurityAspect"
class="com.xxx.jaidwapfactory.security.DomainObjectInstan ceSecurityAspect"
factory-method="aspectOf">
<property name="securityInterceptor"><ref bean="positionManagerSecurity"/></property>
</bean>
4.compile source code with aspectj iajc ant task and deploy all
but I get the following error msg:
11:18:34,248 ERROR ContextLoader,Thread-1:114 - Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: 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.AopConfigExcepti on: Unknown advisor type class net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor; 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.UnknownA dviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.Asp ectJSecurityInterceptor]
org.springframework.aop.framework.AopConfigExcepti on: Unknown advisor type class net.sf.acegisecurity.intercept.method.aspectj.Aspe ctJSecurityInterceptor; 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.UnknownA dviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.Asp ectJSecurityInterceptor]
org.springframework.aop.framework.adapter.UnknownA dviceTypeException: No adapter for Advice of class [net.sf.acegisecurity.intercept.method.aspectj.Asp ectJSecurityInterceptor]
at org.springframework.aop.framework.adapter.DefaultA dvisorAdapterRegistry.wrap(DefaultAdvisorAdapterRe gistry.java:49)
at org.springframework.aop.framework.ProxyFactoryBean .namedBeanToAdvisor(ProxyFactoryBean.java:454)
at org.springframework.aop.framework.ProxyFactoryBean .addAdvisorOnChainCreation(ProxyFactoryBean.java:4 17)
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.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:271)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:230)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:304)
at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:167)
at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:101)
at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 48)
at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3631)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4065)
at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:755)
at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:886)
at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:849)
at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1079)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1011)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1003)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:437)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2010)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:409)