Search in sources :

Example 1 with JcrTemplate

use of org.springframework.extensions.jcr.JcrTemplate in project pentaho-kettle by pentaho.

the class PurRepositoryIT method setApplicationContext.

@Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
    SessionFactory jcrSessionFactory = (SessionFactory) applicationContext.getBean("jcrSessionFactory");
    testJcrTemplate = new JcrTemplate(jcrSessionFactory);
    testJcrTemplate.setAllowCreate(true);
    testJcrTemplate.setExposeNativeSession(true);
    repositoryAdminUsername = (String) applicationContext.getBean("repositoryAdminUsername");
    superAdminRoleName = (String) applicationContext.getBean("superAdminAuthorityName");
    sysAdminUserName = (String) applicationContext.getBean("superAdminUserName");
    tenantAuthenticatedRoleName = (String) applicationContext.getBean("singleTenantAuthenticatedAuthorityName");
    singleTenantAdminRoleName = (String) applicationContext.getBean("singleTenantAdminAuthorityName");
    tenantManager = (ITenantManager) applicationContext.getBean("tenantMgrProxy");
    roleBindingDaoTarget = (IRoleAuthorizationPolicyRoleBindingDao) applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTarget");
    authorizationPolicy = (IAuthorizationPolicy) applicationContext.getBean("authorizationPolicy");
    repo = (IUnifiedRepository) applicationContext.getBean("unifiedRepository");
    userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDao");
    repositoryFileDao = (IRepositoryFileDao) applicationContext.getBean("repositoryFileDao");
    testUserRoleDao = userRoleDao;
    repositoryLifecyleManager = (IBackingRepositoryLifecycleManager) applicationContext.getBean("defaultBackingRepositoryLifecycleManager");
    txnTemplate = (TransactionTemplate) applicationContext.getBean("jcrTransactionTemplate");
    TestPrincipalProvider.userRoleDao = testUserRoleDao;
    TestPrincipalProvider.adminCredentialsStrategy = (CredentialsStrategy) applicationContext.getBean("jcrAdminCredentialsStrategy");
    TestPrincipalProvider.repository = (Repository) applicationContext.getBean("jcrRepository");
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) JcrTemplate(org.springframework.extensions.jcr.JcrTemplate)

Example 2 with JcrTemplate

use of org.springframework.extensions.jcr.JcrTemplate in project pentaho-kettle by pentaho.

the class PurRepositoryTestBase method setApplicationContext.

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    unifiedRepository = applicationContext.getBean("unifiedRepository", IUnifiedRepository.class);
    tenantManager = applicationContext.getBean("tenantMgrProxy", ITenantManager.class);
    userRoleDao = applicationContext.getBean("userRoleDao", IUserRoleDao.class);
    authorizationPolicy = applicationContext.getBean("authorizationPolicy", IAuthorizationPolicy.class);
    roleBindingDaoTarget = (IRoleAuthorizationPolicyRoleBindingDao) applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTarget");
    SessionFactory jcrSessionFactory = (SessionFactory) applicationContext.getBean("jcrSessionFactory");
    testJcrTemplate = new JcrTemplate(jcrSessionFactory);
    testJcrTemplate.setAllowCreate(true);
    testJcrTemplate.setExposeNativeSession(true);
    txnTemplate = applicationContext.getBean("jcrTransactionTemplate", TransactionTemplate.class);
    repositoryFileDao = (IRepositoryFileDao) applicationContext.getBean("repositoryFileDao");
    superAdminRole = applicationContext.getBean("superAdminAuthorityName", String.class);
    repositoryAdmin = applicationContext.getBean("repositoryAdminUsername", String.class);
    systemAdmin = (String) applicationContext.getBean("superAdminUserName");
    tenantAdminRole = applicationContext.getBean("singleTenantAdminAuthorityName", String.class);
    tenantAuthenticatedRole = applicationContext.getBean("singleTenantAuthenticatedAuthorityName", String.class);
    TestPrincipalProvider.userRoleDao = userRoleDao;
    TestPrincipalProvider.adminCredentialsStrategy = (CredentialsStrategy) applicationContext.getBean("jcrAdminCredentialsStrategy");
    TestPrincipalProvider.repository = (Repository) applicationContext.getBean("jcrRepository");
    doSetApplicationContext(applicationContext);
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) JcrTemplate(org.springframework.extensions.jcr.JcrTemplate) ITenantManager(org.pentaho.platform.api.mt.ITenantManager) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 3 with JcrTemplate

