Search in sources :

Example 6 with UserGroup

use of com.thinkbiganalytics.metadata.api.user.UserGroup in project kylo by Teradata.

the class KyloAuthConfig method createDefaultGroup.

protected UserGroup createDefaultGroup(String groupName, String title, String oldGroupName) {
    UserGroup newGroup = userProvider.ensureGroup(groupName);
    newGroup.setTitle(title);
    // If there is an old group replacing this new group transfer the users before deleting it.
    if (oldGroupName != null) {
        userProvider.findGroupByName(oldGroupName).ifPresent(oldGrp -> {
            oldGrp.getUsers().forEach(user -> newGroup.addUser(user));
            userProvider.deleteGroup(oldGrp);
        });
    }
    return newGroup;
}
Also used : UserGroup(com.thinkbiganalytics.metadata.api.user.UserGroup)

Example 7 with UserGroup

use of com.thinkbiganalytics.metadata.api.user.UserGroup in project kylo by Teradata.

the class JcrUserProviderTest method testGroupGetAllContainingGroups.

@Test(dependsOnMethods = "testCreateMemberGroups")
public void testGroupGetAllContainingGroups() {
    metadata.read(() -> {
        UserGroup groupA = this.provider.findGroupByName("groupA").get();
        UserGroup groupB = this.provider.findGroupByName("groupB").get();
        UserGroup groupC = this.provider.findGroupByName("groupC").get();
        UserGroup groupD = this.provider.findGroupByName("groupD").get();
        assertThat(groupA.getAllContainingGroups()).isEmpty();
        assertThat(groupB.getAllContainingGroups()).hasSize(1).extracting(g -> g.getSystemName()).contains("groupA");
        assertThat(groupC.getAllContainingGroups()).hasSize(1).extracting(g -> g.getSystemName()).contains("groupA");
        assertThat(groupD.getAllContainingGroups()).hasSize(2).extracting(g -> g.getSystemName()).contains("groupC", "groupA");
    });
}
Also used : ModeShapeEngineConfig(com.thinkbiganalytics.metadata.modeshape.ModeShapeEngineConfig) UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) User(com.thinkbiganalytics.metadata.api.user.User) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) SpringApplicationConfiguration(org.springframework.boot.test.SpringApplicationConfiguration) UserGroup(com.thinkbiganalytics.metadata.api.user.UserGroup) JcrTestConfig(com.thinkbiganalytics.metadata.modeshape.JcrTestConfig) Optional(java.util.Optional) StreamSupport(java.util.stream.StreamSupport) UserProvider(com.thinkbiganalytics.metadata.api.user.UserProvider) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) UserGroup(com.thinkbiganalytics.metadata.api.user.UserGroup) Test(org.testng.annotations.Test)

Example 8 with UserGroup

use of com.thinkbiganalytics.metadata.api.user.UserGroup in project kylo by Teradata.

the class JcrUserProviderTest method testCreateGroup.

@Test(dependsOnMethods = "testFindUsers")
public void testCreateGroup() {
    UserGroup.ID id = metadata.commit(() -> {
        UserGroup groupA = this.provider.createGroup("groupA");
        assertThat(groupA).isNotNull();
        return groupA.getId();
    }, MetadataAccess.SERVICE);
    metadata.read(() -> {
        Optional<UserGroup> optional = this.provider.findGroupById(id);
        assertThat(optional.isPresent()).isTrue();
    }, MetadataAccess.SERVICE);
}
Also used : UserGroup(com.thinkbiganalytics.metadata.api.user.UserGroup) Test(org.testng.annotations.Test)

Example 9 with UserGroup

use of com.thinkbiganalytics.metadata.api.user.UserGroup in project kylo by Teradata.

the class JcrUserProviderTest method testCreateMemberGroups.

@Test(dependsOnMethods = "testCreateGroup")
public void testCreateMemberGroups() {
    metadata.commit(() -> {
        UserGroup groupA = this.provider.findGroupByName("groupA").get();
        UserGroup groupB = this.provider.createGroup("groupB");
        UserGroup groupC = this.provider.createGroup("groupC");
        UserGroup groupD = this.provider.createGroup("groupD");
        assertThat(groupA.addGroup(groupB)).isTrue();
        assertThat(groupA.addGroup(groupC)).isTrue();
        assertThat(groupC.addGroup(groupD)).isTrue();
    }, MetadataAccess.SERVICE);
}
Also used : UserGroup(com.thinkbiganalytics.metadata.api.user.UserGroup) Test(org.testng.annotations.Test)

Example 10 with UserGroup

use of com.thinkbiganalytics.metadata.api.user.UserGroup in project kylo by Teradata.

the class JcrUserProviderTest method testGetUsers.

@Test(dependsOnMethods = "testAddUsersMembers")
public void testGetUsers() {
    metadata.read(() -> {
        UserGroup groupA = this.provider.findGroupByName("groupA").get();
        UserGroup groupB = this.provider.findGroupByName("groupB").get();
        UserGroup groupC = this.provider.findGroupByName("groupC").get();
        UserGroup groupD = this.provider.findGroupByName("groupD").get();
        assertThat(groupA.getUsers()).extracting(User::getSystemName).containsExactly("user1");
        assertThat(groupB.getUsers()).extracting(User::getSystemName).containsExactly("user2");
        assertThat(groupD.getUsers()).extracting(User::getSystemName).containsExactly("user3");
        assertThat(groupC.getUsers()).hasSize(0);
    });
}
Also used : UserGroup(com.thinkbiganalytics.metadata.api.user.UserGroup) Test(org.testng.annotations.Test)

Aggregations

UserGroup (com.thinkbiganalytics.metadata.api.user.UserGroup)13 Test (org.testng.annotations.Test)8 User (com.thinkbiganalytics.metadata.api.user.User)5 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)3 UserProvider (com.thinkbiganalytics.metadata.api.user.UserProvider)3 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)3 JcrTestConfig (com.thinkbiganalytics.metadata.modeshape.JcrTestConfig)3 ModeShapeEngineConfig (com.thinkbiganalytics.metadata.modeshape.ModeShapeEngineConfig)3 GroupPrincipal (com.thinkbiganalytics.security.GroupPrincipal)3 UsernamePrincipal (com.thinkbiganalytics.security.UsernamePrincipal)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 StreamSupport (java.util.stream.StreamSupport)3 Inject (javax.inject.Inject)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 SpringApplicationConfiguration (org.springframework.boot.test.SpringApplicationConfiguration)3 AbstractTestNGSpringContextTests (org.springframework.test.context.testng.AbstractTestNGSpringContextTests)3 UpgradeException (com.thinkbiganalytics.server.upgrade.UpgradeException)1 RepositoryException (javax.jcr.RepositoryException)1