Search in sources :

Example 1 with RepositoryFile

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

the class PurRepository_DatabaseNames_Test method setUp.

@Before
public void setUp() throws Exception {
    RepositoryFile dbFile = file(EXISTING_DB);
    unifiedRepository = mock(IUnifiedRepository.class);
    when(unifiedRepository.getFile(EXISTING_DB_PATH)).thenReturn(dbFile);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository = new PurRepository();
    purRepository.init(mockMeta);
    purRepository.setTest(unifiedRepository);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Example 2 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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 3 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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 4 with RepositoryFile

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

the class StreamToNodeConvertersPrivateDatabasesTest method getData.

@Parameterized.Parameters
public static List<Object[]> getData() throws Exception {
    RepositoryFile repositoryFile = new RepositoryFile.Builder("test file").build();
    IUnifiedRepository pur = mock(IUnifiedRepository.class);
    when(pur.getFileById(FILE_ID)).thenReturn(repositoryFile);
    TransMeta transMeta = new TransMeta();
    JobMeta jobMeta = new JobMeta();
    Repository repository = mock(Repository.class);
    when(repository.loadTransformation(any(StringObjectId.class), anyString())).thenReturn(transMeta);
    when(repository.loadJob(any(StringObjectId.class), anyString())).thenReturn(jobMeta);
    StreamToTransNodeConverter transNodeConverter = new StreamToTransNodeConverter(pur);
    transNodeConverter = spy(transNodeConverter);
    doReturn(repository).when(transNodeConverter).connectToRepository();
    StreamToJobNodeConverter jobNodeConverter = new StreamToJobNodeConverter(pur);
    jobNodeConverter = spy(jobNodeConverter);
    doReturn(repository).when(jobNodeConverter).connectToRepository();
    Object[] trans = { transNodeConverter, TransMeta.XML_TAG, transMeta };
    Object[] job = { jobNodeConverter, JobMeta.XML_TAG, jobMeta };
    return asList(trans, job);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) TransMeta(org.pentaho.di.trans.TransMeta) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 5 with RepositoryFile

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

the class PurRepositoryTestingUtils method createUserHomeDirCallback.

/**
 * Creates a callback for setting up {@code username}'s home folder. In the folder exists, noting is done. If
 * {@code tenant}'s home folder does not exist nothing is done.
 *
 * @param tenant
 *          tenant
 * @param username
 *          user name
 * @param principleId
 *          user principle's id
 * @param authenticatedRoleId
 *          user authenticated role's id
 * @param fileDao
 *          file dao
 * @return callback for performing the action
 */
static TransactionCallbackWithoutResult createUserHomeDirCallback(final ITenant tenant, final String username, final String principleId, final String authenticatedRoleId, final IRepositoryFileDao fileDao) {
    return new TransactionCallbackWithoutResult() {

        public void doInTransactionWithoutResult(final TransactionStatus status) {
            String tenantRootFolderPath = ServerRepositoryPaths.getTenantRootFolderPath(tenant);
            RepositoryFile tenantRootFolder = fileDao.getFileByAbsolutePath(tenantRootFolderPath);
            if (tenantRootFolder == null) {
                return;
            }
            String userHomeFolderPath = ServerRepositoryPaths.getUserHomeFolderPath(tenant, username);
            RepositoryFile userHomeFolder = fileDao.getFileByAbsolutePath(userHomeFolderPath);
            if (userHomeFolder != null) {
                return;
            }
            RepositoryFileSid userSid = new RepositoryFileSid(principleId);
            String tenantHomeFolderPath = ServerRepositoryPaths.getTenantHomeFolderPath(tenant);
            RepositoryFile tenantHomeFolder = fileDao.getFileByAbsolutePath(tenantHomeFolderPath);
            RepositoryFileAcl.Builder aclsForUserHomeFolder;
            if (tenantHomeFolder == null) {
                RepositoryFileSid ownerSid = new RepositoryFileSid(principleId, RepositoryFileSid.Type.USER);
                RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid(authenticatedRoleId, RepositoryFileSid.Type.ROLE);
                RepositoryFileAcl.Builder aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ));
                aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
                tenantHomeFolder = fileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()).folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder");
            } else {
                RepositoryFileSid ownerSid = new RepositoryFileSid(principleId, RepositoryFileSid.Type.USER);
                aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
            }
            fileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), "user home folder");
        }
    };
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) TransactionStatus(org.springframework.transaction.TransactionStatus) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32