Search in sources :

Example 1 with PentahoUser

use of org.pentaho.platform.security.userroledao.PentahoUser in project pentaho-platform by pentaho.

the class AbstractJcrBackedUserRoleDao method convertToPentahoUser.

@VisibleForTesting
IPentahoUser convertToPentahoUser(User jackrabbitUser) throws RepositoryException {
    if (getUserCache().containsKey(jackrabbitUser.getID())) {
        return (IPentahoUser) getUserCache().get(jackrabbitUser.getID());
    }
    IPentahoUser pentahoUser = null;
    Value[] propertyValues = null;
    String description = null;
    try {
        // $NON-NLS-1$
        propertyValues = jackrabbitUser.getProperty("description");
        description = propertyValues.length > 0 ? propertyValues[0].getString() : null;
    } catch (Exception ex) {
    // CHECKSTYLES IGNORE
    }
    Credentials credentials = jackrabbitUser.getCredentials();
    String password = null;
    if (credentials instanceof CryptedSimpleCredentials) {
        password = new String(((CryptedSimpleCredentials) credentials).getPassword());
    }
    pentahoUser = new PentahoUser(getTenantedUserNameUtils().getTenant(jackrabbitUser.getID()), getTenantedUserNameUtils().getPrincipleName(jackrabbitUser.getID()), password, description, !jackrabbitUser.isDisabled());
    if (isUseJackrabbitUserCache()) {
        getUserCache().put(jackrabbitUser.getID(), pentahoUser);
    }
    return pentahoUser;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) Value(javax.jcr.Value) CryptedSimpleCredentials(org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) RepositoryException(javax.jcr.RepositoryException) NamespaceException(javax.jcr.NamespaceException) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) CryptedSimpleCredentials(org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials) Credentials(javax.jcr.Credentials) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with PentahoUser

use of org.pentaho.platform.security.userroledao.PentahoUser in project pentaho-platform by pentaho.

the class AbstractJcrBackedUserRoleDao method getUsers.

public List<IPentahoUser> getUsers(Session session, ITenant theTenant, boolean includeSubtenants) throws RepositoryException {
    ArrayList<IPentahoUser> users = new ArrayList<IPentahoUser>();
    if (theTenant == null || theTenant.getId() == null) {
        theTenant = JcrTenantUtils.getTenant();
    }
    if (TenantUtils.isAccessibleTenant(theTenant)) {
        UserManager userMgr = getUserManager(theTenant, session);
        pPrincipalName = getJcrName(session);
        Iterator<Authorizable> it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_USER);
        while (it.hasNext()) {
            User user = (User) it.next();
            IPentahoUser pentahoUser = convertToPentahoUser(user);
            if (includeSubtenants) {
                users.add(pentahoUser);
            } else {
                if (pentahoUser.getTenant() != null && pentahoUser.getTenant().equals(theTenant)) {
                    users.add(pentahoUser);
                }
            }
        }
    }
    return users;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.apache.jackrabbit.api.security.user.User) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 3 with PentahoUser

use of org.pentaho.platform.security.userroledao.PentahoUser in project pentaho-platform by pentaho.

the class ProxyPentahoUserRoleHelper method syncUsers.

/**
 * Synchronizes <code>user</code> with fields from <code>proxyUser</code>. The roles set of given
 * <code>user</code> is unmodified.
 */
public static IPentahoUser syncUsers(IPentahoUser user, ProxyPentahoUser proxyUser) {
    IPentahoUser syncedUser = user;
    if (syncedUser == null) {
        syncedUser = new PentahoUser(proxyUser.getName());
    }
    syncedUser.setDescription(proxyUser.getDescription());
    // password is not changed. If the user enters a value, set the password.
    if (!StringUtils.isBlank(proxyUser.getPassword())) {
        PasswordEncoder encoder = // $NON-NLS-1$
        PentahoSystem.get(PasswordEncoder.class, "passwordEncoder", PentahoSessionHolder.getSession());
        syncedUser.setPassword(encoder.encodePassword(proxyUser.getPassword(), null));
    }
    syncedUser.setEnabled(proxyUser.getEnabled());
    return syncedUser;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) PasswordEncoder(org.springframework.security.authentication.encoding.PasswordEncoder) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 4 with PentahoUser

use of org.pentaho.platform.security.userroledao.PentahoUser 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 5 with PentahoUser

use of org.pentaho.platform.security.userroledao.PentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoIT 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) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)5 PentahoUser (org.pentaho.platform.security.userroledao.PentahoUser)5 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)3 IOException (java.io.IOException)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlException (javax.jcr.security.AccessControlException)2 Test (org.junit.Test)2 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)2 BeansException (org.springframework.beans.BeansException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 Credentials (javax.jcr.Credentials)1 NamespaceException (javax.jcr.NamespaceException)1 Value (javax.jcr.Value)1 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)1 AuthorizableExistsException (org.apache.jackrabbit.api.security.user.AuthorizableExistsException)1 User (org.apache.jackrabbit.api.security.user.User)1 UserManager (org.apache.jackrabbit.api.security.user.UserManager)1 CryptedSimpleCredentials (org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials)1 PasswordEncoder (org.springframework.security.authentication.encoding.PasswordEncoder)1