use of org.springframework.security.authentication.RememberMeAuthenticationToken in project spring-security by spring-projects.
the class AbstractRememberMeServices method createSuccessfulAuthentication.
/**
* Creates the final <tt>Authentication</tt> object returned from the
* <tt>autoLogin</tt> method.
* <p>
* By default it will create a <tt>RememberMeAuthenticationToken</tt> instance.
*
* @param request the original request. The configured
* <tt>AuthenticationDetailsSource</tt> will use this to build the details property of
* the returned object.
* @param user the <tt>UserDetails</tt> loaded from the <tt>UserDetailsService</tt>.
* This will be stored as the principal.
*
* @return the <tt>Authentication</tt> for the remember-me authenticated user
*/
protected Authentication createSuccessfulAuthentication(HttpServletRequest request, UserDetails user) {
RememberMeAuthenticationToken auth = new RememberMeAuthenticationToken(key, user, authoritiesMapper.mapAuthorities(user.getAuthorities()));
auth.setDetails(authenticationDetailsSource.buildDetails(request));
return auth;
}
use of org.springframework.security.authentication.RememberMeAuthenticationToken in project spring-security by spring-projects.
the class RememberMeAuthenticationTokenMixinTests method serializeRememberMeAuthenticationWithUserToken.
@Test
public void serializeRememberMeAuthenticationWithUserToken() throws JsonProcessingException, JSONException {
User user = createDefaultUser();
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken(REMEMBERME_KEY, user, user.getAuthorities());
String actualJson = mapper.writeValueAsString(token);
JSONAssert.assertEquals(String.format(REMEMBERME_AUTH_JSON, "\"password\""), actualJson, true);
}
use of org.springframework.security.authentication.RememberMeAuthenticationToken in project spring-security by spring-projects.
the class RememberMeAuthenticationTokenMixinTests method deserializeRememberMeAuthenticationToken.
@Test
public void deserializeRememberMeAuthenticationToken() throws IOException {
RememberMeAuthenticationToken token = mapper.readValue(REMEMBERME_AUTH_STRINGPRINCIPAL_JSON, RememberMeAuthenticationToken.class);
assertThat(token).isNotNull();
assertThat(token.getPrincipal()).isNotNull().isEqualTo("admin").isEqualTo(token.getName());
assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
}
use of org.springframework.security.authentication.RememberMeAuthenticationToken in project spring-security by spring-projects.
the class RememberMeAuthenticationTokenMixinTests method serializeRememberMeAuthenticationWithUserTokenAfterEraseCredential.
@Test
public void serializeRememberMeAuthenticationWithUserTokenAfterEraseCredential() throws JsonProcessingException, JSONException {
User user = createDefaultUser();
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken(REMEMBERME_KEY, user, user.getAuthorities());
token.eraseCredentials();
String actualJson = mapper.writeValueAsString(token);
JSONAssert.assertEquals(REMEMBERME_AUTH_JSON.replace(UserDeserializerTests.USER_PASSWORD, "null"), actualJson, true);
}
use of org.springframework.security.authentication.RememberMeAuthenticationToken in project spring-security by spring-projects.
the class RememberMeAuthenticationProviderTests method testNormalOperation.
@Test
public void testNormalOperation() throws Exception {
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("qwerty", "Test", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
Authentication result = aap.authenticate(token);
assertThat(token).isEqualTo(result);
}
Aggregations