Search in sources :

Example 61 with UsernamePasswordAuthenticationToken

use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project spring-security by spring-projects.

the class UsernamePasswordAuthenticationTokenMixinTests method deserializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest.

@Test
public void deserializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() throws IOException, JSONException {
    UsernamePasswordAuthenticationToken token = mapper.readValue(UNAUTHENTICATED_STRINGPRINCIPAL_JSON, UsernamePasswordAuthenticationToken.class);
    assertThat(token).isNotNull();
    assertThat(token.isAuthenticated()).isEqualTo(false);
    assertThat(token.getAuthorities()).isNotNull().hasSize(0);
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 62 with UsernamePasswordAuthenticationToken

use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project spring-security by spring-projects.

the class UsernamePasswordAuthenticationTokenMixinTests method serializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest.

// @formatter:on
@Test
public void serializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() throws JsonProcessingException, JSONException {
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", "1234");
    String serializedJson = mapper.writeValueAsString(token);
    JSONAssert.assertEquals(UNAUTHENTICATED_STRINGPRINCIPAL_JSON, serializedJson, true);
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 63 with UsernamePasswordAuthenticationToken

use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken 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 64 with UsernamePasswordAuthenticationToken

use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken 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 65 with UsernamePasswordAuthenticationToken

use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project spring-security by spring-projects.

the class UsernamePasswordAuthenticationTokenMixinTests method serializeAuthenticatedUsernamePasswordAuthenticationTokenMixinWithUserTest.

@Test
public void serializeAuthenticatedUsernamePasswordAuthenticationTokenMixinWithUserTest() throws JsonProcessingException, JSONException {
    UsernamePasswordAuthenticationToken token = createToken();
    String actualJson = mapper.writeValueAsString(token);
    JSONAssert.assertEquals(AUTHENTICATED_JSON, actualJson, true);
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Aggregations

UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)309 Test (org.junit.Test)156 Authentication (org.springframework.security.core.Authentication)114 GrantedAuthority (org.springframework.security.core.GrantedAuthority)37 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)34 UserDetails (org.springframework.security.core.userdetails.UserDetails)33 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)29 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)27 SecurityContext (org.springframework.security.core.context.SecurityContext)21 AuthenticationException (org.springframework.security.core.AuthenticationException)20 User (org.springframework.security.core.userdetails.User)17 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)15 ArrayList (java.util.ArrayList)14 OrcidProfileUserDetails (org.orcid.core.oauth.OrcidProfileUserDetails)13 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)13 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)13 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)12 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)11 Before (org.junit.Before)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8