Skip to content

Commit cdafa4e

Browse files
committed
Clarify variable names
Issue gh-11327
1 parent 0c48b6b commit cdafa4e

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

config/src/main/java/org/springframework/security/config/http/DefaultFilterChainValidator.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ private void checkForDuplicates(Class<? extends Filter> clazz, List<Filter> filt
134134
* interceptor
135135
*/
136136
private void checkLoginPageIsntProtected(FilterChainProxy fcp, List<Filter> filterStack) {
137-
ExceptionTranslationFilter etf = getFilter(ExceptionTranslationFilter.class, filterStack);
138-
if (etf == null || !(etf.getAuthenticationEntryPoint() instanceof LoginUrlAuthenticationEntryPoint)) {
137+
ExceptionTranslationFilter exceptions = getFilter(ExceptionTranslationFilter.class, filterStack);
138+
if (exceptions == null
139+
|| !(exceptions.getAuthenticationEntryPoint() instanceof LoginUrlAuthenticationEntryPoint)) {
139140
return;
140141
}
141-
String loginPage = ((LoginUrlAuthenticationEntryPoint) etf.getAuthenticationEntryPoint()).getLoginFormUrl();
142+
String loginPage = ((LoginUrlAuthenticationEntryPoint) exceptions.getAuthenticationEntryPoint())
143+
.getLoginFormUrl();
142144
this.logger.info("Checking whether login URL '" + loginPage + "' is accessible with your configuration");
143145
FilterInvocation loginRequest = new FilterInvocation(loginPage, "POST");
144146
List<Filter> filters = null;
@@ -159,28 +161,28 @@ private void checkLoginPageIsntProtected(FilterChainProxy fcp, List<Filter> filt
159161
this.logger.debug("Default generated login page is in use");
160162
return;
161163
}
162-
FilterSecurityInterceptor fsi = getFilter(FilterSecurityInterceptor.class, filters);
163-
FilterInvocationSecurityMetadataSource fids = fsi.getSecurityMetadataSource();
164+
FilterSecurityInterceptor authorizationInterceptor = getFilter(FilterSecurityInterceptor.class, filters);
165+
FilterInvocationSecurityMetadataSource fids = authorizationInterceptor.getSecurityMetadataSource();
164166
Collection<ConfigAttribute> attributes = fids.getAttributes(loginRequest);
165167
if (attributes == null) {
166168
this.logger.debug("No access attributes defined for login page URL");
167-
if (fsi.isRejectPublicInvocations()) {
169+
if (authorizationInterceptor.isRejectPublicInvocations()) {
168170
this.logger.warn("FilterSecurityInterceptor is configured to reject public invocations."
169171
+ " Your login page may not be accessible.");
170172
}
171173
return;
172174
}
173-
AnonymousAuthenticationFilter anonPF = getFilter(AnonymousAuthenticationFilter.class, filters);
174-
if (anonPF == null) {
175+
AnonymousAuthenticationFilter anonymous = getFilter(AnonymousAuthenticationFilter.class, filters);
176+
if (anonymous == null) {
175177
this.logger.warn("The login page is being protected by the filter chain, but you don't appear to have"
176178
+ " anonymous authentication enabled. This is almost certainly an error.");
177179
return;
178180
}
179181
// Simulate an anonymous access with the supplied attributes.
180-
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", anonPF.getPrincipal(),
181-
anonPF.getAuthorities());
182+
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", anonymous.getPrincipal(),
183+
anonymous.getAuthorities());
182184
try {
183-
fsi.getAccessDecisionManager().decide(token, loginRequest, attributes);
185+
authorizationInterceptor.getAccessDecisionManager().decide(token, loginRequest, attributes);
184186
}
185187
catch (AccessDeniedException ex) {
186188
this.logger.warn("Anonymous access to the login page doesn't appear to be enabled. "

config/src/test/java/org/springframework/security/config/http/DefaultFilterChainValidatorTests.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class DefaultFilterChainValidatorTests {
5353

5454
private DefaultFilterChainValidator validator;
5555

56-
private FilterChainProxy fcp;
56+
private FilterChainProxy chain;
5757

5858
@Mock
5959
private Log logger;
@@ -64,19 +64,19 @@ public class DefaultFilterChainValidatorTests {
6464
@Mock
6565
private AccessDecisionManager accessDecisionManager;
6666

67-
private FilterSecurityInterceptor fsi;
67+
private FilterSecurityInterceptor authorizationInterceptor;
6868

6969
@BeforeEach
7070
public void setUp() {
7171
AnonymousAuthenticationFilter aaf = new AnonymousAuthenticationFilter("anonymous");
72-
this.fsi = new FilterSecurityInterceptor();
73-
this.fsi.setAccessDecisionManager(this.accessDecisionManager);
74-
this.fsi.setSecurityMetadataSource(this.metadataSource);
72+
this.authorizationInterceptor = new FilterSecurityInterceptor();
73+
this.authorizationInterceptor.setAccessDecisionManager(this.accessDecisionManager);
74+
this.authorizationInterceptor.setSecurityMetadataSource(this.metadataSource);
7575
AuthenticationEntryPoint authenticationEntryPoint = new LoginUrlAuthenticationEntryPoint("/login");
7676
ExceptionTranslationFilter etf = new ExceptionTranslationFilter(authenticationEntryPoint);
7777
DefaultSecurityFilterChain securityChain = new DefaultSecurityFilterChain(AnyRequestMatcher.INSTANCE, aaf, etf,
78-
this.fsi);
79-
this.fcp = new FilterChainProxy(securityChain);
78+
this.authorizationInterceptor);
79+
this.chain = new FilterChainProxy(securityChain);
8080
this.validator = new DefaultFilterChainValidator();
8181
ReflectionTestUtils.setField(this.validator, "logger", this.logger);
8282
}
@@ -88,7 +88,7 @@ public void validateCheckLoginPageIsntProtectedThrowsIllegalArgumentException()
8888
IllegalArgumentException toBeThrown = new IllegalArgumentException("failed to eval expression");
8989
willThrow(toBeThrown).given(this.accessDecisionManager).decide(any(Authentication.class), anyObject(),
9090
any(Collection.class));
91-
this.validator.validate(this.fcp);
91+
this.validator.validate(this.chain);
9292
verify(this.logger).info(
9393
"Unable to check access to the login page to determine if anonymous access is allowed. This might be an error, but can happen under normal circumstances.",
9494
toBeThrown);
@@ -99,8 +99,8 @@ public void validateCheckLoginPageIsntProtectedThrowsIllegalArgumentException()
9999
public void validateCustomMetadataSource() {
100100
FilterInvocationSecurityMetadataSource customMetaDataSource = mock(
101101
FilterInvocationSecurityMetadataSource.class);
102-
this.fsi.setSecurityMetadataSource(customMetaDataSource);
103-
this.validator.validate(this.fcp);
102+
this.authorizationInterceptor.setSecurityMetadataSource(customMetaDataSource);
103+
this.validator.validate(this.chain);
104104
verify(customMetaDataSource).getAttributes(any());
105105
}
106106

0 commit comments

Comments
 (0)