Search in sources :

Example 1 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-kettle by pentaho.

the class UIEERepositoryDirectoryIT method createUserHomeFolder.

private void createUserHomeFolder(final ITenant theTenant, final String theUsername) {
    IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
    Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
    StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername);
    pentahoSession.setAuthenticated(null, repositoryAdminUsername);
    PentahoSessionHolder.setSession(pentahoSession);
    try {
        txnTemplate.execute(new TransactionCallbackWithoutResult() {

            public void doInTransactionWithoutResult(final TransactionStatus status) {
                Builder aclsForUserHomeFolder = null;
                Builder aclsForTenantHomeFolder = null;
                ITenant tenant = null;
                String username = null;
                if (theTenant == null) {
                    tenant = getTenant(username, true);
                    username = getPrincipalName(theUsername, true);
                } else {
                    tenant = theTenant;
                    username = theUsername;
                }
                if (tenant == null || tenant.getId() == null) {
                    tenant = getCurrentTenant();
                }
                if (tenant == null || tenant.getId() == null) {
                    tenant = JcrTenantUtils.getDefaultTenant();
                }
                RepositoryFile userHomeFolder = null;
                String userId = userNameUtils.getPrincipleId(theTenant, username);
                final RepositoryFileSid userSid = new RepositoryFileSid(userId);
                RepositoryFile tenantHomeFolder = null;
                RepositoryFile tenantRootFolder = null;
                // Get the Tenant Root folder. If the Tenant Root folder does not exist then exit.
                tenantRootFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantRootFolderPath(theTenant));
                if (tenantRootFolder != null) {
                    // Try to see if Tenant Home folder exist
                    tenantHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantHomeFolderPath(theTenant));
                    if (tenantHomeFolder == null) {
                        String ownerId = userNameUtils.getPrincipleId(theTenant, username);
                        RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
                        String tenantAuthenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName);
                        RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid(tenantAuthenticatedRoleId, Type.ROLE);
                        aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ));
                        aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
                        tenantHomeFolder = repositoryFileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()).folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder");
                    } else {
                        String ownerId = userNameUtils.getPrincipleId(theTenant, username);
                        RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
                        aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
                    }
                    // now check if user's home folder exist
                    userHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username));
                    if (userHomeFolder == null) {
                        userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), // $NON-NLS-1$
                        "user home folder");
                    }
                }
            }
        });
    } finally {
        // Switch our identity back to the original user.
        PentahoSessionHolder.setSession(origPentahoSession);
        SecurityContextHolder.getContext().setAuthentication(origAuthentication);
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Builder(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder) TransactionStatus(org.springframework.transaction.TransactionStatus) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) ITenant(org.pentaho.platform.api.mt.ITenant) Builder(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder) Authentication(org.springframework.security.core.Authentication) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 2 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method getMetaStoreFolders.

