Search in sources :

Example 1 with ITenant

use of org.pentaho.platform.api.mt.ITenant 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 ITenant

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

the class UIEERepositoryDirectoryIT method setUp.

@Before
public void setUp() throws Exception {
    this.testContextManager = new TestContextManager(getClass());
    this.testContextManager.prepareTestInstance(this);
    loginAsRepositoryAdmin();
    SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
    mp = new MicroPlatform();
    // used by DefaultPentahoJackrabbitAccessControlHelper
    mp.defineInstance("tenantedUserNameUtils", userNameUtils);
    mp.defineInstance("tenantedRoleNameUtils", roleNameUtils);
    mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
    mp.defineInstance(ITenantManager.class, tenantManager);
    mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
    mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
    mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(testJcrTemplate, repositoryFileDao));
    mp.defineInstance("useMultiByteEncoding", new Boolean(false));
    mp.defineInstance(IAclService.class, new Boolean(false));
    // Start the micro-platform
    mp.start();
    loginAsRepositoryAdmin();
    setAclManagement();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { singleTenantAdminRoleName });
    logout();
    super.setUp();
    KettleEnvironment.init();
    // programmatically register plugins, annotation based plugins do not get loaded unless
    // they are in kettle's plugins folder.
    JobEntryPluginType.getInstance().registerCustom(JobEntryAttributeTesterJobEntry.class, "test", "JobEntryAttributeTester", "JobEntryAttributeTester", "JobEntryAttributeTester", "");
    StepPluginType.getInstance().registerCustom(TransStepAttributeTesterTransStep.class, "test", "StepAttributeTester", "StepAttributeTester", "StepAttributeTester", "");
    repositoryMeta = new PurRepositoryMeta();
    repositoryMeta.setName("JackRabbit");
    repositoryMeta.setDescription("JackRabbit test repository");
    userInfo = new UserInfo(EXP_LOGIN, "password", EXP_USERNAME, "Apache Tomcat user", true);
    repository = new PurRepository();
    repository.init(repositoryMeta);
    login(sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, EXP_TENANT, singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous");
    userRoleDao.createUser(tenantAcme, EXP_LOGIN, "password", "", new String[] { singleTenantAdminRoleName });
    logout();
    setUpUser();
    PurRepository purRep = (PurRepository) repository;
    final PurRepositoryConnector purRepositoryConnector = new PurRepositoryConnector(purRep, (PurRepositoryMeta) repositoryMeta, purRep.getRootRef());
    purRep.setPurRepositoryConnector(purRepositoryConnector);
    purRep.setTest(repo);
    repository.connect(EXP_LOGIN, "password");
    login(EXP_LOGIN, tenantAcme, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    System.out.println("PUR NAME!!!: " + repo.getClass().getCanonicalName());
    RepositoryFile repositoryFile = repo.getFile(ClientRepositoryPaths.getPublicFolderPath());
    Serializable repositoryFileId = repositoryFile.getId();
    List<RepositoryFile> files = repo.getChildren(repositoryFileId);
    StringBuilder buf = new StringBuilder();
    for (RepositoryFile file : files) {
        buf.append("\n").append(file);
    }
    assertTrue("files not deleted: " + buf, files.isEmpty());
}
Also used : Serializable(java.io.Serializable) PurRepository(org.pentaho.di.repository.pur.PurRepository) PurRepositoryMeta(org.pentaho.di.repository.pur.PurRepositoryMeta) PurRepositoryConnector(org.pentaho.di.repository.pur.PurRepositoryConnector) UserInfo(org.pentaho.di.repository.UserInfo) TestContextManager(org.springframework.test.context.TestContextManager) ITenant(org.pentaho.platform.api.mt.ITenant) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileProxyFactory(org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory) Before(org.junit.Before)

Example 3 with ITenant

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

the class UIEERepositoryDirectoryIT method tearDown.

@After
public void tearDown() throws Exception {
    // null out fields to get back memory
    authorizationPolicy = null;
    login(sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    ITenant tenant = tenantManager.getTenant("/" + ServerRepositoryPaths.getPentahoRootFolderName() + "/" + TENANT_ID_ACME);
    if (tenant != null) {
        cleanupUserAndRoles(tenant);
    }
    login(sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    tenant = tenantManager.getTenant("/" + ServerRepositoryPaths.getPentahoRootFolderName() + "/" + TENANT_ID_DUFF);
    if (tenant != null) {
        cleanupUserAndRoles(tenant);
    }
    cleanupUserAndRoles(systemTenant);
    SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
    logout();
    repositoryAdminUsername = null;
    singleTenantAdminRoleName = null;
    tenantAuthenticatedRoleName = null;
    // roleBindingDao = null;
    authorizationPolicy = null;
    testJcrTemplate = null;
    // null out fields to get back memory
    tenantManager = null;
    repo = null;
    mp.stop();
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) After(org.junit.After)

Example 4 with ITenant

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

the class UIEERepositoryDirectoryIT method getTenant.

private ITenant getTenant(String principalId, boolean isUser) {
    ITenant tenant = null;
    ITenantedPrincipleNameResolver nameUtils = isUser ? userNameUtils : roleNameUtils;
    if (nameUtils != null) {
        tenant = nameUtils.getTenant(principalId);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    return tenant;
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)

Example 5 with ITenant

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

the class PurRepositoryIT method tearDown.

@After
public void tearDown() throws Exception {
    // null out fields to get back memory
    authorizationPolicy = null;
    login(sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    ITenant tenant = tenantManager.getTenant("/" + ServerRepositoryPaths.getPentahoRootFolderName() + "/" + TENANT_ID_ACME);
    if (tenant != null) {
        cleanupUserAndRoles(tenant);
    }
    login(sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    tenant = tenantManager.getTenant("/" + ServerRepositoryPaths.getPentahoRootFolderName() + "/" + TENANT_ID_DUFF);
    if (tenant != null) {
        cleanupUserAndRoles(tenant);
    }
    cleanupUserAndRoles(systemTenant);
    SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
    logout();
    repositoryAdminUsername = null;
    singleTenantAdminRoleName = null;
    tenantAuthenticatedRoleName = null;
    // roleBindingDao = null;
    authorizationPolicy = null;
    testJcrTemplate = null;
    // null out fields to get back memory
    tenantManager = null;
    repo = null;
    mp.stop();
    mp = null;
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) After(org.junit.After)

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