Search in sources :

Example 1 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-kettle by pentaho.

the class RepositoryFactoryTest method testDefaultFactoryConnect.

@Test
public void testDefaultFactoryConnect() throws Exception {
    IRepositoryFactory.DefaultRepositoryFactory repositoryFactory = new IRepositoryFactory.DefaultRepositoryFactory();
    repositoryFactory.setRepositoryId("KettleFileRepository");
    IPentahoSession session = new StandaloneSession("joe");
    PentahoSessionHolder.setSession(session);
    repositoryFactory.connect("foo");
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Test(org.junit.Test)

Example 2 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession 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 IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-kettle by pentaho.

the class PurRepositoryIT method createUserHomeFolder.

protected 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);
    String principleId = userNameUtils.getPrincipleId(theTenant, theUsername);
    String authenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName);
    TransactionCallbackWithoutResult callback = PurRepositoryTestingUtils.createUserHomeDirCallback(theTenant, theUsername, principleId, authenticatedRoleId, repositoryFileDao);
    try {
        txnTemplate.execute(callback);
    } finally {
        // Switch our identity back to the original user.
        PurRepositoryTestingUtils.setSession(origPentahoSession, origAuthentication);
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Authentication(org.springframework.security.core.Authentication) Matchers.anyString(org.mockito.Matchers.anyString) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 4 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-kettle by pentaho.

the class PurRepositoryTestBase method createUserHomeFolder.

private void createUserHomeFolder(final ITenant theTenant, final String theUsername) {
    IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
    Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
    String principleId = userNameUtils.getPrincipleId(theTenant, theUsername);
    String authenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRole);
    TransactionCallbackWithoutResult callback = PurRepositoryTestingUtils.createUserHomeDirCallback(theTenant, theUsername, principleId, authenticatedRoleId, repositoryFileDao);
    try {
        loginAsRepositoryAdmin();
        txnTemplate.execute(callback);
    } finally {
        PurRepositoryTestingUtils.setSession(origPentahoSession, origAuthentication);
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Authentication(org.springframework.security.core.Authentication) Matchers.anyString(org.mockito.Matchers.anyString) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 5 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-metaverse by pentaho.

the class RepositoryLocatorTest method setUp.

@Before
public void setUp() throws Exception {
    RepositoryLocator loc = new RepositoryLocator() {

        @Override
        protected IUnifiedRepository getUnifiedRepository(IPentahoSession session) throws Exception {
            return null;
        }

        @Override
        protected Object getContents(RepositoryFile locatedItem) throws Exception {
            return null;
        }

        /**
         * Returns the locator node for this locator. The locator node is the node in the metaverse
         * that represents this locator. It is used to create a link from this locator to the documents
         * that are found by/within it.
         *
         * @return The locator node in the metaverse
         */
        @Override
        public IMetaverseNode getLocatorNode() {
            return new MetaverseNode(mock(Vertex.class));
        }

        @Override
        public URI getRootUri() {
            return null;
        }
    };
    loc.setMetaverseBuilder(metaverseBuilder);
    baseLocator = spy(loc);
    when(baseLocator.getMetaverseBuilder()).thenReturn(metaverseBuilder);
    when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(metaverseObjectFactory);
    when(metaverseObjectFactory.createDocumentObject()).thenReturn(new MetaverseDocument());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaverseDocument(org.pentaho.metaverse.api.MetaverseDocument) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Before(org.junit.Before)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10