private String getMetaStoreFolders(StringBuilder builder, RepositoryFile folder, int level) {
    String spaces = Const.rightPad(" ", level * 2);
    builder.append(spaces);
    if (folder.isFolder()) {
        builder.append("/");
    }
    builder.append(folder.getName()).append(Const.CR);
    for (RepositoryFile file : getChildren(folder.getId())) {
        getMetaStoreFolders(builder, file, level + 1);
    }
    return builder.toString();
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 3 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class RepositoryFileImportFileHandler method createFolderJustInTime.

public RepositoryFile createFolderJustInTime(String folderPath, String manifestKey) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    // The file doesn't exist and it is a folder. Create folder.
    getLogger().trace("Creating implied folder [" + folderPath + "]");
    final Serializable parentId = getParentId(folderPath);
    Assert.notNull(parentId);
    boolean isHidden;
    if (getImportSession().isFileHidden(manifestKey) == null) {
        isHidden = false;
    } else {
        isHidden = getImportSession().isFileHidden(manifestKey);
    }
    RepositoryFile.Builder builder = new RepositoryFile.Builder(RepositoryFilenameUtils.getName(folderPath)).path(RepositoryFilenameUtils.getPath(folderPath)).folder(true).hidden(isHidden);
    RepositoryFile repoFile = builder.build();
    RepositoryFileAcl repoAcl = getImportSession().processAclForFile(manifestKey);
    if (repoAcl != null) {
        repoFile = repository.createFolder(parentId, repoFile, repoAcl, null);
        RepositoryFileAcl repositoryFileAcl = null;
        try {
            repositoryFileAcl = getImportSession().getManifest().getExportManifestEntity(manifestKey).getRepositoryFileAcl();
        } catch (NullPointerException e) {
        // If npe then manifest entry is not defined which is likely so just ignore
        } catch (ExportManifestFormatException e) {
        // Same goes here
        }
        updateAcl(true, repoFile, repositoryFileAcl);
    } else {
        repoFile = repository.createFolder(parentId, repoFile, null);
    }
    getImportSession().getFoldersCreatedImplicitly().add(folderPath);
    return repoFile;
}
Also used : Serializable(java.io.Serializable) ExportManifestFormatException(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifestFormatException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 4 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class AbstractRepositoryTenantManager method createUserHomeFolder.

@Override
public RepositoryFile createUserHomeFolder(ITenant theTenant, String username) {
    Builder aclsForUserHomeFolder = null;
    Builder aclsForTenantHomeFolder = null;
    RepositoryFile userHomeFolder = null;
    RepositoryFile tenantHomeFolder = null;
    RepositoryFile tenantRootFolder = null;
    String userId = tenantedUserNameResolver.getPrincipleId(theTenant, username);
    final RepositoryFileSid userSid = new RepositoryFileSid(userId);
    username = JcrTenantUtils.getPrincipalName(username, true);
    if (theTenant == null) {
        theTenant = JcrTenantUtils.getTenant(username, true);
    }
    // Get the Tenant Root folder. If the Tenant Root folder does not exist then exit.
    tenantRootFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantRootFolderPath(theTenant));
    if (tenantRootFolder != null) {
        // Try to see if Tenant Home folder exist
        tenantHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantHomeFolderPath(theTenant));
        if (tenantHomeFolder == null) {
            String ownerId = tenantedUserNameResolver.getPrincipleId(theTenant, username);
            RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
            String tenantAuthenticatedRoleId = tenantedRoleNameResolver.getPrincipleId(theTenant, tenantAuthenticatedRoleName);
            RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid(tenantAuthenticatedRoleId, Type.ROLE);
            aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ));
            aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
            tenantHomeFolder = repositoryFileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()).folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder");
        } else {
            String ownerId = tenantedUserNameResolver.getPrincipleId(theTenant, username);
            RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
            aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
        }
        // now check if user's home folder exist
        userHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username));
        if (userHomeFolder == null) {
            userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), // $NON-NLS-1$
            "user home folder");
        }
    }
    return userHomeFolder;
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) Builder(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 5 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class RepositoryTenantManager method createTenant.

/*
   * (non-Javadoc)
   * 
   * @see org.pentaho.platform.api.repository2.unified.ITenantManager#createTenant(java.lang.String,
   * java.lang.String)
   */
@Override
public ITenant createTenant(final ITenant parentTenant, final String tenantName, final String tenantAdminRoleName, final String authenticatedRoleName, final String anonymousRoleName) {
    Tenant newTenant;
    String parentTenantFolder;
    if (parentTenant == null) {
        if (repositoryFileDao.getFileByAbsolutePath("/" + tenantName) != null) {
            return null;
        }
    } else {
        if (repositoryFileDao.getFileByAbsolutePath(parentTenant.getRootFolderAbsolutePath() + "/" + tenantName) != null) {
            return null;
        }
    }
    if (parentTenant == null) {
        newTenant = new Tenant(RepositoryFile.SEPARATOR + tenantName, true);
        parentTenantFolder = "/";
    } else {
        newTenant = new Tenant(parentTenant.getRootFolderAbsolutePath() + RepositoryFile.SEPARATOR + tenantName, true);
        parentTenantFolder = parentTenant.getRootFolderAbsolutePath();
    }
    String tenantCreatorId = PentahoSessionHolder.getSession().getName();
    RepositoryFile tenantRootFolder = createTenantFolder(parentTenant, tenantName, tenantCreatorId);
    userRoleDao.createRole(newTenant, tenantAdminRoleName, "", new String[0]);
    userRoleDao.createRole(newTenant, authenticatedRoleName, "", new String[0]);
    userRoleDao.createRole(newTenant, anonymousRoleName, "", new String[0]);
    roleBindingDao.setRoleBindings(newTenant, authenticatedRoleName, singleTenantAuthenticatedAuthorityRoleBindingList);
    String tenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId(newTenant, tenantAdminRoleName);
    RepositoryFileSid tenantAdminRoleSid = new RepositoryFileSid(tenantAdminRoleId, Type.ROLE);
    this.jcrTemplate.save();
    // tenant admin permissions on the root folder.
    if (parentTenant == null) {
        repositoryFileAclDao.addAce(tenantRootFolder.getId(), tenantAdminRoleSid, EnumSet.of(RepositoryFilePermission.ALL));
    } else {
        RepositoryFileAcl acl = repositoryFileAclDao.getAcl(tenantRootFolder.getId());
        Builder aclBuilder = new RepositoryFileAcl.Builder(acl).ace(tenantAdminRoleSid, EnumSet.of(RepositoryFilePermission.ALL));
        IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
        Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
        login(repositoryAdminUsername, tenantAdminRoleId);
        try {
            // Give all to Tenant Admin of all ancestors
            while (!parentTenantFolder.equals("/")) {
                ITenant tenant = new Tenant(parentTenantFolder, true);
                String parentTenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId(tenant, tenantAdminRoleName);
                RepositoryFileSid parentTenantAdminSid = new RepositoryFileSid(parentTenantAdminRoleId, Type.ROLE);
                aclBuilder.ace(parentTenantAdminSid, EnumSet.of(RepositoryFilePermission.ALL));
                parentTenantFolder = FilenameUtils.getFullPathNoEndSeparator(parentTenantFolder);
            }
            repositoryFileAclDao.updateAcl(aclBuilder.build());
        } catch (Throwable th) {
            th.printStackTrace();
        } finally {
            PentahoSessionHolder.setSession(origPentahoSession);
            SecurityContextHolder.getContext().setAuthentication(origAuthentication);
        }
    }
    try {
        RepositoryFileSid fileOwnerSid = new RepositoryFileSid(tenantCreatorId);
        createInitialTenantFolders(newTenant, tenantRootFolder, fileOwnerSid);
    } catch (Exception ex) {
        throw new RuntimeException("Error creating initial tenant folders", ex);
    }
    return newTenant;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Builder(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) ITenant(org.pentaho.platform.api.mt.ITenant) Builder(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder) Authentication(org.springframework.security.core.Authentication) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)15 ITenant (org.pentaho.platform.api.mt.ITenant)7 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)5 Builder (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder)4 SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)4 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Locale (java.util.Locale)2 Properties (java.util.Properties)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IPentahoLocale (org.pentaho.platform.api.locale.IPentahoLocale)2 PentahoLocale (org.pentaho.platform.repository2.locale.PentahoLocale)2 Authentication (org.springframework.security.core.Authentication)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2