Skip to content

Commit

Permalink
Polish One-Time Token API Names and Doc
Browse files Browse the repository at this point in the history
The names of variables and methods have been adjusted in accordance with the names of the one-time token login API components.

Issue gh-15114
  • Loading branch information
franticticktick committed Oct 15, 2024
1 parent e44fec5 commit 814ab46
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3003,8 +3003,8 @@ public HttpSecurity oauth2ResourceServer(
* }
*
* @Bean
* public GeneratedOneTimeTokenHandler generatedOneTimeTokenHandler() {
* return new MyMagicLinkGeneratedOneTimeTokenHandler();
* public OneTimeTokenGenerationSuccessHandler oneTimeTokenGenerationSuccessHandler() {
* return new MyMagicLinkOneTimeTokenGenerationSuccessHandler();
* }
*
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ private SecurityContextRepository getSecurityContextRepository(H http) {

private void configureOttGenerateFilter(H http) {
GenerateOneTimeTokenFilter generateFilter = new GenerateOneTimeTokenFilter(getOneTimeTokenService(http),
getGeneratedOneTimeTokenHandler(http));
getOneTimeTokenGenerationSuccessHandler(http));
generateFilter.setRequestMatcher(antMatcher(HttpMethod.POST, this.tokenGeneratingUrl));
http.addFilter(postProcess(generateFilter));
http.addFilter(DefaultResourcesFilter.css());
}

private OneTimeTokenGenerationSuccessHandler getGeneratedOneTimeTokenHandler(H http) {
private OneTimeTokenGenerationSuccessHandler getOneTimeTokenGenerationSuccessHandler(H http) {
if (this.oneTimeTokenGenerationSuccessHandler == null) {
this.oneTimeTokenGenerationSuccessHandler = getBeanOrNull(http, OneTimeTokenGenerationSuccessHandler.class);
}
if (this.oneTimeTokenGenerationSuccessHandler == null) {
throw new IllegalStateException("""
A GeneratedOneTimeTokenHandler is required to enable oneTimeTokenLogin().
A OneTimeTokenGenerationSuccessHandler is required to enable oneTimeTokenLogin().
Please provide it as a bean or pass it to the oneTimeTokenLogin() DSL.
""");
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public OneTimeTokenLoginConfigurer<H> tokenGeneratingUrl(String tokenGeneratingU
*/
public OneTimeTokenLoginConfigurer<H> tokenGenerationSuccessHandler(
OneTimeTokenGenerationSuccessHandler oneTimeTokenGenerationSuccessHandler) {
Assert.notNull(oneTimeTokenGenerationSuccessHandler, "generatedOneTimeTokenHandler cannot be null");
Assert.notNull(oneTimeTokenGenerationSuccessHandler, "oneTimeTokenGenerationSuccessHandler cannot be null");
this.oneTimeTokenGenerationSuccessHandler = oneTimeTokenGenerationSuccessHandler;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,8 @@ public ServerHttpSecurity authenticationManager(ReactiveAuthenticationManager ma
* }
*
* &#064;Bean
* public ServerGeneratedOneTimeTokenHandler generatedOneTimeTokenHandler() {
* return new MyMagicLinkServerGeneratedOneTimeTokenHandler();
* public ServerOneTimeTokenGenerationSuccessHandler oneTimeTokenGenerationSuccessHandler() {
* return new MyMagicLinkServerOneTimeTokenGenerationSuccessHandler();
* }
*
* }
Expand Down Expand Up @@ -6151,12 +6151,12 @@ public OneTimeTokenLoginSpec defaultSubmitPageUrl(String submitPageUrl) {

/**
* Specifies strategy to be used to handle generated one-time tokens.
* @param generatedOneTimeTokenHandler
* @param oneTimeTokenGenerationSuccessHandler
*/
public OneTimeTokenLoginSpec tokenGenerationSuccessHandler(
ServerOneTimeTokenGenerationSuccessHandler generatedOneTimeTokenHandler) {
Assert.notNull(generatedOneTimeTokenHandler, "generatedOneTimeTokenHandler cannot be null");
this.tokenGenerationSuccessHandler = generatedOneTimeTokenHandler;
ServerOneTimeTokenGenerationSuccessHandler oneTimeTokenGenerationSuccessHandler) {
Assert.notNull(oneTimeTokenGenerationSuccessHandler, "oneTimeTokenGenerationSuccessHandler cannot be null");
this.tokenGenerationSuccessHandler = oneTimeTokenGenerationSuccessHandler;
return this;
}

Expand Down Expand Up @@ -6193,7 +6193,7 @@ private ServerOneTimeTokenGenerationSuccessHandler getTokenGenerationSuccessHand
}
if (this.tokenGenerationSuccessHandler == null) {
throw new IllegalStateException("""
A ServerGeneratedOneTimeTokenHandler is required to enable oneTimeTokenLogin().
A ServerOneTimeTokenGenerationSuccessHandler is required to enable oneTimeTokenLogin().
Please provide it as a bean or pass it to the oneTimeTokenLogin() DSL.
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ class HttpSecurityDsl(private val http: HttpSecurity, private val init: HttpSecu
* fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
* http {
* oneTimeTokenLogin {
* generatedOneTimeTokenHandler = MyMagicLinkGeneratedOneTimeTokenHandler()
* oneTimeTokenGenerationSuccessHandler = MyMagicLinkOneTimeTokenGenerationSuccessHandler()
* }
* }
* return http.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void oneTimeTokenWhenNoTokenGenerationSuccessHandlerThenException() {
.havingRootCause()
.isInstanceOf(IllegalStateException.class)
.withMessage("""
A GeneratedOneTimeTokenHandler is required to enable oneTimeTokenLogin().
A OneTimeTokenGenerationSuccessHandler is required to enable oneTimeTokenLogin().
Please provide it as a bean or pass it to the oneTimeTokenLogin() DSL.
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ void oneTimeTokenWhenFormLoginConfiguredThenRendersRequestTokenForm() {
}

@Test
void oneTimeTokenWhenNoGeneratedOneTimeTokenHandlerThenException() {
void oneTimeTokenWhenNoOneTimeTokenGenerationSuccessHandlerThenException() {
assertThatException()
.isThrownBy(() -> this.spring.register(OneTimeTokenNotGeneratedOttHandlerConfig.class).autowire())
.havingRootCause()
.isInstanceOf(IllegalStateException.class)
.withMessage("""
A ServerGeneratedOneTimeTokenHandler is required to enable oneTimeTokenLogin().
A ServerOneTimeTokenGenerationSuccessHandler is required to enable oneTimeTokenLogin().
Please provide it as a bean or pass it to the oneTimeTokenLogin() DSL.
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class OneTimeTokenLoginDslTests {
.redirectedUrl("/login/ott")
)

val token = TestGeneratedOneTimeTokenHandler.lastToken?.tokenValue
val token = TestOneTimeTokenGenerationSuccessHandler.lastToken?.tokenValue

this.mockMvc.perform(
MockMvcRequestBuilders.post("/login/ott").param("token", token)
Expand All @@ -91,7 +91,7 @@ class OneTimeTokenLoginDslTests {
)
.andExpectAll(MockMvcResultMatchers.status().isFound(), MockMvcResultMatchers.redirectedUrl("/redirected"))

val token = TestGeneratedOneTimeTokenHandler.lastToken?.tokenValue
val token = TestOneTimeTokenGenerationSuccessHandler.lastToken?.tokenValue

this.mockMvc.perform(
MockMvcRequestBuilders.post("/loginprocessingurl").param("token", token)
Expand All @@ -117,7 +117,7 @@ class OneTimeTokenLoginDslTests {
authorize(anyRequest, authenticated)
}
oneTimeTokenLogin {
oneTimeTokenGenerationSuccessHandler = TestGeneratedOneTimeTokenHandler()
oneTimeTokenGenerationSuccessHandler = TestOneTimeTokenGenerationSuccessHandler()
}
}
// @formatter:on
Expand All @@ -138,7 +138,7 @@ class OneTimeTokenLoginDslTests {
}
oneTimeTokenLogin {
tokenGeneratingUrl = "/generateurl"
oneTimeTokenGenerationSuccessHandler = TestGeneratedOneTimeTokenHandler("/redirected")
oneTimeTokenGenerationSuccessHandler = TestOneTimeTokenGenerationSuccessHandler("/redirected")
loginProcessingUrl = "/loginprocessingurl"
authenticationSuccessHandler = SimpleUrlAuthenticationSuccessHandler("/authenticated")
}
Expand All @@ -156,7 +156,7 @@ class OneTimeTokenLoginDslTests {
InMemoryUserDetailsManager(PasswordEncodedUser.user(), PasswordEncodedUser.admin())
}

private class TestGeneratedOneTimeTokenHandler :
private class TestOneTimeTokenGenerationSuccessHandler :
OneTimeTokenGenerationSuccessHandler {
private val delegate: OneTimeTokenGenerationSuccessHandler

Expand Down
Loading

0 comments on commit 814ab46

Please sign in to comment.