use of org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken in project spring-security by spring-projects.
the class PersistentTokenBasedRememberMeServicesTests method successfulAutoLoginCreatesNewTokenAndCookieWithSameSeries.
@Test
public void successfulAutoLoginCreatesNewTokenAndCookieWithSameSeries() {
services = create(new PersistentRememberMeToken("joe", "series", "token", new Date()));
// 12 => b64 length will be 16
services.setTokenLength(12);
MockHttpServletResponse response = new MockHttpServletResponse();
services.processAutoLoginCookie(new String[] { "series", "token" }, new MockHttpServletRequest(), response);
assertThat(repo.getStoredToken().getSeries()).isEqualTo("series");
assertThat(repo.getStoredToken().getTokenValue().length()).isEqualTo(16);
String[] cookie = services.decodeCookie(response.getCookie("mycookiename").getValue());
assertThat(cookie[0]).isEqualTo("series");
assertThat(cookie[1]).isEqualTo(repo.getStoredToken().getTokenValue());
}
use of org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken in project spring-security by spring-projects.
the class PersistentTokenBasedRememberMeServicesTests method logoutClearsUsersTokenAndCookie.
@Test
public void logoutClearsUsersTokenAndCookie() throws Exception {
Cookie cookie = new Cookie("mycookiename", "somevalue");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setCookies(cookie);
MockHttpServletResponse response = new MockHttpServletResponse();
services = create(new PersistentRememberMeToken("joe", "series", "token", new Date()));
services.logout(request, response, new TestingAuthenticationToken("joe", "somepass", "SOME_AUTH"));
Cookie returnedCookie = response.getCookie("mycookiename");
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
// SEC-1280
services.logout(request, response, null);
}
use of org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken in project spring-security by spring-projects.
the class PersistentTokenBasedRememberMeServicesTests method cookieTheftIsDetectedWhenSeriesAndTokenDontMatch.
@Test(expected = CookieTheftException.class)
public void cookieTheftIsDetectedWhenSeriesAndTokenDontMatch() {
services = create(new PersistentRememberMeToken("joe", "series", "wrongtoken", new Date()));
services.processAutoLoginCookie(new String[] { "series", "token" }, new MockHttpServletRequest(), new MockHttpServletResponse());
}
use of org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken in project spring-security by spring-projects.
the class PersistentTokenBasedRememberMeServicesTests method loginIsRejectedWhenTokenIsExpired.
@Test(expected = RememberMeAuthenticationException.class)
public void loginIsRejectedWhenTokenIsExpired() {
services = create(new PersistentRememberMeToken("joe", "series", "token", new Date(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(1) - 100)));
services.setTokenValiditySeconds(1);
services.processAutoLoginCookie(new String[] { "series", "token" }, new MockHttpServletRequest(), new MockHttpServletResponse());
}
use of org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken in project google-app-engine-jappstart by taylorleese.
the class PersistentTokenRepositoryImpl method getTokenForSeries.
/**
* Gets the token for the given series.
*
* @param series the series
* @return the remember me token
*/
@Override
public final PersistentRememberMeToken getTokenForSeries(final String series) {
PersistentLogin persistentLogin = null;
final Query query = entityManager.createQuery("SELECT p FROM PersistentLogin p WHERE series = :series");
query.setParameter("series", series);
try {
persistentLogin = (PersistentLogin) query.getSingleResult();
} catch (NoResultException e) {
return null;
}
return new PersistentRememberMeToken(persistentLogin.getUsername(), persistentLogin.getSeries(), persistentLogin.getToken(), persistentLogin.getLastUsed());
}
Aggregations