Announcement Announcement Module
Collapse
No announcement yet.
How to use ContextPropagatingRemoteInvocationFactory? Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use ContextPropagatingRemoteInvocationFactory?

    Hi,
    I would like to use acegi to pass security context between my RMI clients and server. The documentation says that ContextPropagatingRemoteInvocationFactory class can be used to pass context from client to server. Is there any working example available on this?
    Secondly, how can I pass context from server to client?
    Thanks,
    Kapil

  • #2
    My requirement is that user has to first call logon api which returns a sessionId and for further calls client has to send sessionId with each request.
    To achieve this, i implemented the SecurityContext interface and set an object of this custom class in the the SecurityContextHolder.

    I made following entries in my xml
    Code:
    <bean id="remoteInvocationFactory" class="org.acegisecurity.context.rmi.ContextPropagatingRemoteInvocationFactory"/>
    <bean id="scriptService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    	     <property name="serviceUrl" value="rmi://localhost:61402/scriptService"/>
    		<property name="serviceInterface" value="com.A.B.service.remote.ScriptService"/>
    		<property name="refreshStubOnConnectFailure"><value>true</value></property>
    		<property name="remoteInvocationFactory"><ref bean="remoteInvocationFactory"/></property>
    	</bean>
    But When I try to get SecurityContext at server side from SecurityContextHolder class, it returns a null value.
    Please help...
    Thanks,
    Kapil

    Comment


    • #3
      Finally I figured out the problem. Its because my service is not a pojo, it implements Remote interface and am using RmiServiceExporter to export it as RMI service since my clients could be non spring aware.
      It works fine if my service is a pojo because then the stubs created by spring implements RmiInvocationHandler and this code in RmiClientInterceptor class checks for type of stub
      Code:
      protected Object doInvoke(MethodInvocation invocation, Remote stub) throws Throwable {
      		if (stub instanceof RmiInvocationHandler) {
      			// RMI invoker
      			try {
      				return doInvoke(invocation, (RmiInvocationHandler) stub);
      			}
      			catch (RemoteException ex) {
      				throw RmiClientInterceptorUtils.convertRmiAccessException(
      				    invocation.getMethod(), ex, isConnectFailure(ex), getServiceUrl());
      			}
      			catch (InvocationTargetException ex) {
      				throw ex.getTargetException();
      			}
      			catch (Throwable ex) {
      				throw new AspectException("Failed to invoke remote service [" + getServiceUrl() + "]", ex);
      			}
      		}
      		else {
      			// traditional RMI stub
      			try {
      				return RmiClientInterceptorUtils.doInvoke(invocation, stub);
      			}
      			catch (InvocationTargetException ex) {
      				Throwable targetEx = ex.getTargetException();
      				if (targetEx instanceof RemoteException) {
      					RemoteException rex = (RemoteException) targetEx;
      					throw RmiClientInterceptorUtils.convertRmiAccessException(
      							invocation.getMethod(), rex, isConnectFailure(rex), getServiceUrl());
      				}
      				else {
      					throw targetEx;
      				}
      			}
      		}
      	}
      In my case it always goes in else block as my service implements Remote interface.
      Shall I file a bug in JIRA?

      Regards,
      Kapil

      Comment


      • #4
        Was a bug filed?

        Comment


        • #5
          Anyone have suggestions for workarounds?

          Comment


          • #6
            BTW, for my case I was using an RmiProxyFactoryBean on the client side, so the fix was as easy as removing the "implements Remote" from the remote interface.

            I suppose it makes sense that you can't export a service as a plain RMI stub AND an RmiInvocationHandler.

            Comment

            Working...
            X