Require GeneratedOneTimeTokenHandler on constructor

Issue gh-15114
This commit is contained in:
Marcus Hert Da Coregio 2024-09-17 08:21:26 -03:00
parent 54d683fd6b
commit a88a7744ed
2 changed files with 8 additions and 16 deletions

View File

@ -133,8 +133,8 @@ public final class OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>
}
private void configureOttGenerateFilter(H http) {
GenerateOneTimeTokenFilter generateFilter = new GenerateOneTimeTokenFilter(getOneTimeTokenService(http));
generateFilter.setGeneratedOneTimeTokenHandler(getGeneratedOneTimeTokenHandler(http));
GenerateOneTimeTokenFilter generateFilter = new GenerateOneTimeTokenFilter(getOneTimeTokenService(http),
getGeneratedOneTimeTokenHandler(http));
generateFilter.setRequestMatcher(antMatcher(HttpMethod.POST, this.generateTokenUrl));
http.addFilter(postProcess(generateFilter));
http.addFilter(DefaultResourcesFilter.css());

View File

@ -45,14 +45,16 @@ public final class GenerateOneTimeTokenFilter extends OncePerRequestFilter {
private final OneTimeTokenService oneTimeTokenService;
private final GeneratedOneTimeTokenHandler generatedOneTimeTokenHandler;
private RequestMatcher requestMatcher = antMatcher(HttpMethod.POST, "/ott/generate");
private GeneratedOneTimeTokenHandler generatedOneTimeTokenHandler = new RedirectGeneratedOneTimeTokenHandler(
"/login/ott");
public GenerateOneTimeTokenFilter(OneTimeTokenService oneTimeTokenService) {
public GenerateOneTimeTokenFilter(OneTimeTokenService oneTimeTokenService,
GeneratedOneTimeTokenHandler generatedOneTimeTokenHandler) {
Assert.notNull(oneTimeTokenService, "oneTimeTokenService cannot be null");
Assert.notNull(generatedOneTimeTokenHandler, "generatedOneTimeTokenHandler cannot be null");
this.oneTimeTokenService = oneTimeTokenService;
this.generatedOneTimeTokenHandler = generatedOneTimeTokenHandler;
}
@Override
@ -81,14 +83,4 @@ public final class GenerateOneTimeTokenFilter extends OncePerRequestFilter {
this.requestMatcher = requestMatcher;
}
/**
* Specifies {@link GeneratedOneTimeTokenHandler} to be used to handle generated
* one-time tokens
* @param generatedOneTimeTokenHandler
*/
public void setGeneratedOneTimeTokenHandler(GeneratedOneTimeTokenHandler generatedOneTimeTokenHandler) {
Assert.notNull(generatedOneTimeTokenHandler, "generatedOneTimeTokenHandler cannot be null");
this.generatedOneTimeTokenHandler = generatedOneTimeTokenHandler;
}
}