Search in sources :

Example 16 with IPentahoUser

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

the class UserRoleDaoEncodeIT method testUpdateUser.

@Test
public void testUpdateUser() 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 });
    IPentahoUser pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_5);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_5);
    String changedDescription1 = USER_DESCRIPTION_5 + "change1";
    userRoleDaoProxy.setUserDescription(mainTenant_1, USER_5, changedDescription1);
    pentahoUser = userRoleDaoProxy.getUser(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
    assertEquals(changedDescription1, pentahoUser.getDescription());
    String changedDescription2 = USER_DESCRIPTION_5 + "change2";
    userRoleDaoProxy.setUserDescription(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), changedDescription2);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_5);
    assertEquals(changedDescription2, pentahoUser.getDescription());
    userRoleDaoProxy.setUserDescription(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), null);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_5);
    assertNull(pentahoUser.getDescription());
    try {
        userRoleDaoProxy.setUserDescription(null, null, changedDescription2);
        fail("Exception not thrown");
    } catch (Exception ex) {
    // Expected exception
    }
    try {
        userRoleDaoProxy.setUserDescription(null, USER_5, changedDescription2);
    } catch (Exception ex) {
    // Expected exception
    }
    try {
        userRoleDaoProxy.setUserDescription(mainTenant_1, UNKNOWN_USER, changedDescription2);
        fail("Exception not thrown");
    } catch (NotFoundException ex) {
    // Expected exception
    }
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    try {
        changedDescription1 = USER_DESCRIPTION_5 + "change1";
        userRoleDaoProxy.setUserDescription(mainTenant_1, USER_5, changedDescription1);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
}
Also used : 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 17 with IPentahoUser

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

the class UserRoleDaoEncodeIT method testCreateUser.

@Test
public void testCreateUser() 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 });
    subTenant1_1 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant1_1, "admin", "password", "", new String[] { adminRoleName });
    subTenant1_2 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant1_2, "admin", "password", "", new String[] { adminRoleName });
    subTenant2_1 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant2_1, "admin", "password", "", new String[] { adminRoleName });
    subTenant2_2 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant2_2, "admin", "password", "", new String[] { adminRoleName });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    List<IPentahoUser> users = userRoleDaoProxy.getUsers(mainTenant_1);
    IPentahoUser pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_2);
    assertEquals(pentahoUser.getTenant(), mainTenant_1);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    /*login( "admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName } );
    try {
      pentahoUser = userRoleDaoProxy.createUser( mainTenant_1, USER_2, PASSWORD_2,
        USER_DESCRIPTION_2, null );
      fail( "Exception not thrown" );
    } catch ( Throwable th ) {
      assertNotNull( th );
    }
    logout();*/
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    users = userRoleDaoProxy.getUsers(mainTenant_1);
    int DEFAULT_USER_COUNT = 1;
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    boolean foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_2)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), mainTenant_1);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.createUser(mainTenant_2, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(mainTenant_2, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_2, USER_2);
    assertEquals(pentahoUser.getTenant(), mainTenant_2);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    users = userRoleDaoProxy.getUsers(mainTenant_2);
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_2)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), mainTenant_2);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.createUser(null, USER_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath(), PASSWORD_3, USER_DESCRIPTION_3, null);
    pentahoUser = userRoleDaoProxy.getUser(null, USER_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
    assertEquals(pentahoUser.getTenant(), subTenant2_1);
    assertEquals(pentahoUser.getUsername(), USER_3);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_3);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(subTenant2_1, USER_1, PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    users = userRoleDaoProxy.getUsers(subTenant2_1);
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_3)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), subTenant2_1);
    assertEquals(pentahoUser.getUsername(), USER_3);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_3);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.createUser(null, USER_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath(), PASSWORD_4, USER_DESCRIPTION_4, null);
    pentahoUser = userRoleDaoProxy.getUser(null, USER_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
    assertEquals(pentahoUser.getTenant(), subTenant1_1);
    assertEquals(pentahoUser.getUsername(), USER_4);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_4);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(subTenant1_1, USER_1, PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    users = userRoleDaoProxy.getUsers(subTenant1_1);
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_4)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), subTenant1_1);
    assertEquals(pentahoUser.getUsername(), USER_4);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_4);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_1, PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (AlreadyExistsException e) {
    // Expected exception
    }
    try {
        pentahoUser = userRoleDaoProxy.createUser(null, USER_1 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (AlreadyExistsException e) {
    // Expected exception
    }
}
Also used : AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 18 with IPentahoUser

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

the class UserRoleDaoIT method testUpdateUser.

@Test
public void testUpdateUser() 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 });
    IPentahoUser pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_5);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_5);
    String changedDescription1 = USER_DESCRIPTION_5 + "change1";
    userRoleDaoProxy.setUserDescription(mainTenant_1, USER_5, changedDescription1);
    pentahoUser = userRoleDaoProxy.getUser(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
    assertEquals(changedDescription1, pentahoUser.getDescription());
    String changedDescription2 = USER_DESCRIPTION_5 + "change2";
    userRoleDaoProxy.setUserDescription(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), changedDescription2);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_5);
    assertEquals(changedDescription2, pentahoUser.getDescription());
    userRoleDaoProxy.setUserDescription(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), null);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_5);
    assertNull(pentahoUser.getDescription());
    try {
        userRoleDaoProxy.setUserDescription(null, null, changedDescription2);
        fail("Exception not thrown");
    } catch (Exception ex) {
    // Expected exception
    }
    try {
        userRoleDaoProxy.setUserDescription(null, USER_5, changedDescription2);
    } catch (Exception ex) {
    // Expected exception
    }
    try {
        userRoleDaoProxy.setUserDescription(mainTenant_1, UNKNOWN_USER, changedDescription2);
        fail("Exception not thrown");
    } catch (NotFoundException ex) {
    // Expected exception
    }
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    try {
        changedDescription1 = USER_DESCRIPTION_5 + "change1";
        userRoleDaoProxy.setUserDescription(mainTenant_1, USER_5, changedDescription1);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
}
Also used : 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) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 with IPentahoUser

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

