Search in sources :

Example 1 with LdapUserDetailsImpl

use of org.springframework.security.ldap.userdetails.LdapUserDetailsImpl in project spring-security by spring-projects.

the class LdapUserDetailsImplMixinTests method serializeWhenMixinRegisteredThenSerializes.

@Test
public void serializeWhenMixinRegisteredThenSerializes() throws Exception {
    LdapUserDetailsMapper mapper = new LdapUserDetailsMapper();
    LdapUserDetailsImpl p = (LdapUserDetailsImpl) mapper.mapUserFromContext(createUserContext(), "ghengis", AuthorityUtils.NO_AUTHORITIES);
    String json = this.mapper.writeValueAsString(p);
    JSONAssert.assertEquals(USER_JSON, json, true);
}
Also used : LdapUserDetailsImpl(org.springframework.security.ldap.userdetails.LdapUserDetailsImpl) LdapUserDetailsMapper(org.springframework.security.ldap.userdetails.LdapUserDetailsMapper) Test(org.junit.jupiter.api.Test)

Example 2 with LdapUserDetailsImpl

use of org.springframework.security.ldap.userdetails.LdapUserDetailsImpl in project spring-security by spring-projects.

the class LdapUserDetailsImplMixinTests method deserializeWhenMixinRegisteredThenDeserializes.

@Test
public void deserializeWhenMixinRegisteredThenDeserializes() throws Exception {
    LdapUserDetailsMapper mapper = new LdapUserDetailsMapper();
    LdapUserDetailsImpl expectedAuthentication = (LdapUserDetailsImpl) mapper.mapUserFromContext(createUserContext(), "ghengis", AuthorityUtils.NO_AUTHORITIES);
    LdapUserDetailsImpl authentication = this.mapper.readValue(USER_JSON, LdapUserDetailsImpl.class);
    assertThat(authentication.getAuthorities()).containsExactlyElementsOf(expectedAuthentication.getAuthorities());
    assertThat(authentication.getDn()).isEqualTo(expectedAuthentication.getDn());
    assertThat(authentication.getUsername()).isEqualTo(expectedAuthentication.getUsername());
    assertThat(authentication.getPassword()).isEqualTo(expectedAuthentication.getPassword());
    assertThat(authentication.getGraceLoginsRemaining()).isEqualTo(expectedAuthentication.getGraceLoginsRemaining());
    assertThat(authentication.getTimeBeforeExpiration()).isEqualTo(expectedAuthentication.getTimeBeforeExpiration());
    assertThat(authentication.isAccountNonExpired()).isEqualTo(expectedAuthentication.isAccountNonExpired());
    assertThat(authentication.isAccountNonLocked()).isEqualTo(expectedAuthentication.isAccountNonLocked());
    assertThat(authentication.isEnabled()).isEqualTo(expectedAuthentication.isEnabled());
    assertThat(authentication.isCredentialsNonExpired()).isEqualTo(expectedAuthentication.isCredentialsNonExpired());
}
Also used : LdapUserDetailsImpl(org.springframework.security.ldap.userdetails.LdapUserDetailsImpl) LdapUserDetailsMapper(org.springframework.security.ldap.userdetails.LdapUserDetailsMapper) Test(org.junit.jupiter.api.Test)

Example 3 with LdapUserDetailsImpl

use of org.springframework.security.ldap.userdetails.LdapUserDetailsImpl in project spring-security by spring-projects.

the class LdapUserDetailsImplMixinTests method serializeWhenEraseCredentialInvokedThenUserPasswordIsNull.

@Test
public void serializeWhenEraseCredentialInvokedThenUserPasswordIsNull() throws JsonProcessingException, JSONException {
    LdapUserDetailsMapper mapper = new LdapUserDetailsMapper();
    LdapUserDetailsImpl p = (LdapUserDetailsImpl) mapper.mapUserFromContext(createUserContext(), "ghengis", AuthorityUtils.NO_AUTHORITIES);
    p.eraseCredentials();
    String actualJson = this.mapper.writeValueAsString(p);
    JSONAssert.assertEquals(USER_JSON.replaceAll("\"" + USER_PASSWORD + "\"", "null"), actualJson, true);
}
Also used : LdapUserDetailsImpl(org.springframework.security.ldap.userdetails.LdapUserDetailsImpl) LdapUserDetailsMapper(org.springframework.security.ldap.userdetails.LdapUserDetailsMapper) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 LdapUserDetailsImpl (org.springframework.security.ldap.userdetails.LdapUserDetailsImpl)3 LdapUserDetailsMapper (org.springframework.security.ldap.userdetails.LdapUserDetailsMapper)3