Search in sources :

Example 41 with IPentahoUser

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

the class DefaultDeleteHelper method getUserList.

protected List<String> getUserList() {
    IUserRoleDao userRoleDao = PentahoSystem.get(IUserRoleDao.class);
    List<IPentahoUser> iusers = userRoleDao.getUsers();
    return iusers.stream().map(user -> user.getUsername()).collect(Collectors.toList());
}
Also used : Tenant(org.pentaho.platform.core.mt.Tenant) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) VersionHistory(javax.jcr.version.VersionHistory) QueryObjectModelConstants(javax.jcr.query.qom.QueryObjectModelConstants) Version(javax.jcr.version.Version) Date(java.util.Date) VersionIterator(javax.jcr.version.VersionIterator) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) QueryResult(javax.jcr.query.QueryResult) Property(javax.jcr.Property) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) ITenant(org.pentaho.platform.api.mt.ITenant) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Calendar(java.util.Calendar) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryException(javax.jcr.RepositoryException) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) VersionManager(javax.jcr.version.VersionManager) Lock(javax.jcr.lock.Lock) Query(javax.jcr.query.Query) Session(javax.jcr.Session) Constraint(javax.jcr.query.qom.Constraint) Messages(org.pentaho.platform.repository2.messages.Messages) Set(java.util.Set) Collectors(java.util.stream.Collectors) PentahoSessionHolder(org.pentaho.platform.engine.core.system.PentahoSessionHolder) ServerRepositoryPaths(org.pentaho.platform.repository2.unified.ServerRepositoryPaths) Serializable(java.io.Serializable) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) AdministerSecurityAction(org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction) List(java.util.List) Selector(javax.jcr.query.qom.Selector) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Collections(java.util.Collections) NodeIterator(javax.jcr.NodeIterator) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 42 with IPentahoUser

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

the class DefaultUserRepositoryLifecycleManager method configureUsers.

private void configureUsers() throws PasswordServiceException {
    String singleTenantAdminPlainTextPassword = passwordService.decrypt(singleTenantAdminPassword);
    String nonAdminPasswordPlainTextPassword = passwordService.decrypt(nonAdminPassword);
    for (final String userName : userRoleMappings.keySet()) {
        final IPentahoUser user = userRoleDao.getUser(DEFAULT_TENANT, userName);
        if (user == null) {
            StringBuffer buffer = new StringBuffer();
            if (logger.isDebugEnabled()) {
                logger.debug("Creating user: " + userName);
            }
            List<String> roleNames = new ArrayList<String>();
            for (String roleName : userRoleMappings.get(userName)) {
                if (roleMappings.containsKey(roleName) || systemRoles.contains(roleName)) {
                    roleNames.add(roleName);
                    buffer.append(roleName + "  ");
                } else {
                    logger.error("Unable to map undefined role to user. User[" + userName + "] Role[" + roleName + "]");
                }
            }
            if (singleTenantAdminUserName.equals(userName)) {
                userRoleDao.createUser(DEFAULT_TENANT, userName, singleTenantAdminPlainTextPassword, "user", roleNames.toArray(EMPTY_STRING_ARRAY));
            } else {
                userRoleDao.createUser(DEFAULT_TENANT, userName, nonAdminPasswordPlainTextPassword, "user", roleNames.toArray(EMPTY_STRING_ARRAY));
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Created user: " + userName + "with role mappings [" + buffer + "]");
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 43 with IPentahoUser

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

the class UserRoleWebService method updateRole.

@Override
public void updateRole(String roleName, String description, List<String> usernames) throws UserRoleException {
    IPentahoRole role = getDao().getRole(null, roleName);
    if (role == null) {
        throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0006_ROLE_UPDATE_FAILED", // $NON-NLS-1$
        roleName));
    }
    Set<String> users = new HashSet<String>();
    for (String username : usernames) {
        IPentahoUser user = getDao().getUser(null, username);
        if (user == null) {
            throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0006_ROLE_UPDATE_FAILED", // $NON-NLS-1$
            roleName));
        }
        users.add(user.getUsername());
    }
    getDao().setRoleDescription(null, roleName, description);
    getDao().setRoleMembers(null, roleName, users.toArray(new String[0]));
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) HashSet(java.util.HashSet)

Example 44 with IPentahoUser

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

the class UserRoleWebService method updateUser.

@Override
public boolean updateUser(ProxyPentahoUser proxyUser) throws UserRoleException {
    IPentahoUser user = getDao().getUser(proxyUser.getTenant(), proxyUser.getName());
    if (user == null) {
        throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0004_FAILED_TO_FIND_USER", // $NON-NLS-1$
        proxyUser.getName()));
    }
    if (!StringUtils.isBlank(proxyUser.getPassword())) {
        getDao().setPassword(proxyUser.getTenant(), proxyUser.getName(), proxyUser.getPassword());
    }
    getDao().setUserDescription(proxyUser.getTenant(), proxyUser.getName(), proxyUser.getDescription());
    return true;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 45 with IPentahoUser

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

the class UserRoleWebService method getUserRoleSecurityInfo.

@Override
public UserRoleSecurityInfo getUserRoleSecurityInfo() throws UserRoleException {
    UserRoleSecurityInfo userRoleSecurityInfo = new UserRoleSecurityInfo();
    IUserRoleDao dao = getDao();
    List<IPentahoUser> users = dao.getUsers();
    if (users != null) {
        for (IPentahoUser user : users) {
            userRoleSecurityInfo.getUsers().add(ProxyPentahoUserRoleHelper.toProxyUser(user));
            List<IPentahoRole> roles = dao.getUserRoles(user.getTenant(), user.getUsername());
            if (roles != null) {
                for (IPentahoRole role : roles) {
                    userRoleSecurityInfo.getAssignments().add(new UserToRoleAssignment(user.getUsername(), role.getName()));
                }
            }
        }
    }
    userRoleSecurityInfo.getRoles().addAll(Arrays.asList(getRoles()));
    return userRoleSecurityInfo;
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) 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