the class UserRoleDaoIT method testCreateUser.

@Test
public void testCreateUser() 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 });
    subTenant1_1 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant1_1, "admin", "password", "", new String[] { adminRoleName });
    subTenant1_2 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant1_2, "admin", "password", "", new String[] { adminRoleName });
    subTenant2_1 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant2_1, "admin", "password", "", new String[] { adminRoleName });
    subTenant2_2 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant2_2, "admin", "password", "", new String[] { adminRoleName });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    List<IPentahoUser> users = userRoleDaoProxy.getUsers(mainTenant_1);
    IPentahoUser pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_2);
    assertEquals(pentahoUser.getTenant(), mainTenant_1);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    /*login( "admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName } );
    try {
      pentahoUser = userRoleDaoProxy.createUser( mainTenant_1, USER_2, PASSWORD_2,
        USER_DESCRIPTION_2, null );
      fail( "Exception not thrown" );
    } catch ( Throwable th ) {
      assertNotNull( th );
    }
    logout();*/
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    users = userRoleDaoProxy.getUsers(mainTenant_1);
    int DEFAULT_USER_COUNT = 1;
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    boolean foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_2)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), mainTenant_1);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.createUser(mainTenant_2, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(mainTenant_2, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.getUser(mainTenant_2, USER_2);
    assertEquals(pentahoUser.getTenant(), mainTenant_2);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    users = userRoleDaoProxy.getUsers(mainTenant_2);
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_2)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), mainTenant_2);
    assertEquals(pentahoUser.getUsername(), USER_2);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_2);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.createUser(null, USER_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath(), PASSWORD_3, USER_DESCRIPTION_3, null);
    pentahoUser = userRoleDaoProxy.getUser(null, USER_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
    assertEquals(pentahoUser.getTenant(), subTenant2_1);
    assertEquals(pentahoUser.getUsername(), USER_3);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_3);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(subTenant2_1, USER_1, PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    users = userRoleDaoProxy.getUsers(subTenant2_1);
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_3)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), subTenant2_1);
    assertEquals(pentahoUser.getUsername(), USER_3);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_3);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    pentahoUser = userRoleDaoProxy.createUser(null, USER_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath(), PASSWORD_4, USER_DESCRIPTION_4, null);
    pentahoUser = userRoleDaoProxy.getUser(null, USER_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
    assertEquals(pentahoUser.getTenant(), subTenant1_1);
    assertEquals(pentahoUser.getUsername(), USER_4);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_4);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(subTenant1_1, USER_1, PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    users = userRoleDaoProxy.getUsers(subTenant1_1);
    assertTrue(users.size() == 1 + DEFAULT_USER_COUNT);
    foundUser = false;
    for (IPentahoUser user : users) {
        if (user.getUsername().equals(USER_4)) {
            foundUser = true;
            pentahoUser = user;
            break;
        }
    }
    assertTrue(foundUser);
    assertEquals(pentahoUser.getTenant(), subTenant1_1);
    assertEquals(pentahoUser.getUsername(), USER_4);
    assertEquals(pentahoUser.getDescription(), USER_DESCRIPTION_4);
    assertEquals(pentahoUser.isEnabled(), true);
    logout();
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_1, PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (AlreadyExistsException e) {
    // Expected exception
    }
    try {
        pentahoUser = userRoleDaoProxy.createUser(null, USER_1 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), PASSWORD_1, USER_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (AlreadyExistsException e) {
    // Expected exception
    }
}
Also used : AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 20 with IPentahoUser

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

the class UserRoleDaoService method updatePassword.

public void updatePassword(User user) throws SecurityException {
    if (canAdminister()) {
        String userName = decode(user.getUserName());
        String password = decode(user.getPassword());
        IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class, "userRoleDaoProxy", PentahoSessionHolder.getSession());
        IPentahoUser puser = roleDao.getUser(null, userName);
        if (puser != null) {
            roleDao.setPassword(null, userName, password);
        } else {
            throw new SecurityException("User not found");
        }
    } else {
        throw new SecurityException("Logged-in user is not authorized to change password");
    }
}
Also used : IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

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