org.springframework.security.core.CredentialsContainer Java Examples

The following examples show how to use org.springframework.security.core.CredentialsContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlowableUserDetailsServiceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoadingKnownUserWithAllPrivileges() {
    UserDetails kermit = userDetailsService.loadUserByUsername("kermit");

    assertThat(kermit).isNotNull();
    assertThat(kermit.isCredentialsNonExpired()).as("credentialsNonExpired").isTrue();
    assertThat(kermit.isAccountNonLocked()).as("accountNonLocked").isTrue();
    assertThat(kermit.isAccountNonExpired()).as("accountNonExpired").isTrue();
    assertThat(kermit.isEnabled()).as("enabled").isTrue();
    assertThat(kermit.getUsername()).as("username").isEqualTo("kermit");
    assertThat(kermit.getPassword()).as("password").isEqualTo("kermit");
    assertThat(kermit.getAuthorities())
        .extracting(GrantedAuthority::getAuthority)
        .as("granted authorities")
        .containsExactly(
            "access admin application",
            "access modeler application",
            "start processes"
        );

    assertThat(kermit).isInstanceOf(FlowableUserDetails.class);

    FlowableUserDetails kermitFlowable = (FlowableUserDetails) kermit;

    User user = kermitFlowable.getUser();
    assertThat(user.getId()).isEqualTo("kermit");
    assertThat(user.getFirstName()).isEqualTo("Kermit");
    assertThat(user.getLastName()).isEqualTo("the Frog");
    assertThat(user.getDisplayName()).isEqualTo("Kermit the Frog");
    assertThat(user.getEmail()).isEqualTo("[email protected]");
    assertThat(user.getPassword()).isEqualTo("kermit");

    user.setId("test");
    user.setFirstName("test");
    user.setLastName("test");
    user.setDisplayName("test");
    user.setEmail("test");

    assertThat(user.getId()).isEqualTo("kermit");
    assertThat(user.getFirstName()).isEqualTo("Kermit");
    assertThat(user.getLastName()).isEqualTo("the Frog");
    assertThat(user.getDisplayName()).isEqualTo("Kermit the Frog");
    assertThat(user.getEmail()).isEqualTo("[email protected]");

    assertThat(kermitFlowable.getGroups())
        .extracting(Group::getId, Group::getName, Group::getType)
        .as("Groups")
        .containsExactlyInAnyOrder(
            tuple("admins", "Admins", "user"),
            tuple("sales", "Sales", "user"),
            tuple("engineering", "Engineering", "tech")
        );

    kermitFlowable.getGroups().forEach(group -> {
        group.setId("test");
        group.setType("test");
        group.setName("test");
    });

    assertThat(kermitFlowable.getGroups())
        .extracting(Group::getId, Group::getName, Group::getType)
        .as("Groups")
        .containsExactlyInAnyOrder(
            tuple("admins", "Admins", "user"),
            tuple("sales", "Sales", "user"),
            tuple("engineering", "Engineering", "tech")
        );

    assertThat(kermit).isInstanceOf(CredentialsContainer.class);
    CredentialsContainer container = (CredentialsContainer) kermit;
    container.eraseCredentials();
    assertThat(kermit.getPassword()).as("Password after erase").isNull();
    assertThat(kermitFlowable.getUser().getPassword()).as("User password after erase").isNull();
}