Skip to content
This repository was archived by the owner on Nov 11, 2019. It is now read-only.

Commit 4fa65ca

Browse files
committed
Append test case for fallback key configuration
1 parent 8fd1b6f commit 4fa65ca

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/configurers/RememberMeConfigurerTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
3737
import org.springframework.security.web.authentication.RememberMeServices;
3838
import org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter;
39+
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
3940
import org.springframework.test.web.servlet.MockMvc;
4041
import org.springframework.test.web.servlet.MvcResult;
4142

@@ -453,4 +454,35 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
453454
// @formatter:on
454455
}
455456
}
457+
458+
@Test
459+
public void getWhenRememberMeCookieThenAuthenticationIsRememberMeAuthenticationTokenWithFallbackKeyConfiguration()
460+
throws Exception {
461+
this.spring.register(FallbackRememberMeKeyConfig.class).autowire();
462+
463+
MvcResult mvcResult = this.mvc.perform(post("/login")
464+
.with(csrf())
465+
.param("username", "user")
466+
.param("password", "password")
467+
.param("remember-me", "true"))
468+
.andReturn();
469+
Cookie rememberMeCookie = mvcResult.getResponse().getCookie("remember-me");
470+
471+
this.mvc.perform(get("/abc")
472+
.cookie(rememberMeCookie))
473+
.andExpect(authenticated().withAuthentication(auth ->
474+
assertThat(auth).isInstanceOf(RememberMeAuthenticationToken.class)));
475+
}
476+
477+
@EnableWebSecurity
478+
static class FallbackRememberMeKeyConfig extends RememberMeConfig {
479+
480+
@Override
481+
protected void configure(HttpSecurity http) throws Exception {
482+
// @formatter:off
483+
http.rememberMe()
484+
.rememberMeServices(new TokenBasedRememberMeServices("key", userDetailsService()));
485+
// @formatter:on
486+
}
487+
}
456488
}

0 commit comments

Comments
 (0)