Search in sources :

Example 16 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class UserRoleDaoResource_RolesUpdatedTest method rolesUpdated_WhenAssignAllUsersToRole_WithSessionAndNonSessionUser.

@Test
public void rolesUpdated_WhenAssignAllUsersToRole_WithSessionAndNonSessionUser() {
    ITenant tenant = mock(ITenant.class);
    doReturn(tenant).when(resource).getTenant(DEFAULT_STRING);
    final IPentahoUser sessionUser = new MockPentahoUser(tenant, SESSION_USER_NAME, DEFAULT_STRING, DEFAULT_STRING, true);
    final IPentahoUser nonSessionUser = new MockPentahoUser(tenant, NON_SESSION_USER_NAME, DEFAULT_STRING, DEFAULT_STRING, true);
    List<IPentahoUser> users = Arrays.asList(sessionUser, nonSessionUser);
    doReturn(users).when(userRoleDao).getUsers(tenant);
    resource.assignAllUsersToRole(DEFAULT_STRING, ROLE_NAME_DEVELOPER);
    verify(resource).updateRolesForCurrentSession();
}
Also used : MockPentahoUser(org.pentaho.test.mock.MockPentahoUser) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 17 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class JcrRepositoryFileAclDao method internalUpdateAcl.

protected RepositoryFileAcl internalUpdateAcl(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final RepositoryFileAcl acl) throws RepositoryException {
    if (isKioskEnabled()) {
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
    }
    DefaultPermissionConversionHelper permissionConversionHelper = new DefaultPermissionConversionHelper(session);
    Node node = session.getNodeByIdentifier(fileId.toString());
    if (node == null) {
        throw new RepositoryException(Messages.getInstance().getString("JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND", // $NON-NLS-1$
        fileId.toString()));
    }
    String absPath = node.getPath();
    AccessControlManager acMgr = session.getAccessControlManager();
    AccessControlList acList = getAccessControlList(acMgr, absPath);
    // clear all entries
    AccessControlEntry[] acEntries = acList.getAccessControlEntries();
    for (int i = 0; i < acEntries.length; i++) {
        acList.removeAccessControlEntry(acEntries[i]);
    }
    JcrRepositoryFileAclUtils.setAclMetadata(session, absPath, acList, new AclMetadata(acl.getOwner().getName(), acl.isEntriesInheriting()));
    // add entries to now empty list but only if not inheriting; force user to start with clean slate
    boolean adminPrincipalExist = false;
    ITenant principalTenant = null;
    if (!acl.isEntriesInheriting()) {
        for (RepositoryFileAce ace : acl.getAces()) {
            Principal principal = null;
            if (RepositoryFileSid.Type.ROLE == ace.getSid().getType()) {
                String principalName = JcrTenantUtils.getRoleNameUtils().getPrincipleName(ace.getSid().getName());
                if (tenantAdminAuthorityName.equals(principalName)) {
                    adminPrincipalExist = true;
                }
                principal = new SpringSecurityRolePrincipal(JcrTenantUtils.getTenantedRole(ace.getSid().getName()));
            } else {
                principal = new SpringSecurityUserPrincipal(JcrTenantUtils.getTenantedUser(ace.getSid().getName()));
            }
            acList.addAccessControlEntry(principal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, ace.getPermissions()));
        }
        if (!adminPrincipalExist) {
            if (acl.getAces() != null && acl.getAces().size() > 0) {
                principalTenant = JcrTenantUtils.getRoleNameUtils().getTenant(acl.getAces().get(0).getSid().getName());
            }
            if (principalTenant == null || principalTenant.getId() == null) {
                principalTenant = JcrTenantUtils.getTenant();
            }
            List<RepositoryFilePermission> permissionList = new ArrayList<RepositoryFilePermission>();
            permissionList.add(RepositoryFilePermission.ALL);
            Principal adminPrincipal = new SpringSecurityRolePrincipal(JcrTenantUtils.getRoleNameUtils().getPrincipleId(principalTenant, tenantAdminAuthorityName));
            acList.addAccessControlEntry(adminPrincipal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, EnumSet.copyOf(permissionList)));
        }
    }
    acMgr.setPolicy(absPath, acList);
    session.save();
    return getAcl(fileId);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) Node(javax.jcr.Node) AclMetadata(org.pentaho.platform.repository2.unified.jcr.IAclMetadataStrategy.AclMetadata) ArrayList(java.util.ArrayList) AccessControlEntry(javax.jcr.security.AccessControlEntry) RepositoryException(javax.jcr.RepositoryException) ITenant(org.pentaho.platform.api.mt.ITenant) SpringSecurityRolePrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityRolePrincipal) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) SpringSecurityRolePrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityRolePrincipal) SpringSecurityUserPrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityUserPrincipal) Principal(java.security.Principal) SpringSecurityUserPrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityUserPrincipal)

