Always use 'this.' when accessing fields
Apply an Eclipse cleanup rules to ensure that fields are always accessed using `this.`. This aligns with the style used by Spring Framework and helps users quickly see the difference between a local and member variable. Issue gh-8945
This commit is contained in:
+1
-1
@@ -72,7 +72,7 @@ public class AuthenticationSimpleHttpInvokerRequestExecutor extends SimpleHttpIn
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null)
|
||||
&& !trustResolver.isAnonymous(auth)) {
|
||||
&& !this.trustResolver.isAnonymous(auth)) {
|
||||
String base64 = auth.getName() + ":" + auth.getCredentials().toString();
|
||||
con.setRequestProperty("Authorization",
|
||||
"Basic " + new String(Base64.getEncoder().encode(base64.getBytes())));
|
||||
|
||||
+7
-7
@@ -63,17 +63,17 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
||||
Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (currentUser != null) {
|
||||
principal = currentUser.getName();
|
||||
this.principal = currentUser.getName();
|
||||
Object userCredentials = currentUser.getCredentials();
|
||||
credentials = userCredentials == null ? null : userCredentials.toString();
|
||||
this.credentials = userCredentials == null ? null : userCredentials.toString();
|
||||
}
|
||||
else {
|
||||
principal = credentials = null;
|
||||
this.principal = this.credentials = null;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("RemoteInvocation now has principal: " + principal);
|
||||
if (credentials == null) {
|
||||
logger.debug("RemoteInvocation now has principal: " + this.principal);
|
||||
if (this.credentials == null) {
|
||||
logger.debug("RemoteInvocation now has null credentials.");
|
||||
}
|
||||
}
|
||||
@@ -94,8 +94,8 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
||||
public Object invoke(Object targetObject)
|
||||
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
|
||||
if (principal != null) {
|
||||
Authentication request = createAuthenticationRequest(principal, credentials);
|
||||
if (this.principal != null) {
|
||||
Authentication request = createAuthenticationRequest(this.principal, this.credentials);
|
||||
request.setAuthenticated(false);
|
||||
SecurityContextHolder.getContext().setAuthentication(request);
|
||||
|
||||
|
||||
+19
-18
@@ -45,64 +45,65 @@ public class JndiDnsResolverTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
contextFactory = mock(InitialContextFactory.class);
|
||||
context = mock(DirContext.class);
|
||||
dnsResolver = new JndiDnsResolver();
|
||||
dnsResolver.setCtxFactory(contextFactory);
|
||||
when(contextFactory.getCtx()).thenReturn(context);
|
||||
this.contextFactory = mock(InitialContextFactory.class);
|
||||
this.context = mock(DirContext.class);
|
||||
this.dnsResolver = new JndiDnsResolver();
|
||||
this.dnsResolver.setCtxFactory(this.contextFactory);
|
||||
when(this.contextFactory.getCtx()).thenReturn(this.context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveIpAddress() throws Exception {
|
||||
Attributes records = new BasicAttributes("A", "63.246.7.80");
|
||||
|
||||
when(context.getAttributes("www.springsource.com", new String[] { "A" })).thenReturn(records);
|
||||
when(this.context.getAttributes("www.springsource.com", new String[] { "A" })).thenReturn(records);
|
||||
|
||||
String ipAddress = dnsResolver.resolveIpAddress("www.springsource.com");
|
||||
String ipAddress = this.dnsResolver.resolveIpAddress("www.springsource.com");
|
||||
assertThat(ipAddress).isEqualTo("63.246.7.80");
|
||||
}
|
||||
|
||||
@Test(expected = DnsEntryNotFoundException.class)
|
||||
public void testResolveIpAddressNotExisting() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class)))
|
||||
when(this.context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NameNotFoundException("not found"));
|
||||
|
||||
dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
|
||||
this.dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveServiceEntry() throws Exception {
|
||||
BasicAttributes records = createSrvRecords();
|
||||
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(records);
|
||||
when(this.context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(records);
|
||||
|
||||
String hostname = dnsResolver.resolveServiceEntry("ldap", "springsource.com");
|
||||
String hostname = this.dnsResolver.resolveServiceEntry("ldap", "springsource.com");
|
||||
assertThat(hostname).isEqualTo("kdc.springsource.com");
|
||||
}
|
||||
|
||||
@Test(expected = DnsEntryNotFoundException.class)
|
||||
public void testResolveServiceEntryNotExisting() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class)))
|
||||
when(this.context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NameNotFoundException("not found"));
|
||||
|
||||
dnsResolver.resolveServiceEntry("wrong", "secpod.de");
|
||||
this.dnsResolver.resolveServiceEntry("wrong", "secpod.de");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveServiceIpAddress() throws Exception {
|
||||
BasicAttributes srvRecords = createSrvRecords();
|
||||
BasicAttributes aRecords = new BasicAttributes("A", "63.246.7.80");
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(srvRecords);
|
||||
when(context.getAttributes("kdc.springsource.com", new String[] { "A" })).thenReturn(aRecords);
|
||||
when(this.context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(srvRecords);
|
||||
when(this.context.getAttributes("kdc.springsource.com", new String[] { "A" })).thenReturn(aRecords);
|
||||
|
||||
String ipAddress = dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
|
||||
String ipAddress = this.dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
|
||||
assertThat(ipAddress).isEqualTo("63.246.7.80");
|
||||
}
|
||||
|
||||
@Test(expected = DnsLookupException.class)
|
||||
public void testUnknowError() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NamingException("error"));
|
||||
dnsResolver.resolveIpAddress("");
|
||||
when(this.context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NamingException("error"));
|
||||
this.dnsResolver.resolveIpAddress("");
|
||||
}
|
||||
|
||||
private BasicAttributes createSrvRecords() {
|
||||
|
||||
+2
-2
@@ -111,11 +111,11 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
|
||||
}
|
||||
|
||||
public String getRequestProperty(String key) {
|
||||
return requestProperties.get(key);
|
||||
return this.requestProperties.get(key);
|
||||
}
|
||||
|
||||
public void setRequestProperty(String key, String value) {
|
||||
requestProperties.put(key, value);
|
||||
this.requestProperties.put(key, value);
|
||||
}
|
||||
|
||||
public boolean usingProxy() {
|
||||
|
||||
Reference in New Issue
Block a user