Search in sources :

Example 11 with User

use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.

the class UsernamePasswordAuthenticationTokenMixinTests method createToken.

private UsernamePasswordAuthenticationToken createToken() {
    User user = createDefaultUser();
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities());
    return token;
}
Also used : User(org.springframework.security.core.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 12 with User

use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.

the class UsernamePasswordAuthenticationTokenMixinTests method serializeAuthenticatedUsernamePasswordAuthenticationTokenMixinTest.

@Test
public void serializeAuthenticatedUsernamePasswordAuthenticationTokenMixinTest() throws JsonProcessingException, JSONException {
    User user = createDefaultUser();
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword(), user.getAuthorities());
    String serializedJson = mapper.writeValueAsString(token);
    JSONAssert.assertEquals(AUTHENTICATED_STRINGPRINCIPAL_JSON, serializedJson, true);
}
Also used : User(org.springframework.security.core.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 13 with User

use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.

the class AnonymousAuthenticationTokenMixinTests method serializeAnonymousAuthenticationTokenTest.

// @formatter:on
@Test
public void serializeAnonymousAuthenticationTokenTest() throws JsonProcessingException, JSONException {
    User user = createDefaultUser();
    AnonymousAuthenticationToken token = new AnonymousAuthenticationToken(HASH_KEY, user, user.getAuthorities());
    String actualJson = mapper.writeValueAsString(token);
    JSONAssert.assertEquals(ANONYMOUS_JSON, actualJson, true);
}
Also used : User(org.springframework.security.core.userdetails.User) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Test(org.junit.Test)

Example 14 with User

use of org.springframework.security.core.userdetails.User 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);
}
Also used : User(org.springframework.security.core.userdetails.User) RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) Test(org.junit.Test)

Example 15 with User

use of org.springframework.security.core.userdetails.User 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);
}
Also used : User(org.springframework.security.core.userdetails.User) RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) Test(org.junit.Test)

Aggregations

User (org.springframework.security.core.userdetails.User)54 Test (org.junit.Test)30 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)16 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)15 UserDetails (org.springframework.security.core.userdetails.UserDetails)14 Authentication (org.springframework.security.core.Authentication)13 GrantedAuthority (org.springframework.security.core.GrantedAuthority)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 ArrayList (java.util.ArrayList)5 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)4 Before (org.junit.Before)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 SecurityContext (org.springframework.security.core.context.SecurityContext)3 FilterChain (javax.servlet.FilterChain)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Assertion (org.jasig.cas.client.validation.Assertion)2 AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)2 DirContextOperations (org.springframework.ldap.core.DirContextOperations)2 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)2