Browse Source

Move RMI context propagation support classes to core, and rename and document to more clearly reflect function.

1.0.x
Ben Alex 21 years ago
parent
commit
61580d1973
  1. 111
      core/src/main/java/org/acegisecurity/ui/rmi/ContextPropagatingRemoteInvocation.java
  2. 17
      core/src/main/java/org/acegisecurity/ui/rmi/ContextPropagatingRemoteInvocationFactory.java
  3. 8
      core/src/main/java/org/acegisecurity/ui/rmi/package.html
  4. 58
      sandbox/src/main/java/org/acegisecurity/remoting/AcegiRemoteInvocation.java

111
core/src/main/java/org/acegisecurity/ui/rmi/ContextPropagatingRemoteInvocation.java

@ -0,0 +1,111 @@ @@ -0,0 +1,111 @@
/* Copyright 2004 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.ui.rmi;
import net.sf.acegisecurity.context.Context;
import net.sf.acegisecurity.context.ContextHolder;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.remoting.support.RemoteInvocation;
import java.lang.reflect.InvocationTargetException;
/**
* The actual <code>RemoteInvocation</code> that is passed from the client to
* the server, which contains the contents of {@link ContextHolder}.
*
* <p>
* When constructed on the client via {@link
* net.sf.acegisecurity.ui.rmi.ContextPropagatingRemoteInvocationFactory}, the
* contents of the <code>ContextHolder</code> are stored inside the object.
* The object is then passed to the server that is processing the remote
* invocation. Upon the server invoking the remote invocation, it will
* retrieve the passed contents of the <code>ContextHolder</code> and set them
* to the server-side <code>ContextHolder</code> whilst the target object is
* invoked. When the target invocation has been completed, the server-side
* <code>ContextHolder</code> will be reset to <code>null</code>.
* </p>
*
* @author James Monaghan
* @author Ben Alex
* @version $Id$
*/
public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
//~ Static fields/initializers =============================================
private static final Log logger = LogFactory.getLog(ContextPropagatingRemoteInvocation.class);
//~ Instance fields ========================================================
private Context context;
//~ Constructors ===========================================================
/**
* Constructs the object, storing the value of the client-side
* <code>ContextHolder</code> inside the object.
*
* @param methodInvocation the method to invoke
*/
public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
super(methodInvocation);
context = ContextHolder.getContext();
if (logger.isDebugEnabled()) {
logger.debug("RemoteInvocation now has context of: "
+ context.toString());
}
}
//~ Methods ================================================================
/**
* Invoked on the server-side as described in the class JavaDocs.
*
* @param targetObject the target object to apply the invocation to
*
* @return the invocation result
*
* @throws NoSuchMethodException if the method name could not be resolved
* @throws IllegalAccessException if the method could not be accessed
* @throws InvocationTargetException if the method invocation resulted in
* an exception
*/
public Object invoke(Object targetObject)
throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
ContextHolder.setContext(context);
if (logger.isDebugEnabled()) {
logger.debug("Set ContextHolder to contain: " + context.toString());
}
Object result = super.invoke(targetObject);
ContextHolder.setContext(null);
if (logger.isDebugEnabled()) {
logger.debug("Set ContextHolder to null");
}
return result;
}
}

17
sandbox/src/main/java/org/acegisecurity/remoting/AcegiRemoteInvocationFactory.java → core/src/main/java/org/acegisecurity/ui/rmi/ContextPropagatingRemoteInvocationFactory.java

@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
* limitations under the License.
*/
package net.sf.acegisecurity.remoting;
package net.sf.acegisecurity.ui.rmi;
import org.aopalliance.intercept.MethodInvocation;
@ -22,16 +22,25 @@ import org.springframework.remoting.support.RemoteInvocationFactory; @@ -22,16 +22,25 @@ import org.springframework.remoting.support.RemoteInvocationFactory;
/**
* DOCUMENT ME!
* Called by a client-side instance of
* <code>org.springframework.remoting.rmi.RmiProxyFactoryBean</code> when it
* wishes to create a remote invocation.
*
* <P>
* Set an instance of this bean against the above class'
* <code>remoteInvocationFactory</code> property.
* </p>
*
* @author James Monaghan
* @author Ben Alex
* @version $Id$
*/
public class AcegiRemoteInvocationFactory implements RemoteInvocationFactory {
public class ContextPropagatingRemoteInvocationFactory
implements RemoteInvocationFactory {
//~ Methods ================================================================
public RemoteInvocation createRemoteInvocation(
MethodInvocation methodInvocation) {
return new AcegiRemoteInvocation(methodInvocation);
return new ContextPropagatingRemoteInvocation(methodInvocation);
}
}

8
sandbox/src/main/java/org/acegisecurity/remoting/package.html → core/src/main/java/org/acegisecurity/ui/rmi/package.html

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
<html>
<body>
Enables use of Spring's remoting extension points to propogate
security identity from one JVM to the remote JVM.
Enables use of Spring's RMI remoting extension points to propagate
the <code>ContextHolder</code> (which should contain an
<code>Authentication</code> request token)
from one JVM to the remote JVM.
<P>The beans are wired as follows:
@ -14,7 +16,7 @@ security identity from one JVM to the remote JVM. @@ -14,7 +16,7 @@ security identity from one JVM to the remote JVM.
&lt;property name="remoteInvocationFactory"&gt;&lt;ref bean="remoteInvocationFactory"/&gt;&lt;/property&gt;<BR>
&lt;/bean&gt;<BR>
<BR>
&lt;bean id="remoteInvocationFactory" class="net.sf.acegisecurity.remoting.AcegiRemoteInvocationFactory"/&gt;<BR>
&lt;bean id="remoteInvocationFactory" class="net.sf.acegisecurity.ui.rmi.ContextPropagatingRemoteInvocationFactory"/&gt;<BR>
</code>
</body>

58
sandbox/src/main/java/org/acegisecurity/remoting/AcegiRemoteInvocation.java

@ -1,58 +0,0 @@ @@ -1,58 +0,0 @@
/* Copyright 2004 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.remoting;
import net.sf.acegisecurity.context.Context;
import net.sf.acegisecurity.context.ContextHolder;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.remoting.support.RemoteInvocation;
import java.lang.reflect.InvocationTargetException;
/**
* DOCUMENT ME!
*
* @author James Monaghan
* @version $Id$
*/
public class AcegiRemoteInvocation extends RemoteInvocation {
//~ Instance fields ========================================================
private Context context;
//~ Constructors ===========================================================
public AcegiRemoteInvocation(MethodInvocation methodInvocation) {
super(methodInvocation);
context = ContextHolder.getContext();
}
//~ Methods ================================================================
public Object invoke(Object targetObject)
throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
ContextHolder.setContext(context);
Object result = super.invoke(targetObject);
ContextHolder.setContext(null);
return result;
}
}
Loading…
Cancel
Save