Example 18 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class JcrTenantUtils method getTenantedUser.

public static String getTenantedUser(String username) {
    if (username != null && !username.equals(getRepositoryAdminUserName()) && getUserNameUtils() != null) {
        ITenant tenant = getUserNameUtils().getTenant(username);
        if (tenant == null || tenant.getId() == null) {
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
            if (tenantId == null) {
                tenantId = getDefaultTenantPath();
            }
            tenant = new Tenant(tenantId, true);
            return getUserNameUtils().getPrincipleId(tenant, username);
        } else {
            return username;
        }
    } else {
        return username;
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 19 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class JcrTenantUtils method getTenantedRole.

public static String getTenantedRole(String principal) {
    if (principal != null && !principal.equals("administrators") && getRoleNameUtils() != null) {
        ITenant tenant = getRoleNameUtils().getTenant(principal);
        if (tenant == null || tenant.getId() == null) {
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
            if (tenantId == null) {
                tenantId = getDefaultTenantPath();
            }
            tenant = new Tenant(tenantId, true);
            return getRoleNameUtils().getPrincipleId(tenant, principal);
        } else {
            return principal;
        }
    } else {
        return principal;
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 20 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class AbstractRepositoryTenantManager method getChildTenants.

public List<ITenant> getChildTenants(Session session, final ITenant parentTenant, final boolean includeDisabledTenants) throws RepositoryException {
    List<ITenant> children = new ArrayList<ITenant>();
    List<RepositoryFile> allChildren = JcrRepositoryFileUtils.getChildren(session, new PentahoJcrConstants(session), pathConversionHelper, null, getTenantRootFolder(session, parentTenant).getId(), null);
    for (RepositoryFile repoFile : allChildren) {
        Map<String, Serializable> metadata = JcrRepositoryFileUtils.getFileMetadata(session, repoFile.getId());
        if (metadata.containsKey(ITenantManager.TENANT_ROOT) && (Boolean) metadata.get(ITenantManager.TENANT_ROOT)) {
            Tenant tenant = new Tenant(repoFile.getPath(), isTenantEnabled(session, repoFile.getId()));
            if (includeDisabledTenants || tenant.isEnabled()) {
                children.add(new Tenant(pathConversionHelper.relToAbs(repoFile.getPath()), isTenantEnabled(session, repoFile.getId())));
            }
        }
    }
    return children;
}
Also used : Serializable(java.io.Serializable) ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) PentahoJcrConstants(org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Aggregations

ITenant (org.pentaho.platform.api.mt.ITenant)174 Test (org.junit.Test)120 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)86 Matchers.anyString (org.mockito.Matchers.anyString)47 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)27 ArrayList (java.util.ArrayList)21 Tenant (org.pentaho.platform.core.mt.Tenant)21 ByteArrayInputStream (java.io.ByteArrayInputStream)17 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)17 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)15 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)14 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)14 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)12 WebResource (com.sun.jersey.api.client.WebResource)11 JerseyTest (com.sun.jersey.test.framework.JerseyTest)11 ITenantedPrincipleNameResolver (org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)10 SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)10 Serializable (java.io.Serializable)9 Date (java.util.Date)9 HashMap (java.util.HashMap)9