|
@@ -72,7 +72,7 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
this.mvc.perform(post("/ott/generate").param("username", "user").with(csrf()))
|
|
this.mvc.perform(post("/ott/generate").param("username", "user").with(csrf()))
|
|
.andExpectAll(status().isFound(), redirectedUrl("/login/ott"));
|
|
.andExpectAll(status().isFound(), redirectedUrl("/login/ott"));
|
|
|
|
|
|
- String token = TestOneTimeTokenGenerationSuccessHandler.lastToken.getTokenValue();
|
|
|
|
|
|
+ String token = getLastToken().getTokenValue();
|
|
|
|
|
|
this.mvc.perform(post("/login/ott").param("token", token).with(csrf()))
|
|
this.mvc.perform(post("/login/ott").param("token", token).with(csrf()))
|
|
.andExpectAll(status().isFound(), redirectedUrl("/"), authenticated());
|
|
.andExpectAll(status().isFound(), redirectedUrl("/"), authenticated());
|
|
@@ -84,7 +84,7 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
this.mvc.perform(post("/generateurl").param("username", "user").with(csrf()))
|
|
this.mvc.perform(post("/generateurl").param("username", "user").with(csrf()))
|
|
.andExpectAll(status().isFound(), redirectedUrl("/redirected"));
|
|
.andExpectAll(status().isFound(), redirectedUrl("/redirected"));
|
|
|
|
|
|
- String token = TestOneTimeTokenGenerationSuccessHandler.lastToken.getTokenValue();
|
|
|
|
|
|
+ String token = getLastToken().getTokenValue();
|
|
|
|
|
|
this.mvc.perform(post("/loginprocessingurl").param("token", token).with(csrf()))
|
|
this.mvc.perform(post("/loginprocessingurl").param("token", token).with(csrf()))
|
|
.andExpectAll(status().isFound(), redirectedUrl("/authenticated"), authenticated());
|
|
.andExpectAll(status().isFound(), redirectedUrl("/authenticated"), authenticated());
|
|
@@ -96,7 +96,7 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
this.mvc.perform(post("/ott/generate").param("username", "user").with(csrf()))
|
|
this.mvc.perform(post("/ott/generate").param("username", "user").with(csrf()))
|
|
.andExpectAll(status().isFound(), redirectedUrl("/login/ott"));
|
|
.andExpectAll(status().isFound(), redirectedUrl("/login/ott"));
|
|
|
|
|
|
- String token = TestOneTimeTokenGenerationSuccessHandler.lastToken.getTokenValue();
|
|
|
|
|
|
+ String token = getLastToken().getTokenValue();
|
|
|
|
|
|
this.mvc.perform(post("/login/ott").param("token", token).with(csrf()))
|
|
this.mvc.perform(post("/login/ott").param("token", token).with(csrf()))
|
|
.andExpectAll(status().isFound(), redirectedUrl("/"), authenticated());
|
|
.andExpectAll(status().isFound(), redirectedUrl("/"), authenticated());
|
|
@@ -194,25 +194,37 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
""");
|
|
""");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private OneTimeToken getLastToken() {
|
|
|
|
+ OneTimeToken lastToken = this.spring.getContext()
|
|
|
|
+ .getBean(TestOneTimeTokenGenerationSuccessHandler.class).lastToken;
|
|
|
|
+ return lastToken;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Configuration(proxyBeanMethods = false)
|
|
@Configuration(proxyBeanMethods = false)
|
|
@EnableWebSecurity
|
|
@EnableWebSecurity
|
|
@Import(UserDetailsServiceConfig.class)
|
|
@Import(UserDetailsServiceConfig.class)
|
|
static class OneTimeTokenDefaultConfig {
|
|
static class OneTimeTokenDefaultConfig {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
- SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
|
|
+ SecurityFilterChain securityFilterChain(HttpSecurity http,
|
|
|
|
+ OneTimeTokenGenerationSuccessHandler ottSuccessHandler) throws Exception {
|
|
// @formatter:off
|
|
// @formatter:off
|
|
http
|
|
http
|
|
.authorizeHttpRequests((authz) -> authz
|
|
.authorizeHttpRequests((authz) -> authz
|
|
.anyRequest().authenticated()
|
|
.anyRequest().authenticated()
|
|
)
|
|
)
|
|
.oneTimeTokenLogin((ott) -> ott
|
|
.oneTimeTokenLogin((ott) -> ott
|
|
- .tokenGenerationSuccessHandler(new TestOneTimeTokenGenerationSuccessHandler())
|
|
|
|
|
|
+ .tokenGenerationSuccessHandler(ottSuccessHandler)
|
|
);
|
|
);
|
|
// @formatter:on
|
|
// @formatter:on
|
|
return http.build();
|
|
return http.build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Bean
|
|
|
|
+ TestOneTimeTokenGenerationSuccessHandler ottSuccessHandler() {
|
|
|
|
+ return new TestOneTimeTokenGenerationSuccessHandler();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
@Configuration(proxyBeanMethods = false)
|
|
@@ -221,7 +233,8 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
static class OneTimeTokenDifferentUrlsConfig {
|
|
static class OneTimeTokenDifferentUrlsConfig {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
- SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
|
|
+ SecurityFilterChain securityFilterChain(HttpSecurity http,
|
|
|
|
+ OneTimeTokenGenerationSuccessHandler ottSuccessHandler) throws Exception {
|
|
// @formatter:off
|
|
// @formatter:off
|
|
http
|
|
http
|
|
.authorizeHttpRequests((authz) -> authz
|
|
.authorizeHttpRequests((authz) -> authz
|
|
@@ -229,7 +242,7 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
)
|
|
)
|
|
.oneTimeTokenLogin((ott) -> ott
|
|
.oneTimeTokenLogin((ott) -> ott
|
|
.tokenGeneratingUrl("/generateurl")
|
|
.tokenGeneratingUrl("/generateurl")
|
|
- .tokenGenerationSuccessHandler(new TestOneTimeTokenGenerationSuccessHandler("/redirected"))
|
|
|
|
|
|
+ .tokenGenerationSuccessHandler(ottSuccessHandler)
|
|
.loginProcessingUrl("/loginprocessingurl")
|
|
.loginProcessingUrl("/loginprocessingurl")
|
|
.authenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler("/authenticated"))
|
|
.authenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler("/authenticated"))
|
|
);
|
|
);
|
|
@@ -237,6 +250,11 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
return http.build();
|
|
return http.build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Bean
|
|
|
|
+ TestOneTimeTokenGenerationSuccessHandler ottSuccessHandler() {
|
|
|
|
+ return new TestOneTimeTokenGenerationSuccessHandler("/redirected");
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
@Configuration(proxyBeanMethods = false)
|
|
@@ -245,7 +263,8 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
static class OneTimeTokenFormLoginConfig {
|
|
static class OneTimeTokenFormLoginConfig {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
- SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
|
|
+ SecurityFilterChain securityFilterChain(HttpSecurity http,
|
|
|
|
+ OneTimeTokenGenerationSuccessHandler ottSuccessHandler) throws Exception {
|
|
// @formatter:off
|
|
// @formatter:off
|
|
http
|
|
http
|
|
.authorizeHttpRequests((authz) -> authz
|
|
.authorizeHttpRequests((authz) -> authz
|
|
@@ -253,12 +272,17 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
)
|
|
)
|
|
.formLogin(Customizer.withDefaults())
|
|
.formLogin(Customizer.withDefaults())
|
|
.oneTimeTokenLogin((ott) -> ott
|
|
.oneTimeTokenLogin((ott) -> ott
|
|
- .tokenGenerationSuccessHandler(new TestOneTimeTokenGenerationSuccessHandler())
|
|
|
|
|
|
+ .tokenGenerationSuccessHandler(ottSuccessHandler)
|
|
);
|
|
);
|
|
// @formatter:on
|
|
// @formatter:on
|
|
return http.build();
|
|
return http.build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Bean
|
|
|
|
+ TestOneTimeTokenGenerationSuccessHandler ottSuccessHandler() {
|
|
|
|
+ return new TestOneTimeTokenGenerationSuccessHandler();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
@Configuration(proxyBeanMethods = false)
|
|
@@ -282,7 +306,7 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
|
|
|
|
static class TestOneTimeTokenGenerationSuccessHandler implements OneTimeTokenGenerationSuccessHandler {
|
|
static class TestOneTimeTokenGenerationSuccessHandler implements OneTimeTokenGenerationSuccessHandler {
|
|
|
|
|
|
- private static OneTimeToken lastToken;
|
|
|
|
|
|
+ private OneTimeToken lastToken;
|
|
|
|
|
|
private final OneTimeTokenGenerationSuccessHandler delegate;
|
|
private final OneTimeTokenGenerationSuccessHandler delegate;
|
|
|
|
|
|
@@ -297,7 +321,7 @@ public class OneTimeTokenLoginConfigurerTests {
|
|
@Override
|
|
@Override
|
|
public void handle(HttpServletRequest request, HttpServletResponse response, OneTimeToken oneTimeToken)
|
|
public void handle(HttpServletRequest request, HttpServletResponse response, OneTimeToken oneTimeToken)
|
|
throws IOException, ServletException {
|
|
throws IOException, ServletException {
|
|
- lastToken = oneTimeToken;
|
|
|
|
|
|
+ this.lastToken = oneTimeToken;
|
|
this.delegate.handle(request, response, oneTimeToken);
|
|
this.delegate.handle(request, response, oneTimeToken);
|
|
}
|
|
}
|
|
|
|
|