Skip to content

Commit 861a9a9

Browse files
committed
OneTimeToken Missing Token Propagates Request
Closes gh-16780
1 parent 8199015 commit 861a9a9

File tree

2 files changed

+5
-38
lines changed

2 files changed

+5
-38
lines changed

web/src/main/java/org/springframework/security/web/authentication/ott/OneTimeTokenAuthenticationFilter.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,8 @@
1616

1717
package org.springframework.security.web.authentication.ott;
1818

19-
import java.io.IOException;
20-
21-
import jakarta.servlet.ServletException;
22-
import jakarta.servlet.http.HttpServletRequest;
23-
import jakarta.servlet.http.HttpServletResponse;
24-
25-
import org.springframework.security.authentication.BadCredentialsException;
26-
import org.springframework.security.core.Authentication;
27-
import org.springframework.security.core.AuthenticationException;
2819
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
29-
import org.springframework.security.web.authentication.AuthenticationConverter;
3020
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
31-
import org.springframework.util.Assert;
3221

3322
/**
3423
* Filter that processes a one-time token for log in.
@@ -43,31 +32,9 @@ public final class OneTimeTokenAuthenticationFilter extends AbstractAuthenticati
4332

4433
public static final String DEFAULT_LOGIN_PROCESSING_URL = "/login/ott";
4534

46-
private AuthenticationConverter authenticationConverter = new OneTimeTokenAuthenticationConverter();
47-
4835
public OneTimeTokenAuthenticationFilter() {
4936
super(new AntPathRequestMatcher(DEFAULT_LOGIN_PROCESSING_URL, "POST"));
50-
}
51-
52-
@Override
53-
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
54-
throws AuthenticationException, IOException, ServletException {
55-
Authentication authentication = this.authenticationConverter.convert(request);
56-
if (authentication == null) {
57-
throw new BadCredentialsException("Unable to authenticate with the one-time token");
58-
}
59-
return getAuthenticationManager().authenticate(authentication);
60-
}
61-
62-
/**
63-
* Use this {@link AuthenticationConverter} when converting incoming requests to an
64-
* {@link Authentication}. By default, the {@link OneTimeTokenAuthenticationConverter}
65-
* is used.
66-
* @param authenticationConverter the {@link AuthenticationConverter} to use
67-
*/
68-
public void setAuthenticationConverter(AuthenticationConverter authenticationConverter) {
69-
Assert.notNull(authenticationConverter, "authenticationConverter cannot be null");
70-
this.authenticationConverter = authenticationConverter;
37+
setAuthenticationConverter(new OneTimeTokenAuthenticationConverter());
7138
}
7239

7340
}

web/src/test/java/org/springframework/security/web/authentication/ott/OneTimeTokenAuthenticationFilterTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOEx
9595
}
9696

9797
@Test
98-
void doFilterWhenMissingTokenThenUnauthorized() throws ServletException, IOException {
99-
this.filter.doFilter(post("/login/ott").buildRequest(new MockServletContext()), this.response, this.chain);
100-
assertThat(this.response.getStatus()).isEqualTo(HttpStatus.UNAUTHORIZED.value());
101-
verifyNoInteractions(this.chain);
98+
void doFilterWhenMissingTokenThenPropagatesRequest() throws ServletException, IOException {
99+
FilterChain chain = mock(FilterChain.class);
100+
this.filter.doFilter(post("/login/ott").buildRequest(new MockServletContext()), this.response, chain);
101+
verify(chain).doFilter(any(), any());
102102
}
103103

104104
@Test

0 commit comments

Comments
 (0)