22
22
import org .apache .commons .logging .Log ;
23
23
import org .apache .commons .logging .LogFactory ;
24
24
25
+ import org .springframework .core .log .LogMessage ;
25
26
import org .springframework .remoting .support .RemoteInvocation ;
26
27
import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
27
28
import org .springframework .security .core .Authentication ;
@@ -61,7 +62,6 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
61
62
public ContextPropagatingRemoteInvocation (MethodInvocation methodInvocation ) {
62
63
super (methodInvocation );
63
64
Authentication currentUser = SecurityContextHolder .getContext ().getAuthentication ();
64
-
65
65
if (currentUser != null ) {
66
66
this .principal = currentUser .getName ();
67
67
Object userCredentials = currentUser .getCredentials ();
@@ -71,7 +71,6 @@ public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
71
71
this .credentials = null ;
72
72
this .principal = null ;
73
73
}
74
-
75
74
if (logger .isDebugEnabled ()) {
76
75
logger .debug ("RemoteInvocation now has principal: " + this .principal );
77
76
if (this .credentials == null ) {
@@ -95,26 +94,18 @@ public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
95
94
@ Override
96
95
public Object invoke (Object targetObject )
97
96
throws NoSuchMethodException , IllegalAccessException , InvocationTargetException {
98
-
99
97
if (this .principal != null ) {
100
98
Authentication request = createAuthenticationRequest (this .principal , this .credentials );
101
99
request .setAuthenticated (false );
102
100
SecurityContextHolder .getContext ().setAuthentication (request );
103
-
104
- if (logger .isDebugEnabled ()) {
105
- logger .debug ("Set SecurityContextHolder to contain: " + request );
106
- }
101
+ logger .debug (LogMessage .format ("Set SecurityContextHolder to contain: %s" , request ));
107
102
}
108
-
109
103
try {
110
104
return super .invoke (targetObject );
111
105
}
112
106
finally {
113
107
SecurityContextHolder .clearContext ();
114
-
115
- if (logger .isDebugEnabled ()) {
116
- logger .debug ("Cleared SecurityContextHolder." );
117
- }
108
+ logger .debug ("Cleared SecurityContextHolder." );
118
109
}
119
110
}
120
111
0 commit comments