1
0
mirror of synced 2026-05-22 21:33:16 +00:00

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:
Phillip Webb
2020-07-26 11:51:05 -07:00
committed by Rob Winch
parent 6894ff5d12
commit 8866fa6fb0
793 changed files with 8689 additions and 8459 deletions
@@ -80,30 +80,30 @@ public class OpenID4JavaConsumer implements OpenIDConsumer {
List<DiscoveryInformation> discoveries;
try {
discoveries = consumerManager.discover(identityUrl);
discoveries = this.consumerManager.discover(identityUrl);
}
catch (DiscoveryException e) {
throw new OpenIDConsumerException("Error during discovery", e);
}
DiscoveryInformation information = consumerManager.associate(discoveries);
DiscoveryInformation information = this.consumerManager.associate(discoveries);
req.getSession().setAttribute(DISCOVERY_INFO_KEY, information);
AuthRequest authReq;
try {
authReq = consumerManager.authenticate(information, returnToUrl, realm);
authReq = this.consumerManager.authenticate(information, returnToUrl, realm);
logger.debug("Looking up attribute fetch list for identifier: " + identityUrl);
this.logger.debug("Looking up attribute fetch list for identifier: " + identityUrl);
List<OpenIDAttribute> attributesToFetch = attributesToFetchFactory.createAttributeList(identityUrl);
List<OpenIDAttribute> attributesToFetch = this.attributesToFetchFactory.createAttributeList(identityUrl);
if (!attributesToFetch.isEmpty()) {
req.getSession().setAttribute(ATTRIBUTE_LIST_KEY, attributesToFetch);
FetchRequest fetchRequest = FetchRequest.createFetchRequest();
for (OpenIDAttribute attr : attributesToFetch) {
if (logger.isDebugEnabled()) {
logger.debug("Adding attribute " + attr.getType() + " to fetch request");
if (this.logger.isDebugEnabled()) {
this.logger.debug("Adding attribute " + attr.getType() + " to fetch request");
}
fetchRequest.addAttribute(attr.getName(), attr.getType(), attr.isRequired(), attr.getCount());
}
@@ -148,7 +148,7 @@ public class OpenID4JavaConsumer implements OpenIDConsumer {
VerificationResult verification;
try {
verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered);
verification = this.consumerManager.verify(receivingURL.toString(), openidResp, discovered);
}
catch (MessageException | AssociationException | DiscoveryException e) {
throw new OpenIDConsumerException("Error verifying openid response", e);
@@ -178,7 +178,7 @@ public class OpenID4JavaConsumer implements OpenIDConsumer {
return Collections.emptyList();
}
logger.debug("Extracting attributes retrieved by attribute exchange");
this.logger.debug("Extracting attributes retrieved by attribute exchange");
List<OpenIDAttribute> attributes = Collections.emptyList();
@@ -202,8 +202,8 @@ public class OpenID4JavaConsumer implements OpenIDConsumer {
throw new OpenIDConsumerException("Attribute retrieval failed", e);
}
if (logger.isDebugEnabled()) {
logger.debug("Retrieved attributes" + attributes);
if (this.logger.isDebugEnabled()) {
this.logger.debug("Retrieved attributes" + attributes);
}
return attributes;
@@ -63,14 +63,14 @@ public class OpenIDAttribute implements Serializable {
* The attribute name
*/
public String getName() {
return name;
return this.name;
}
/**
* The attribute type Identifier (a URI).
*/
public String getType() {
return typeIdentifier;
return this.typeIdentifier;
}
/**
@@ -78,7 +78,7 @@ public class OpenIDAttribute implements Serializable {
* Defaults to "false".
*/
public boolean isRequired() {
return required;
return this.required;
}
public void setRequired(boolean required) {
@@ -90,7 +90,7 @@ public class OpenIDAttribute implements Serializable {
* request. Defaults to 1.
*/
public int getCount() {
return count;
return this.count;
}
public void setCount(int count) {
@@ -101,17 +101,17 @@ public class OpenIDAttribute implements Serializable {
* The values obtained from an attribute exchange.
*/
public List<String> getValues() {
Assert.notNull(values, "Cannot read values from an authentication request attribute");
return values;
Assert.notNull(this.values, "Cannot read values from an authentication request attribute");
return this.values;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder("[");
result.append(name);
if (values != null) {
result.append(this.name);
if (this.values != null) {
result.append(":");
result.append(values.toString());
result.append(this.values.toString());
}
result.append("]");
return result.toString();
@@ -95,18 +95,18 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
public void afterPropertiesSet() {
super.afterPropertiesSet();
if (consumer == null) {
if (this.consumer == null) {
try {
consumer = new OpenID4JavaConsumer();
this.consumer = new OpenID4JavaConsumer();
}
catch (ConsumerException e) {
throw new IllegalArgumentException("Failed to initialize OpenID", e);
}
}
if (returnToUrlParameters.isEmpty() && getRememberMeServices() instanceof AbstractRememberMeServices) {
returnToUrlParameters = new HashSet<>();
returnToUrlParameters.add(((AbstractRememberMeServices) getRememberMeServices()).getParameter());
if (this.returnToUrlParameters.isEmpty() && getRememberMeServices() instanceof AbstractRememberMeServices) {
this.returnToUrlParameters = new HashSet<>();
this.returnToUrlParameters.add(((AbstractRememberMeServices) getRememberMeServices()).getParameter());
}
}
@@ -132,10 +132,10 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
try {
String returnToUrl = buildReturnToUrl(request);
String realm = lookupRealm(returnToUrl);
String openIdUrl = consumer.beginConsumption(request, claimedIdentity, returnToUrl, realm);
if (logger.isDebugEnabled()) {
logger.debug("return_to is '" + returnToUrl + "', realm is '" + realm + "'");
logger.debug("Redirecting to " + openIdUrl);
String openIdUrl = this.consumer.beginConsumption(request, claimedIdentity, returnToUrl, realm);
if (this.logger.isDebugEnabled()) {
this.logger.debug("return_to is '" + returnToUrl + "', realm is '" + realm + "'");
this.logger.debug("Redirecting to " + openIdUrl);
}
response.sendRedirect(openIdUrl);
@@ -143,24 +143,24 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
return null;
}
catch (OpenIDConsumerException e) {
logger.debug("Failed to consume claimedIdentity: " + claimedIdentity, e);
this.logger.debug("Failed to consume claimedIdentity: " + claimedIdentity, e);
throw new AuthenticationServiceException(
"Unable to process claimed identity '" + claimedIdentity + "'");
}
}
if (logger.isDebugEnabled()) {
logger.debug("Supplied OpenID identity is " + identity);
if (this.logger.isDebugEnabled()) {
this.logger.debug("Supplied OpenID identity is " + identity);
}
try {
token = consumer.endConsumption(request);
token = this.consumer.endConsumption(request);
}
catch (OpenIDConsumerException oice) {
throw new AuthenticationServiceException("Consumer error", oice);
}
token.setDetails(authenticationDetailsSource.buildDetails(request));
token.setDetails(this.authenticationDetailsSource.buildDetails(request));
// delegate to the authentication provider
Authentication authentication = this.getAuthenticationManager().authenticate(token);
@@ -169,7 +169,7 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
}
protected String lookupRealm(String returnToUrl) {
String mapping = realmMapping.get(returnToUrl);
String mapping = this.realmMapping.get(returnToUrl);
if (mapping == null) {
try {
@@ -185,7 +185,7 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
mapping = realmBuffer.toString();
}
catch (MalformedURLException e) {
logger.warn("returnToUrl was not a valid URL: [" + returnToUrl + "]", e);
this.logger.warn("returnToUrl was not a valid URL: [" + returnToUrl + "]", e);
}
}
@@ -201,7 +201,7 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
protected String buildReturnToUrl(HttpServletRequest request) {
StringBuffer sb = request.getRequestURL();
Iterator<String> iterator = returnToUrlParameters.iterator();
Iterator<String> iterator = this.returnToUrlParameters.iterator();
boolean isFirst = true;
while (iterator.hasNext()) {
@@ -230,10 +230,10 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
* Reads the <tt>claimedIdentityFieldName</tt> from the submitted request.
*/
protected String obtainUsername(HttpServletRequest req) {
String claimedIdentity = req.getParameter(claimedIdentityFieldName);
String claimedIdentity = req.getParameter(this.claimedIdentityFieldName);
if (!StringUtils.hasText(claimedIdentity)) {
logger.error("No claimed identity supplied in authentication request");
this.logger.error("No claimed identity supplied in authentication request");
return "";
}
@@ -53,7 +53,7 @@ public enum OpenIDAuthenticationStatus {
@Override
public String toString() {
return name;
return this.name;
}
}
@@ -84,11 +84,11 @@ public class OpenIDAuthenticationToken extends AbstractAuthenticationToken {
}
public String getIdentityUrl() {
return identityUrl;
return this.identityUrl;
}
public String getMessage() {
return message;
return this.message;
}
/**
@@ -97,20 +97,20 @@ public class OpenIDAuthenticationToken extends AbstractAuthenticationToken {
* @see org.springframework.security.core.Authentication#getPrincipal()
*/
public Object getPrincipal() {
return principal;
return this.principal;
}
public OpenIDAuthenticationStatus getStatus() {
return status;
return this.status;
}
public List<OpenIDAttribute> getAttributes() {
return attributes;
return this.attributes;
}
@Override
public String toString() {
return "[" + super.toString() + ", attributes : " + attributes + "]";
return "[" + super.toString() + ", attributes : " + this.attributes + "]";
}
}
@@ -38,9 +38,9 @@ public class RegexBasedAxFetchListFactory implements AxFetchListFactory {
* which should be fetched for that pattern.
*/
public RegexBasedAxFetchListFactory(Map<String, List<OpenIDAttribute>> regexMap) {
idToAttributes = new LinkedHashMap<>();
this.idToAttributes = new LinkedHashMap<>();
for (Map.Entry<String, List<OpenIDAttribute>> entry : regexMap.entrySet()) {
idToAttributes.put(Pattern.compile(entry.getKey()), entry.getValue());
this.idToAttributes.put(Pattern.compile(entry.getKey()), entry.getValue());
}
}
@@ -49,7 +49,7 @@ public class RegexBasedAxFetchListFactory implements AxFetchListFactory {
* defined for the first match. If no match is found, returns an empty list.
*/
public List<OpenIDAttribute> createAttributeList(String identifier) {
for (Map.Entry<Pattern, List<OpenIDAttribute>> entry : idToAttributes.entrySet()) {
for (Map.Entry<Pattern, List<OpenIDAttribute>> entry : this.idToAttributes.entrySet()) {
if (entry.getKey().matcher(identifier).matches()) {
return entry.getValue();
}
@@ -47,11 +47,11 @@ public class MockOpenIDConsumer implements OpenIDConsumer {
}
public String beginConsumption(HttpServletRequest req, String claimedIdentity, String returnToUrl, String realm) {
return redirectUrl;
return this.redirectUrl;
}
public OpenIDAuthenticationToken endConsumption(HttpServletRequest req) {
return token;
return this.token;
}
/**
@@ -70,7 +70,7 @@ public class OpenID4JavaConsumerTests {
consumer.beginConsumption(request, "", "", "");
assertThat(request.getSession().getAttribute("SPRING_SECURITY_OPEN_ID_ATTRIBUTES_FETCH_LIST"))
.isEqualTo(attributes);
.isEqualTo(this.attributes);
assertThat(request.getSession().getAttribute(DiscoveryInformation.class.getName())).isEqualTo(di);
// Check with empty attribute fetch list
@@ -180,7 +180,7 @@ public class OpenID4JavaConsumerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.getSession().setAttribute(DiscoveryInformation.class.getName(), di);
request.getSession().setAttribute("SPRING_SECURITY_OPEN_ID_ATTRIBUTES_FETCH_LIST", attributes);
request.getSession().setAttribute("SPRING_SECURITY_OPEN_ID_ATTRIBUTES_FETCH_LIST", this.attributes);
OpenIDAuthenticationToken auth = consumer.endConsumption(request);
@@ -196,7 +196,7 @@ public class OpenID4JavaConsumerTests {
when(msg.getExtension(AxMessage.OPENID_NS_AX)).thenReturn(fr);
when(fr.getAttributeValues("a")).thenReturn(Arrays.asList("x", "y"));
List<OpenIDAttribute> fetched = consumer.fetchAxAttributes(msg, attributes);
List<OpenIDAttribute> fetched = consumer.fetchAxAttributes(msg, this.attributes);
assertThat(fetched).hasSize(1);
assertThat(fetched.get(0).getValues()).hasSize(2);
@@ -211,7 +211,7 @@ public class OpenID4JavaConsumerTests {
when(msg.getExtension(AxMessage.OPENID_NS_AX)).thenThrow(new MessageException(""));
when(fr.getAttributeValues("a")).thenReturn(Arrays.asList("x", "y"));
consumer.fetchAxAttributes(msg, attributes);
consumer.fetchAxAttributes(msg, this.attributes);
}
@Test(expected = OpenIDConsumerException.class)
@@ -229,7 +229,7 @@ public class OpenID4JavaConsumerTests {
private class MockAttributesFactory implements AxFetchListFactory {
public List<OpenIDAttribute> createAttributeList(String identifier) {
return attributes;
return OpenID4JavaConsumerTests.this.attributes;
}
}
@@ -57,13 +57,13 @@ public class OpenIDAuthenticationFilterTests {
@Before
public void setUp() {
filter = new OpenIDAuthenticationFilter();
filter.setConsumer(new MockOpenIDConsumer(REDIRECT_URL));
this.filter = new OpenIDAuthenticationFilter();
this.filter.setConsumer(new MockOpenIDConsumer(REDIRECT_URL));
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
filter.setAuthenticationSuccessHandler(new SavedRequestAwareAuthenticationSuccessHandler());
this.filter.setAuthenticationSuccessHandler(new SavedRequestAwareAuthenticationSuccessHandler());
successHandler.setDefaultTargetUrl(DEFAULT_TARGET_URL);
filter.setAuthenticationManager(a -> a);
filter.afterPropertiesSet();
this.filter.setAuthenticationManager(a -> a);
this.filter.afterPropertiesSet();
}
@Test
@@ -77,7 +77,7 @@ public class OpenIDAuthenticationFilterTests {
req.setParameter("openid_identifier", " " + CLAIMED_IDENTITY_URL);
req.setRemoteHost("www.example.com");
filter.setConsumer(new MockOpenIDConsumer() {
this.filter.setConsumer(new MockOpenIDConsumer() {
public String beginConsumption(HttpServletRequest req, String claimedIdentity, String returnToUrl,
String realm) {
assertThat(claimedIdentity).isEqualTo(CLAIMED_IDENTITY_URL);
@@ -88,7 +88,7 @@ public class OpenIDAuthenticationFilterTests {
});
FilterChain fc = mock(FilterChain.class);
filter.doFilter(req, response, fc);
this.filter.doFilter(req, response, fc);
assertThat(response.getRedirectedUrl()).isEqualTo(REDIRECT_URL);
// Filter chain shouldn't proceed
verify(fc, never()).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
@@ -104,9 +104,9 @@ public class OpenIDAuthenticationFilterTests {
String paramValue = "https://example.com/path?a=b&c=d";
MockHttpServletRequest req = new MockHttpServletRequest("GET", REQUEST_PATH);
req.addParameter(paramName, paramValue);
filter.setReturnToUrlParameters(Collections.singleton(paramName));
this.filter.setReturnToUrlParameters(Collections.singleton(paramName));
URI returnTo = new URI(filter.buildReturnToUrl(req));
URI returnTo = new URI(this.filter.buildReturnToUrl(req));
String query = returnTo.getRawQuery();
assertThat(count(query, '=')).isEqualTo(1);
assertThat(count(query, '&')).isZero();