Skip to content

Commit 16819be

Browse files
philwebbrwinch
authored andcommitted
Polish spring-security-remoting main code
Manually polish `spring-security-remoting` following the formatting and checkstyle fixes. Issue gh-8945
1 parent 5924ed8 commit 16819be

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

remoting/src/main/java/org/springframework/security/remoting/dns/JndiDnsResolver.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ private String resolveServiceEntry(String serviceType, String domain, DirContext
9898
// (highest number)
9999
int highestPriority = -1;
100100
int highestWeight = -1;
101-
102101
for (NamingEnumeration<?> recordEnum = dnsRecord.getAll(); recordEnum.hasMoreElements();) {
103102
String[] record = recordEnum.next().toString().split(" ");
104103
if (record.length != 4) {
@@ -123,7 +122,6 @@ private String resolveServiceEntry(String serviceType, String domain, DirContext
123122
catch (NamingException ex) {
124123
throw new DnsLookupException("DNS lookup failed for service " + serviceType + " at " + domain, ex);
125124
}
126-
127125
// remove the "." at the end
128126
if (result.endsWith(".")) {
129127
result = result.substring(0, result.length() - 1);
@@ -134,7 +132,6 @@ private String resolveServiceEntry(String serviceType, String domain, DirContext
134132
private Attribute lookup(String query, DirContext ictx, String recordType) {
135133
try {
136134
Attributes dnsResult = ictx.getAttributes(query, new String[] { recordType });
137-
138135
return dnsResult.get(recordType);
139136
}
140137
catch (NamingException ex) {
@@ -152,14 +149,12 @@ public DirContext getCtx() {
152149
Hashtable<String, String> env = new Hashtable<>();
153150
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
154151
env.put(Context.PROVIDER_URL, "dns:"); // This is needed for IBM JDK/JRE
155-
InitialDirContext ictx;
156152
try {
157-
ictx = new InitialDirContext(env);
153+
return new InitialDirContext(env);
158154
}
159155
catch (NamingException ex) {
160156
throw new DnsLookupException("Cannot create InitialDirContext for DNS lookup", ex);
161157
}
162-
return ictx;
163158
}
164159

165160
}

remoting/src/main/java/org/springframework/security/remoting/rmi/ContextPropagatingRemoteInvocation.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
2424

25+
import org.springframework.core.log.LogMessage;
2526
import org.springframework.remoting.support.RemoteInvocation;
2627
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
2728
import org.springframework.security.core.Authentication;
@@ -61,7 +62,6 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
6162
public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
6263
super(methodInvocation);
6364
Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
64-
6565
if (currentUser != null) {
6666
this.principal = currentUser.getName();
6767
Object userCredentials = currentUser.getCredentials();
@@ -71,7 +71,6 @@ public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
7171
this.credentials = null;
7272
this.principal = null;
7373
}
74-
7574
if (logger.isDebugEnabled()) {
7675
logger.debug("RemoteInvocation now has principal: " + this.principal);
7776
if (this.credentials == null) {
@@ -95,26 +94,18 @@ public ContextPropagatingRemoteInvocation(MethodInvocation methodInvocation) {
9594
@Override
9695
public Object invoke(Object targetObject)
9796
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
98-
9997
if (this.principal != null) {
10098
Authentication request = createAuthenticationRequest(this.principal, this.credentials);
10199
request.setAuthenticated(false);
102100
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));
107102
}
108-
109103
try {
110104
return super.invoke(targetObject);
111105
}
112106
finally {
113107
SecurityContextHolder.clearContext();
114-
115-
if (logger.isDebugEnabled()) {
116-
logger.debug("Cleared SecurityContextHolder.");
117-
}
108+
logger.debug("Cleared SecurityContextHolder.");
118109
}
119110
}
120111

0 commit comments

Comments
 (0)