Search in sources :

Example 51 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class MockUserRoleDao method getUser.

public IPentahoUser getUser(ITenant tenant, String userName) throws UncategorizedUserRoleDaoException {
    if (tenant == null) {
        tenant = getTenant(userName, true);
        userName = getPrincipalName(userName, true);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    HashSet<IPentahoUser> users = tenantUsers.get(tenant);
    if (users != null) {
        for (IPentahoUser user : users) {
            if (user.getUsername().equals(userName)) {
                return user;
            }
        }
    }
    return null;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 52 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class MockUserRoleDao method setRoleMembers.

public void setRoleMembers(ITenant tenant, String roleName, String[] userNames) throws NotFoundException, UncategorizedUserRoleDaoException {
    if (tenant == null) {
        tenant = getTenant(roleName, false);
        roleName = getPrincipalName(roleName, false);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    IPentahoRole role = getRole(tenant, roleName);
    HashSet<IPentahoUser> users = roleMembers.get(role);
    users.clear();
    if (userNames != null) {
        for (String userName : userNames) {
            IPentahoUser user = getUser(tenant, userName);
            if (!userRoles.containsKey(user)) {
                userRoles.put(user, new HashSet<IPentahoRole>());
            }
            userRoles.get(user).add(role);
            if (user != null) {
                users.add(user);
            }
        }
    }
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 53 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoEncodeIT method testDeleteUser.

@Test
public void testDeleteUser() throws Exception {
    int DEFAULT_TENANT_USER = 1;
    loginAsRepositoryAdmin();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
    login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
    mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
    mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    IPentahoUser pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null);
    pentahoUser = userRoleDaoProxy.getUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
    assertNotNull(pentahoUser);
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    try {
        userRoleDaoProxy.deleteUser(pentahoUser);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.getUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
    assertNull(pentahoUser);
    assertEquals(DEFAULT_TENANT_USER, userRoleDaoProxy.getUsers(mainTenant_1).size());
    pentahoUser = userRoleDaoProxy.createUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), PASSWORD_6, USER_DESCRIPTION_6, null);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_6);
    assertNotNull(pentahoUser);
    userRoleDaoProxy.deleteUser(pentahoUser);
    assertNull(userRoleDaoProxy.getUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath()));
    try {
        userRoleDaoProxy.deleteUser(pentahoUser);
        fail("Exception not thrown");
    } catch (NotFoundException e) {
    // Expected exception
    }
    try {
        pentahoUser = new PentahoUser(null, USER_6, PASSWORD_6, USER_DESCRIPTION_6, true);
        userRoleDaoProxy.deleteUser(pentahoUser);
        fail("Exception not thrown");
    } catch (Exception ex) {
    // Expected exception
    }
    try {
        pentahoUser = new PentahoUser(mainTenant_1, null, PASSWORD_6, USER_DESCRIPTION_6, true);
        userRoleDaoProxy.deleteUser(pentahoUser);
        fail("Exception not thrown");
    } catch (NotFoundException e) {
    // Expected exception
    }
    try {
        pentahoUser = new PentahoUser(mainTenant_1, UNKNOWN_USER, PASSWORD_6, USER_DESCRIPTION_6, true);
        userRoleDaoProxy.deleteUser(pentahoUser);
        fail("Exception not thrown");
    } catch (NotFoundException e) {
    // Expected exception
    }
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) Test(org.junit.Test)

Example 54 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoEncodeIT method testGetUsers.

