Announcement Announcement Module
Collapse
No announcement yet.
Configuring work around for "delegating proxy effect" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring work around for "delegating proxy effect"

    I'm very new to AOP and I'm using it to secure method invocations using
    the Acegi Security System for Spring framework.

    For several reasons my business layer services extend a GenericService
    that provides a method executeOperation that takes two parameters: a
    method name and a Map that contains method arguments. This method then
    calls the actual method implementation (or calls an external system
    using JCA or web services if needed). I want to secure the 'native'
    Java methods called by executeOperation. One further complication is
    that the services are called through a HttpInvoker.

    Following advise I found in
    <a href="http://forum.springframework.org/showthread.php?t=25123">this</a>
    forum thread, my current configuration is basically as follows:

    In the GenericService:
    Code:
    private GenericService thisInstance = this;
    public void setThis(GenericService instance) {
       thisInstance = instance;
    }
    public GenericService getThis() {
       return thisInstance;
    }
    public Map executeOperation(String service, Map arguments) {
       // convert the Map to an Object[] params
       
       // create a Class[] paramClasses that details the classes of the
       // arguments
       
       Method method = getThis().getClass().getMethod(operation,
                                                      paramClasses);
       Object result = method.invoke(getThis(), params);
       
       // convert the result back into a Map
    }
    and in my services:
    Code:
    package a.b.c
    public class MyService extends GenericService implements MyServiceItf {
       public MyObject myOperation(/* parameters */) {
          // ...
       }
    }
    In my configuration:
    Code:
    <bean id="serviceTarget" class="a.b.c.MyService">
       <property name="this" ref="service" />
    </bean>
    
    <bean id="service" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
       <property name="transactionManager">
          <ref bean="transactionManager" />
       </property>
       <property name="target">
          <ref bean="serviceTarget" />
       </property>
       <property name="transactionAttributes">
          <!-- Transaction attributes go here -->
       </property>
       <property name="postInterceptors" ref="myInterceptor" />
    </bean>
    
    <bean id="httpService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
       <property name="service">
          <ref bean="service" />
       </property>
       <property name="serviceInterface">
          a.b.c.MyServiceItf
       </property>
    </bean>
    where the bean myInterceptor is an Acegi Security
    MethodSecurityInterceptor.

    The problem is that my application server (JBoss 4.0) complains about
    circular bean references (something I can very well understand by
    looking at my config):
    Code:
    2006-08-21 09:49:34,537 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpService' defined in URL [...]: Can't resolve reference to bean 'service' while setting property 'service'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in URL [...]: Can't resolve reference to bean 'target' while setting property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceTarget' defined in URL [...]: Can't resolve reference to bean 'service' while setting property 'this'; nested exception is org.springframework.beans.factory.FactoryBeanNotInitializedException: Error creating bean with name 'service': FactoryBean returned null object: probably not fully initialized (maybe due to circular bean reference)
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in URL [...]: Can't resolve reference to bean 'serviceTarget' while setting property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceTarget' defined in URL [...]: Can't resolve reference to bean 'service' while setting property 'this'; nested exception is org.springframework.beans.factory.FactoryBeanNotInitializedException: Error creating bean with name 'service': FactoryBean returned null object: probably not fully initialized (maybe due to circular bean reference)
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceTarget' defined in URL [...]: Can't resolve reference to bean 'service' while setting property 'this'; nested exception is org.springframework.beans.factory.FactoryBeanNotInitializedException: Error creating bean with name 'service': FactoryBean returned null object: probably not fully initialized (maybe due to circular bean reference)
    org.springframework.beans.factory.FactoryBeanNotInitializedException: Error creating bean with name 'errorMessageService': FactoryBean returned null object: probably not fully initialized (maybe due to circular bean reference)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForSharedInstance(AbstractBeanFactory.java:819)
    	...
    	at java.lang.Thread.run(Thread.java:534)
    Do you have any idea how I may proceed ?
Working...
X