1
0
mirror of synced 2026-08-05 17:57:15 +00:00

Polish One-Time Token Component Names

Aligning parts of speech so that names are using nouns/verbs
where comparable components are using nouns/verbs.

Issue gh-15114
This commit is contained in:
Josh Cummings
2024-10-14 13:58:23 -06:00
parent b8aa78829c
commit c40334317d
19 changed files with 158 additions and 142 deletions
@@ -43,18 +43,18 @@ import static org.springframework.security.web.util.matcher.AntPathRequestMatche
*/
public final class GenerateOneTimeTokenFilter extends OncePerRequestFilter {
private final OneTimeTokenService oneTimeTokenService;
private final OneTimeTokenService tokenService;
private final GeneratedOneTimeTokenHandler generatedOneTimeTokenHandler;
private final OneTimeTokenGenerationSuccessHandler tokenGenerationSuccessHandler;
private RequestMatcher requestMatcher = antMatcher(HttpMethod.POST, "/ott/generate");
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;
public GenerateOneTimeTokenFilter(OneTimeTokenService tokenService,
OneTimeTokenGenerationSuccessHandler tokenGenerationSuccessHandler) {
Assert.notNull(tokenService, "tokenService cannot be null");
Assert.notNull(tokenGenerationSuccessHandler, "tokenGenerationSuccessHandler cannot be null");
this.tokenService = tokenService;
this.tokenGenerationSuccessHandler = tokenGenerationSuccessHandler;
}
@Override
@@ -70,8 +70,8 @@ public final class GenerateOneTimeTokenFilter extends OncePerRequestFilter {
return;
}
GenerateOneTimeTokenRequest generateRequest = new GenerateOneTimeTokenRequest(username);
OneTimeToken ott = this.oneTimeTokenService.generate(generateRequest);
this.generatedOneTimeTokenHandler.handle(request, response, ott);
OneTimeToken ott = this.tokenService.generate(generateRequest);
this.tokenGenerationSuccessHandler.handle(request, response, ott);
}
/**
@@ -31,7 +31,7 @@ import org.springframework.security.authentication.ott.OneTimeToken;
* @since 6.4
*/
@FunctionalInterface
public interface GeneratedOneTimeTokenHandler {
public interface OneTimeTokenGenerationSuccessHandler {
/**
* Handles generated one-time tokens
@@ -27,12 +27,13 @@ import org.springframework.security.web.RedirectStrategy;
import org.springframework.util.Assert;
/**
* A {@link GeneratedOneTimeTokenHandler} that performs a redirect to a specific location
* A {@link OneTimeTokenGenerationSuccessHandler} that performs a redirect to a specific
* location
*
* @author Marcus da Coregio
* @since 6.4
*/
public final class RedirectGeneratedOneTimeTokenHandler implements GeneratedOneTimeTokenHandler {
public final class RedirectOneTimeTokenGenerationSuccessHandler implements OneTimeTokenGenerationSuccessHandler {
private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@@ -42,7 +43,7 @@ public final class RedirectGeneratedOneTimeTokenHandler implements GeneratedOneT
* Constructs an instance of this class that redirects to the specified URL.
* @param redirectUrl
*/
public RedirectGeneratedOneTimeTokenHandler(String redirectUrl) {
public RedirectOneTimeTokenGenerationSuccessHandler(String redirectUrl) {
Assert.hasText(redirectUrl, "redirectUrl cannot be empty or null");
this.redirectUrl = redirectUrl;
}
@@ -157,7 +157,7 @@ public class DefaultLoginPageGeneratingFilter extends GenericFilterBean {
this.authenticationUrl = authenticationUrl;
}
public void setGenerateOneTimeTokenUrl(String generateOneTimeTokenUrl) {
public void setOneTimeTokenGenerationUrl(String generateOneTimeTokenUrl) {
this.generateOneTimeTokenUrl = generateOneTimeTokenUrl;
}
@@ -43,10 +43,10 @@ public final class GenerateOneTimeTokenWebFilter implements WebFilter {
private ServerWebExchangeMatcher matcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, "/ott/generate");
private final ServerGeneratedOneTimeTokenHandler generatedOneTimeTokenHandler;
private final ServerOneTimeTokenGenerationSuccessHandler generatedOneTimeTokenHandler;
public GenerateOneTimeTokenWebFilter(ReactiveOneTimeTokenService oneTimeTokenService,
ServerGeneratedOneTimeTokenHandler generatedOneTimeTokenHandler) {
ServerOneTimeTokenGenerationSuccessHandler generatedOneTimeTokenHandler) {
Assert.notNull(generatedOneTimeTokenHandler, "generatedOneTimeTokenHandler cannot be null");
Assert.notNull(oneTimeTokenService, "oneTimeTokenService cannot be null");
this.generatedOneTimeTokenHandler = generatedOneTimeTokenHandler;
@@ -28,7 +28,7 @@ import org.springframework.web.server.ServerWebExchange;
* @since 6.4
*/
@FunctionalInterface
public interface ServerGeneratedOneTimeTokenHandler {
public interface ServerOneTimeTokenGenerationSuccessHandler {
/**
* Handles generated one-time tokens
@@ -27,19 +27,20 @@ import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
/**
* A {@link ServerGeneratedOneTimeTokenHandler} that performs a redirect to a specific
* location
* A {@link ServerOneTimeTokenGenerationSuccessHandler} that performs a redirect to a
* specific location
*
* @author Max Batischev
* @since 6.4
*/
public final class ServerRedirectGeneratedOneTimeTokenHandler implements ServerGeneratedOneTimeTokenHandler {
public final class ServerRedirectOneTimeTokenGenerationSuccessHandler
implements ServerOneTimeTokenGenerationSuccessHandler {
private final ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy();
private final URI redirectUri;
public ServerRedirectGeneratedOneTimeTokenHandler(String redirectUri) {
public ServerRedirectOneTimeTokenGenerationSuccessHandler(String redirectUri) {
Assert.hasText(redirectUri, "redirectUri cannot be empty or null");
this.redirectUri = URI.create(redirectUri);
}
@@ -192,7 +192,7 @@ public class DefaultLoginPageGeneratingFilterTests {
DefaultLoginPageGeneratingFilter filter = new DefaultLoginPageGeneratingFilter();
filter.setLoginPageUrl(DefaultLoginPageGeneratingFilter.DEFAULT_LOGIN_PAGE_URL);
filter.setOneTimeTokenEnabled(true);
filter.setGenerateOneTimeTokenUrl("/ott/authenticate");
filter.setOneTimeTokenGenerationUrl("/ott/authenticate");
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(new MockHttpServletRequest("GET", "/login"), response, this.chain);
assertThat(response.getContentAsString()).contains("Request a One-Time Token");
@@ -29,15 +29,16 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link RedirectGeneratedOneTimeTokenHandler}
* Tests for {@link RedirectOneTimeTokenGenerationSuccessHandler}
*
* @author Marcus da Coregio
*/
class RedirectGeneratedOneTimeTokenHandlerTests {
class RedirectOneTimeTokenGenerationSuccessHandlerTests {
@Test
void handleThenRedirectToDefaultLocation() throws IOException {
RedirectGeneratedOneTimeTokenHandler handler = new RedirectGeneratedOneTimeTokenHandler("/login/ott");
RedirectOneTimeTokenGenerationSuccessHandler handler = new RedirectOneTimeTokenGenerationSuccessHandler(
"/login/ott");
MockHttpServletResponse response = new MockHttpServletResponse();
handler.handle(new MockHttpServletRequest(), response, new DefaultOneTimeToken("token", "user", Instant.now()));
assertThat(response.getRedirectedUrl()).isEqualTo("/login/ott");
@@ -46,16 +47,17 @@ class RedirectGeneratedOneTimeTokenHandlerTests {
@Test
void handleWhenUrlChangedThenRedirectToUrl() throws IOException {
MockHttpServletResponse response = new MockHttpServletResponse();
RedirectGeneratedOneTimeTokenHandler handler = new RedirectGeneratedOneTimeTokenHandler("/redirected");
RedirectOneTimeTokenGenerationSuccessHandler handler = new RedirectOneTimeTokenGenerationSuccessHandler(
"/redirected");
handler.handle(new MockHttpServletRequest(), response, new DefaultOneTimeToken("token", "user", Instant.now()));
assertThat(response.getRedirectedUrl()).isEqualTo("/redirected");
}
@Test
void setRedirectUrlWhenNullOrEmptyThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> new RedirectGeneratedOneTimeTokenHandler(null))
assertThatIllegalArgumentException().isThrownBy(() -> new RedirectOneTimeTokenGenerationSuccessHandler(null))
.withMessage("redirectUrl cannot be empty or null");
assertThatIllegalArgumentException().isThrownBy(() -> new RedirectGeneratedOneTimeTokenHandler(""))
assertThatIllegalArgumentException().isThrownBy(() -> new RedirectOneTimeTokenGenerationSuccessHandler(""))
.withMessage("redirectUrl cannot be empty or null");
}
@@ -45,7 +45,7 @@ public class GenerateOneTimeTokenWebFilterTests {
private final ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
private final ServerRedirectGeneratedOneTimeTokenHandler generatedOneTimeTokenHandler = new ServerRedirectGeneratedOneTimeTokenHandler(
private final ServerRedirectOneTimeTokenGenerationSuccessHandler generatedOneTimeTokenHandler = new ServerRedirectOneTimeTokenGenerationSuccessHandler(
"/login/ott");
private static final String TOKEN = "token";
@@ -29,11 +29,11 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link ServerRedirectGeneratedOneTimeTokenHandler}
* Tests for {@link ServerRedirectOneTimeTokenGenerationSuccessHandler}
*
* @author Max Batischev
*/
public class ServerRedirectGeneratedOneTimeTokenHandlerTests {
public class ServerRedirectOneTimeTokenGenerationSuccessHandlerTests {
private static final String TOKEN = "token";
@@ -43,7 +43,8 @@ public class ServerRedirectGeneratedOneTimeTokenHandlerTests {
@Test
void handleThenRedirectToDefaultLocation() {
ServerGeneratedOneTimeTokenHandler handler = new ServerRedirectGeneratedOneTimeTokenHandler("/login/ott");
ServerOneTimeTokenGenerationSuccessHandler handler = new ServerRedirectOneTimeTokenGenerationSuccessHandler(
"/login/ott");
MockServerWebExchange webExchange = MockServerWebExchange.from(this.request);
handler.handle(webExchange, new DefaultOneTimeToken(TOKEN, USERNAME, Instant.now())).block();
@@ -54,7 +55,8 @@ public class ServerRedirectGeneratedOneTimeTokenHandlerTests {
@Test
void handleWhenUrlChangedThenRedirectToUrl() {
ServerGeneratedOneTimeTokenHandler handler = new ServerRedirectGeneratedOneTimeTokenHandler("/redirected");
ServerOneTimeTokenGenerationSuccessHandler handler = new ServerRedirectOneTimeTokenGenerationSuccessHandler(
"/redirected");
MockServerWebExchange webExchange = MockServerWebExchange.from(this.request);
handler.handle(webExchange, new DefaultOneTimeToken(TOKEN, USERNAME, Instant.now())).block();
@@ -65,9 +67,11 @@ public class ServerRedirectGeneratedOneTimeTokenHandlerTests {
@Test
void setRedirectUrlWhenNullOrEmptyThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> new ServerRedirectGeneratedOneTimeTokenHandler(null))
assertThatIllegalArgumentException()
.isThrownBy(() -> new ServerRedirectOneTimeTokenGenerationSuccessHandler(null))
.withMessage("redirectUri cannot be empty or null");
assertThatIllegalArgumentException().isThrownBy(() -> new ServerRedirectGeneratedOneTimeTokenHandler(""))
assertThatIllegalArgumentException()
.isThrownBy(() -> new ServerRedirectOneTimeTokenGenerationSuccessHandler(""))
.withMessage("redirectUri cannot be empty or null");
}