コード例 #1
0
 private void assertGroupEquals(Group expected, Group found) {
   assertThat(found).isNotNull();
   assertThat(found).isEqualTo(expected);
   assertThat(found.getName()).isEqualTo(expected.getName());
   assertThat(expected.getSubjectCredentials()).isEqualTo(found.getSubjectCredentials());
   Asserts.assertCreatedTimestamps(expected, found);
 }
コード例 #2
0
  @Test
  public void test_remove_groups_from_user() {
    SubjectCredentials subjectCredentials =
        SubjectCredentials.Builder.create()
            .authenticationType(SubjectCredentials.AuthenticationType.PASSWORD)
            .name("user1")
            .password("password")
            .groups(Sets.newHashSet("group1", "group2"))
            .build();
    subjectCredentialsService.save(subjectCredentials);

    subjectCredentials.removeGroup("group1");
    subjectCredentialsService.save(subjectCredentials);

    SubjectCredentials found =
        subjectCredentialsService.getSubjectCredentials(subjectCredentials.getName());
    assertSubjectEquals(subjectCredentials, found);

    assertThat(subjectCredentialsService.getGroups()).hasSize(2);

    Group group1 = subjectCredentialsService.getGroup("group1");
    assertThat(group1).isNotNull();
    assertThat(group1.getSubjectCredentials()).isEmpty();

    Group group2 = subjectCredentialsService.getGroup("group2");
    assertThat(group2).isNotNull();
    assertThat(group2.getSubjectCredentials()).hasSize(1);
    assertThat(group2.getSubjectCredentials()).contains(subjectCredentials.getName());
  }
コード例 #3
0
  @Test
  public void test_delete_user_with_groups() {
    SubjectCredentials subjectCredentials =
        SubjectCredentials.Builder.create()
            .authenticationType(SubjectCredentials.AuthenticationType.PASSWORD)
            .name("user1")
            .password("password")
            .groups(Sets.newHashSet("group1", "group2"))
            .build();
    subjectCredentialsService.save(subjectCredentials);

    subjectCredentialsService.delete(subjectCredentials);

    assertThat(
            subjectCredentialsService.getSubjectCredentials(
                SubjectCredentials.AuthenticationType.PASSWORD))
        .isEmpty();

    Group group1 = subjectCredentialsService.getGroup("group1");
    assertThat(group1.getSubjectCredentials()).isEmpty();

    Group group2 = subjectCredentialsService.getGroup("group2");
    assertThat(group2.getSubjectCredentials()).isEmpty();
  }