Polish AuthenticationFilter

Updated member variable references to be prefixed with "this.".
Fixed typo in authentication manager resolver error message.

Issue: gh-6506
This commit is contained in:
Josh Cummings 2019-08-01 16:21:00 -06:00
parent 50adb6abcb
commit d157125c8e
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
1 changed files with 11 additions and 12 deletions

View File

@ -78,7 +78,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
public AuthenticationFilter(AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver, public AuthenticationFilter(AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver,
AuthenticationConverter authenticationConverter) { AuthenticationConverter authenticationConverter) {
Assert.notNull(authenticationManagerResolver, "authenticationResolverManager cannot be null"); Assert.notNull(authenticationManagerResolver, "authenticationManagerResolver cannot be null");
Assert.notNull(authenticationConverter, "authenticationConverter cannot be null"); Assert.notNull(authenticationConverter, "authenticationConverter cannot be null");
this.authenticationManagerResolver = authenticationManagerResolver; this.authenticationManagerResolver = authenticationManagerResolver;
@ -86,7 +86,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
} }
public RequestMatcher getRequestMatcher() { public RequestMatcher getRequestMatcher() {
return requestMatcher; return this.requestMatcher;
} }
public void setRequestMatcher(RequestMatcher requestMatcher) { public void setRequestMatcher(RequestMatcher requestMatcher) {
@ -95,7 +95,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
} }
public AuthenticationConverter getAuthenticationConverter() { public AuthenticationConverter getAuthenticationConverter() {
return authenticationConverter; return this.authenticationConverter;
} }
public void setAuthenticationConverter(AuthenticationConverter authenticationConverter) { public void setAuthenticationConverter(AuthenticationConverter authenticationConverter) {
@ -104,7 +104,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
} }
public AuthenticationSuccessHandler getSuccessHandler() { public AuthenticationSuccessHandler getSuccessHandler() {
return successHandler; return this.successHandler;
} }
public void setSuccessHandler(AuthenticationSuccessHandler successHandler) { public void setSuccessHandler(AuthenticationSuccessHandler successHandler) {
@ -113,7 +113,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
} }
public AuthenticationFailureHandler getFailureHandler() { public AuthenticationFailureHandler getFailureHandler() {
return failureHandler; return this.failureHandler;
} }
public void setFailureHandler(AuthenticationFailureHandler failureHandler) { public void setFailureHandler(AuthenticationFailureHandler failureHandler) {
@ -122,7 +122,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
} }
public AuthenticationManagerResolver<HttpServletRequest> getAuthenticationManagerResolver() { public AuthenticationManagerResolver<HttpServletRequest> getAuthenticationManagerResolver() {
return authenticationManagerResolver; return this.authenticationManagerResolver;
} }
public void setAuthenticationManagerResolver( public void setAuthenticationManagerResolver(
@ -134,7 +134,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
@Override @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException { throws ServletException, IOException {
if (!requestMatcher.matches(request)) { if (!this.requestMatcher.matches(request)) {
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
return; return;
} }
@ -155,7 +155,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
private void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, private void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response,
AuthenticationException failed) throws IOException, ServletException { AuthenticationException failed) throws IOException, ServletException {
SecurityContextHolder.clearContext(); SecurityContextHolder.clearContext();
failureHandler.onAuthenticationFailure(request, response, failed); this.failureHandler.onAuthenticationFailure(request, response, failed);
} }
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
@ -163,18 +163,17 @@ public class AuthenticationFilter extends OncePerRequestFilter {
SecurityContext context = SecurityContextHolder.createEmptyContext(); SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication); context.setAuthentication(authentication);
SecurityContextHolder.setContext(context); SecurityContextHolder.setContext(context);
this.successHandler.onAuthenticationSuccess(request, response, chain, authentication);
successHandler.onAuthenticationSuccess(request, response, chain, authentication);
} }
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException { throws AuthenticationException, IOException, ServletException {
Authentication authentication = authenticationConverter.convert(request); Authentication authentication = this.authenticationConverter.convert(request);
if (authentication == null) { if (authentication == null) {
return null; return null;
} }
AuthenticationManager authenticationManager = authenticationManagerResolver.resolve(request); AuthenticationManager authenticationManager = this.authenticationManagerResolver.resolve(request);
Authentication authenticationResult = authenticationManager.authenticate(authentication); Authentication authenticationResult = authenticationManager.authenticate(authentication);
if (authenticationResult == null) { if (authenticationResult == null) {
throw new ServletException("AuthenticationManager should not return null Authentication object."); throw new ServletException("AuthenticationManager should not return null Authentication object.");