Skip to content

Commit ec8c133

Browse files
committed
Clarify variable names
Issue gh-11327
1 parent 696da87 commit ec8c133

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
@@ -133,11 +133,13 @@ private void checkForDuplicates(Class<? extends Filter> clazz, List<Filter> filt
133133
* interceptor
134134
*/
135135
private void checkLoginPageIsntProtected(FilterChainProxy fcp, List<Filter> filterStack) {
136-
ExceptionTranslationFilter etf = getFilter(ExceptionTranslationFilter.class, filterStack);
137-
if (etf == null || !(etf.getAuthenticationEntryPoint() instanceof LoginUrlAuthenticationEntryPoint)) {
136+
ExceptionTranslationFilter exceptions = getFilter(ExceptionTranslationFilter.class, filterStack);
137+
if (exceptions == null
138+
|| !(exceptions.getAuthenticationEntryPoint() instanceof LoginUrlAuthenticationEntryPoint)) {
138139
return;
139140
}
140-
String loginPage = ((LoginUrlAuthenticationEntryPoint) etf.getAuthenticationEntryPoint()).getLoginFormUrl();
141+
String loginPage = ((LoginUrlAuthenticationEntryPoint) exceptions.getAuthenticationEntryPoint())
142+
.getLoginFormUrl();
141143
this.logger.info("Checking whether login URL '" + loginPage + "' is accessible with your configuration");
142144
FilterInvocation loginRequest = new FilterInvocation(loginPage, "POST");
143145
List<Filter> filters = null;
@@ -158,28 +160,28 @@ private void checkLoginPageIsntProtected(FilterChainProxy fcp, List<Filter> filt
158160
this.logger.debug("Default generated login page is in use");
159161
return;
160162
}
161-
FilterSecurityInterceptor fsi = getFilter(FilterSecurityInterceptor.class, filters);
162-
FilterInvocationSecurityMetadataSource fids = fsi.getSecurityMetadataSource();
163+
FilterSecurityInterceptor authorizationInterceptor = getFilter(FilterSecurityInterceptor.class, filters);
164+
FilterInvocationSecurityMetadataSource fids = authorizationInterceptor.getSecurityMetadataSource();
163165
Collection<ConfigAttribute> attributes = fids.getAttributes(loginRequest);
164166
if (attributes == null) {
165167
this.logger.debug("No access attributes defined for login page URL");
166-
if (fsi.isRejectPublicInvocations()) {
168+
if (authorizationInterceptor.isRejectPublicInvocations()) {
167169
this.logger.warn("FilterSecurityInterceptor is configured to reject public invocations."
168170
+ " Your login page may not be accessible.");
169171
}
170172
return;
171173
}
172-
AnonymousAuthenticationFilter anonPF = getFilter(AnonymousAuthenticationFilter.class, filters);
173-
if (anonPF == null) {
174+
AnonymousAuthenticationFilter anonymous = getFilter(AnonymousAuthenticationFilter.class, filters);
175+
if (anonymous == null) {
174176
this.logger.warn("The login page is being protected by the filter chain, but you don't appear to have"
175177
+ " anonymous authentication enabled. This is almost certainly an error.");
176178
return;
177179
}
178180
// Simulate an anonymous access with the supplied attributes.
179-
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", anonPF.getPrincipal(),
180-
anonPF.getAuthorities());
181+
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", anonymous.getPrincipal(),
182+
anonymous.getAuthorities());
181183
try {
182-
fsi.getAccessDecisionManager().decide(token, loginRequest, attributes);
184+
authorizationInterceptor.getAccessDecisionManager().decide(token, loginRequest, attributes);
183185
}
184186
catch (AccessDeniedException ex) {
185187
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)