Search in sources :

Example 11 with NotFoundException

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

the class AbstractJcrBackedUserRoleDao method setPassword.

public void setPassword(Session session, final ITenant theTenant, final String userName, final String password) throws NotFoundException, RepositoryException {
    User jackrabbitUser = getJackrabbitUser(theTenant, userName, session);
    if ((jackrabbitUser == null) || !TenantUtils.isAccessibleTenant(theTenant == null ? tenantedUserNameUtils.getTenant(jackrabbitUser.getID()) : theTenant)) {
        throw new NotFoundException(Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.ERROR_0003_USER_NOT_FOUND"));
    }
    jackrabbitUser.changePassword(password);
    /**
     * BISERVER-9906 Clear cache after changing password
     */
    purgeUserFromCache(userName);
    userCache.remove(jackrabbitUser.getID());
}
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) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException)

Example 12 with NotFoundException

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

the class AbstractJcrBackedUserRoleDao method deleteUser.

public void deleteUser(Session session, final IPentahoUser user) throws NotFoundException, RepositoryException {
    if (canDeleteUser(session, user)) {
        User jackrabbitUser = getJackrabbitUser(user.getTenant(), user.getUsername(), session);
        if (jackrabbitUser != null && TenantUtils.isAccessibleTenant(tenantedUserNameUtils.getTenant(jackrabbitUser.getID()))) {
            // [BISERVER-9215] Adding new user with same user name as a previously deleted user, defaults to all
            // previous
            // roles
            Iterator<Group> currentGroups = jackrabbitUser.memberOf();
            while (currentGroups.hasNext()) {
                currentGroups.next().removeMember(jackrabbitUser);
            }
            purgeUserFromCache(user.getUsername());
            // [BISERVER-9215]
            jackrabbitUser.remove();
        } else {
            // $NON-NLS-1$
            throw new NotFoundException("");
        }
    } else {
        throw new RepositoryException(Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.ERROR_0004_LAST_USER_NEEDED_IN_ROLE", tenantAdminRoleName));
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.apache.jackrabbit.api.security.user.User) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) RepositoryException(javax.jcr.RepositoryException)

Example 13 with NotFoundException

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

the class AbstractJcrBackedUserRoleDao method deleteRole.

public void deleteRole(Session session, final IPentahoRole role) throws NotFoundException, RepositoryException {
    if (canDeleteRole(session, role)) {
        final List<IPentahoUser> roleMembers = this.getRoleMembers(session, role.getTenant(), role.getName());
        Group jackrabbitGroup = getJackrabbitGroup(role.getTenant(), role.getName(), session);
        if (jackrabbitGroup != null && TenantUtils.isAccessibleTenant(tenantedRoleNameUtils.getTenant(jackrabbitGroup.getID()))) {
            jackrabbitGroup.remove();
        } else {
            // $NON-NLS-1$
            throw new NotFoundException("");
        }
        for (IPentahoUser roleMember : roleMembers) {
            purgeUserFromCache(roleMember.getUsername());
        }
    } else {
        throw new RepositoryException(Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.ERROR_0007_ATTEMPTED_SYSTEM_ROLE_DELETE"));
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) RepositoryException(javax.jcr.RepositoryException) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 14 with NotFoundException

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

the class JcrRoleAuthorizationPolicyRoleBindingDao method setRoleBindings.

@Override
public void setRoleBindings(final ITenant tenant, final String runtimeRoleName, final List<String> logicalRoleNames) {
    ITenant tempTenant = tenant;
    if (tenant == null) {
        tempTenant = JcrTenantUtils.getTenant(runtimeRoleName, false);
    }
    if (!TenantUtils.isAccessibleTenant(tempTenant)) {
        throw new NotFoundException("Tenant " + tenant.getId() + " not found");
    }
    Assert.notNull(logicalRoleNames);
    jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            setRoleBindings(session, tenant, runtimeRoleName, logicalRoleNames);
            return null;
        }
    });
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session)

Example 15 with NotFoundException

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

the class UserRoleDaoResourceTest method testAssignRoleToUserNotFoundException.

@Test
public void testAssignRoleToUserNotFoundException() {
    String user = "testUser1";
    String roles = "testRole1";
    doThrow(new NotFoundException("expectedTestException")).when(userRoleService).assignRolesToUser(anyString(), anyString());
    try {
        userRoleResource.assignRolesToUser(user, roles);
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)25 Test (org.junit.Test)12 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)12 IOException (java.io.IOException)9 RepositoryException (javax.jcr.RepositoryException)9 AccessControlException (javax.jcr.security.AccessControlException)8 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)8 ITenant (org.pentaho.platform.api.mt.ITenant)8 BeansException (org.springframework.beans.BeansException)8 PentahoUser (org.pentaho.platform.security.userroledao.PentahoUser)7 Group (org.apache.jackrabbit.api.security.user.Group)5 User (org.apache.jackrabbit.api.security.user.User)5 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Matchers.anyString (org.mockito.Matchers.anyString)4 DefaultTenantedPrincipleNameResolver (org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver)4 HashSet (java.util.HashSet)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2