1616
1717package 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 ;
2819import org .springframework .security .web .authentication .AbstractAuthenticationProcessingFilter ;
29- import org .springframework .security .web .authentication .AuthenticationConverter ;
3020import 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}
0 commit comments