@Test
public void testGetUsers() throws Exception {
    int DEFAULT_USER_COUNT = 1;
    loginAsRepositoryAdmin();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
    login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
    mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
    mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    userRoleDaoProxy.createUser(mainTenant_1, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
    userRoleDaoProxy.createUser(mainTenant_1, USER_8, PASSWORD_8, USER_DESCRIPTION_8, null);
    List<IPentahoUser> users = userRoleDaoProxy.getUsers(mainTenant_1);
    assertEquals(2 + DEFAULT_USER_COUNT, users.size());
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_1)) {
            assertEquals(user.getTenant(), mainTenant_1);
            assertEquals(user.isEnabled(), true);
        } else if (user.getUsername().equals(USER_7)) {
            assertEquals(user.getTenant(), mainTenant_1);
            assertEquals(user.getDescription(), USER_DESCRIPTION_7);
            assertEquals(user.isEnabled(), true);
        } else if (user.getUsername().equals(USER_8)) {
            assertEquals(user.getTenant(), mainTenant_1);
            assertEquals(user.getDescription(), USER_DESCRIPTION_8);
            assertEquals(user.isEnabled(), true);
        } else {
            fail("Invalid user name");
        }
    }
    try {
        users = userRoleDaoProxy.getUsers(UNKNOWN_TENANT);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 55 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoEncodeIT method testRoleWithMembers.

@Test
public void testRoleWithMembers() throws Exception {
    loginAsRepositoryAdmin();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
    login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
    mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
    mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null);
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null);
    userRoleDaoProxy.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, new String[] { ROLE_1 });
    userRoleDaoProxy.createUser(mainTenant_1, USER_3, PASSWORD_3, USER_DESCRIPTION_3, new String[] { ROLE_1, ROLE_2 });
    List<IPentahoUser> users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_2);
    assertEquals(1, users.size());
    assertEquals(USER_3, users.get(0).getUsername());
    ArrayList<String> expectedUserNames = new ArrayList<String>();
    expectedUserNames.add(USER_2);
    expectedUserNames.add(USER_3);
    ArrayList<String> actualUserNames = new ArrayList<String>();
    String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
    users = userRoleDaoProxy.getRoleMembers(null, ROLE_1 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
    for (IPentahoUser user : users) {
        actualUserNames.add(user.getUsername());
    }
    assertEquals(2, actualUserNames.size());
    assertTrue(actualUserNames.containsAll(expectedUserNames));
    users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_3);
    assertEquals(0, users.size());
    userRoleDaoProxy.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
    userRoleDaoProxy.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null);
    userRoleDaoProxy.createUser(mainTenant_1, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_5, ROLE_DESCRIPTION_6, new String[] { USER_5 });
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_6, ROLE_DESCRIPTION_7, new String[] { USER_5, USER_6 });
    ArrayList<String> expectedRoleNames = new ArrayList<String>();
    expectedRoleNames.add(ROLE_6);
    expectedRoleNames.add(authenticatedRoleName);
    ArrayList<String> actualRoleNames = new ArrayList<String>();
    List<IPentahoRole> roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_6);
    for (IPentahoRole role : roles) {
        actualRoleNames.add(role.getName());
    }
    assertEquals(2, roles.size());
    assertTrue(actualRoleNames.containsAll(expectedRoleNames));
    expectedRoleNames = new ArrayList<String>();
    expectedRoleNames.add(ROLE_5);
    expectedRoleNames.add(ROLE_6);
    expectedRoleNames.add(authenticatedRoleName);
    actualRoleNames = new ArrayList<String>();
    roles = userRoleDaoProxy.getUserRoles(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
    for (IPentahoRole role : roles) {
        actualRoleNames.add(role.getName());
    }
    assertEquals(3, actualRoleNames.size());
    assertTrue(actualRoleNames.containsAll(expectedRoleNames));
    roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_7);
    assertEquals(1, roles.size());
    assertEquals(authenticatedRoleName, roles.get(0).getName());
    userRoleDaoProxy.setUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), new String[] { ROLE_5, ROLE_6 });
    roles = userRoleDaoProxy.getUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
    actualRoleNames.clear();
    for (IPentahoRole role : roles) {
        actualRoleNames.add(role.getName());
    }
    assertEquals(3, actualRoleNames.size());
    assertTrue(actualRoleNames.containsAll(expectedRoleNames));
    expectedUserNames = new ArrayList<String>();
    expectedUserNames.add(USER_1);
    expectedUserNames.add(USER_2);
    expectedRoleNames.add(authenticatedRoleName);
    userRoleDaoProxy.setRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), new String[] { USER_1, USER_2 });
    users = userRoleDaoProxy.getRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
    actualUserNames.clear();
    for (IPentahoUser user : users) {
        actualUserNames.add(user.getUsername());
    }
    assertEquals(2, actualUserNames.size());
    assertTrue(actualUserNames.containsAll(expectedUserNames));
}
Also used : ArrayList(java.util.ArrayList) DefaultTenantedPrincipleNameResolver(org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Aggregations

IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)60 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)16 ITenant (org.pentaho.platform.api.mt.ITenant)15 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)13 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)12 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)11 RepositoryException (javax.jcr.RepositoryException)8 PentahoUser (org.pentaho.platform.security.userroledao.PentahoUser)8 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)7 HashSet (java.util.HashSet)6 Matchers.anyString (org.mockito.Matchers.anyString)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 IOException (java.io.IOException)4 AccessControlException (javax.jcr.security.AccessControlException)4 Group (org.apache.jackrabbit.api.security.user.Group)4 BeansException (org.springframework.beans.BeansException)4 User (org.apache.jackrabbit.api.security.user.User)3 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)3 UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)3