use of org.springframework.extensions.jcr.JcrTemplate in project pentaho-platform by pentaho.

the class DumpToFilePentahoSystemListener method startup.

// ~ Instance fields
// =================================================================================================
// ~ Constructors
// ====================================================================================================
// ~ Methods
// =========================================================================================================
@Override
public boolean startup(IPentahoSession pentahoSession) {
    Mode tmpMode = null;
    if (!StringUtils.hasText(fileName)) {
        fileName = System.getProperty(PROP_DUMP_TO_FILE);
        tmpMode = Mode.CUSTOM;
        if (fileName == null) {
            fileName = System.getProperty(PROP_DUMP_TO_FILE_SYSTEM_VIEW);
            tmpMode = Mode.SYS;
        }
        if (fileName == null) {
            fileName = System.getProperty(PROP_DUMP_TO_FILE_DOCUMENT_VIEW);
            tmpMode = Mode.DOC;
        }
    } else {
        tmpMode = Mode.CUSTOM;
    }
    final Mode mode = tmpMode;
    if (fileName != null) {
        // $NON-NLS-1$
        final JcrTemplate jcrTemplate = PentahoSystem.get(JcrTemplate.class, "jcrTemplate", pentahoSession);
        TransactionTemplate txnTemplate = // $NON-NLS-1$
        PentahoSystem.get(TransactionTemplate.class, "jcrTransactionTemplate", pentahoSession);
        // $NON-NLS-1$
        String repositoryAdminUsername = PentahoSystem.get(String.class, "repositoryAdminUsername", pentahoSession);
        // $NON-NLS-1$
        final String ZIP_EXTENSION = ".zip";
        // let the user know this is a zip
        if (!fileName.endsWith(ZIP_EXTENSION)) {
            fileName = fileName + ZIP_EXTENSION;
        }
        // $NON-NLS-1$
        logger.debug(String.format("dumping repository to file \"%s\"", fileName));
        ZipOutputStream tmpOut = null;
        try {
            tmpOut = new ZipOutputStream(new BufferedOutputStream(FileUtils.openOutputStream(new File(fileName))));
        } catch (IOException e) {
            IOUtils.closeQuietly(tmpOut);
            throw new RuntimeException(e);
        }
        final ZipOutputStream out = tmpOut;
        // stash existing session
        IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
        // run as repo super user
        PentahoSessionHolder.setSession(createRepositoryAdminPentahoSession(repositoryAdminUsername));
        try {
            txnTemplate.execute(new TransactionCallbackWithoutResult() {

                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    jcrTemplate.execute(new JcrCallback() {

                        public Object doInJcr(final Session session) throws RepositoryException, IOException {
                            switch(mode) {
                                case SYS:
                                    {
                                        final boolean SKIP_BINARY = false;
                                        final boolean NO_RECURSE = false;
                                        // $NON-NLS-1$
                                        out.putNextEntry(new ZipEntry("repository.xml"));
                                        // $NON-NLS-1$
                                        session.exportSystemView("/", out, SKIP_BINARY, NO_RECURSE);
                                        return null;
                                    }
                                case DOC:
                                    {
                                        final boolean SKIP_BINARY = false;
                                        final boolean NO_RECURSE = false;
                                        // $NON-NLS-1$
                                        out.putNextEntry(new ZipEntry("repository.xml"));
                                        // $NON-NLS-1$
                                        session.exportDocumentView("/", out, SKIP_BINARY, NO_RECURSE);
                                        return null;
                                    }
                                default:
                                    {
                                        // $NON-NLS-1$
                                        out.putNextEntry(new ZipEntry("repository.txt"));
                                        session.getRootNode().accept(new DumpToFileTraversingItemVisitor(out));
                                        return null;
                                    }
                            }
                        }
                    });
                }
            });
        } finally {
            // restore original session
            PentahoSessionHolder.setSession(origPentahoSession);
            IOUtils.closeQuietly(out);
        }
        // $NON-NLS-1$
        logger.debug(String.format("dumped repository to file \"%s\"", fileName));
    }
    return true;
}
Also used : JcrTemplate(org.springframework.extensions.jcr.JcrTemplate) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ZipEntry(java.util.zip.ZipEntry) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) IOException(java.io.IOException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) ZipOutputStream(java.util.zip.ZipOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Session(javax.jcr.Session) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 4 with JcrTemplate

use of org.springframework.extensions.jcr.JcrTemplate in project pentaho-platform by pentaho.

the class DirectoryResourceIT method setApplicationContext.

public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
    manager = (IBackingRepositoryLifecycleManager) applicationContext.getBean("backingRepositoryLifecycleManager");
    SessionFactory jcrSessionFactory = (SessionFactory) applicationContext.getBean("jcrSessionFactory");
    testJcrTemplate = new JcrTemplate(jcrSessionFactory);
    testJcrTemplate.setAllowCreate(true);
    testJcrTemplate.setExposeNativeSession(true);
    repositoryAdminUsername = (String) applicationContext.getBean("repositoryAdminUsername");
    authenticatedAuthorityName = (String) applicationContext.getBean("singleTenantAuthenticatedAuthorityName");
    adminAuthorityName = (String) applicationContext.getBean("singleTenantAdminAuthorityName");
    sysAdminAuthorityName = (String) applicationContext.getBean("superAdminAuthorityName");
    sysAdminUserName = (String) applicationContext.getBean("superAdminUserName");
    authorizationPolicy = (IAuthorizationPolicy) applicationContext.getBean("authorizationPolicy");
    roleBindingDaoTarget = (IRoleAuthorizationPolicyRoleBindingDao) applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTarget");
    tenantManager = (ITenantManager) applicationContext.getBean("tenantMgrTxn");
    repositoryFileDao = (IRepositoryFileDao) applicationContext.getBean("repositoryFileDao");
    userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
    tenantedUserNameUtils = (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedUserNameUtils");
    tenantedRoleNameUtils = (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedRoleNameUtils");
    repo = (IUnifiedRepository) applicationContext.getBean("unifiedRepository");
    TestPrincipalProvider.userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
    TestPrincipalProvider.adminCredentialsStrategy = (CredentialsStrategy) applicationContext.getBean("jcrAdminCredentialsStrategy");
    TestPrincipalProvider.repository = (Repository) applicationContext.getBean("jcrRepository");
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) JcrTemplate(org.springframework.extensions.jcr.JcrTemplate)

Example 5 with JcrTemplate

use of org.springframework.extensions.jcr.JcrTemplate in project pentaho-platform by pentaho.

the class FileResourceIT method setApplicationContext.

public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
    manager = (IBackingRepositoryLifecycleManager) applicationContext.getBean("backingRepositoryLifecycleManager");
    SessionFactory jcrSessionFactory = (SessionFactory) applicationContext.getBean("jcrSessionFactory");
    testJcrTemplate = new JcrTemplate(jcrSessionFactory);
    testJcrTemplate.setAllowCreate(true);
    testJcrTemplate.setExposeNativeSession(true);
    repositoryAdminUsername = (String) applicationContext.getBean("repositoryAdminUsername");
    authenticatedAuthorityName = (String) applicationContext.getBean("singleTenantAuthenticatedAuthorityName");
    adminAuthorityName = (String) applicationContext.getBean("singleTenantAdminAuthorityName");
    sysAdminAuthorityName = (String) applicationContext.getBean("superAdminAuthorityName");
    sysAdminUserName = (String) applicationContext.getBean("superAdminUserName");
    authorizationPolicy = (IAuthorizationPolicy) applicationContext.getBean("authorizationPolicy");
    roleBindingDaoTarget = (IRoleAuthorizationPolicyRoleBindingDao) applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTarget");
    tenantManager = (ITenantManager) applicationContext.getBean("tenantMgrTxn");
    repositoryFileDao = (IRepositoryFileDao) applicationContext.getBean("repositoryFileDao");
    userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
    tenantedUserNameUtils = (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedUserNameUtils");
    tenantedRoleNameUtils = (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedRoleNameUtils");
    repo = (IUnifiedRepository) applicationContext.getBean("unifiedRepository");
    TestPrincipalProvider.userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
    TestPrincipalProvider.adminCredentialsStrategy = (CredentialsStrategy) applicationContext.getBean("jcrAdminCredentialsStrategy");
    TestPrincipalProvider.repository = (Repository) applicationContext.getBean("jcrRepository");
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) JcrTemplate(org.springframework.extensions.jcr.JcrTemplate)

Aggregations

JcrTemplate (org.springframework.extensions.jcr.JcrTemplate)12 SessionFactory (org.springframework.extensions.jcr.SessionFactory)9 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 Session (javax.jcr.Session)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 JcrCallback (org.springframework.extensions.jcr.JcrCallback)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Workspace (javax.jcr.Workspace)1 VersionManagerImpl (org.apache.jackrabbit.core.VersionManagerImpl)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)1