|
@@ -22,6 +22,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
+import org.springframework.core.log.LogMessage;
|
|
import org.springframework.remoting.support.RemoteInvocation;
|
|
import org.springframework.remoting.support.RemoteInvocation;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
@@ -61,7 +62,6 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
|
public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
|
|
public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
|
|
super(methodInvocation);
|
|
super(methodInvocation);
|
|
Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
|
|
Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
|
|
-
|
|
|
|
if (currentUser != null) {
|
|
if (currentUser != null) {
|
|
this.principal = currentUser.getName();
|
|
this.principal = currentUser.getName();
|
|
Object userCredentials = currentUser.getCredentials();
|
|
Object userCredentials = currentUser.getCredentials();
|
|
@@ -71,7 +71,6 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
|
this.credentials = null;
|
|
this.credentials = null;
|
|
this.principal = null;
|
|
this.principal = null;
|
|
}
|
|
}
|
|
-
|
|
|
|
if (logger.isDebugEnabled()) {
|
|
if (logger.isDebugEnabled()) {
|
|
logger.debug("RemoteInvocation now has principal: " + this.principal);
|
|
logger.debug("RemoteInvocation now has principal: " + this.principal);
|
|
if (this.credentials == null) {
|
|
if (this.credentials == null) {
|
|
@@ -95,26 +94,18 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
|
@Override
|
|
@Override
|
|
public Object invoke(Object targetObject)
|
|
public Object invoke(Object targetObject)
|
|
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
|
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
|
-
|
|
|
|
if (this.principal != null) {
|
|
if (this.principal != null) {
|
|
Authentication request = createAuthenticationRequest(this.principal, this.credentials);
|
|
Authentication request = createAuthenticationRequest(this.principal, this.credentials);
|
|
request.setAuthenticated(false);
|
|
request.setAuthenticated(false);
|
|
SecurityContextHolder.getContext().setAuthentication(request);
|
|
SecurityContextHolder.getContext().setAuthentication(request);
|
|
-
|
|
|
|
- if (logger.isDebugEnabled()) {
|
|
|
|
- logger.debug("Set SecurityContextHolder to contain: " + request);
|
|
|
|
- }
|
|
|
|
|
|
+ logger.debug(LogMessage.format("Set SecurityContextHolder to contain: %s", request));
|
|
}
|
|
}
|
|
-
|
|
|
|
try {
|
|
try {
|
|
return super.invoke(targetObject);
|
|
return super.invoke(targetObject);
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
SecurityContextHolder.clearContext();
|
|
SecurityContextHolder.clearContext();
|
|
-
|
|
|
|
- if (logger.isDebugEnabled()) {
|
|
|
|
- logger.debug("Cleared SecurityContextHolder.");
|
|
|
|
- }
|
|
|
|
|
|
+ logger.debug("Cleared SecurityContextHolder.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|