Search in sources :

Example 6 with SessionFactory

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

the class UIEERepositoryDirectoryIT 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 7 with SessionFactory

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

the class DefaultUnifiedRepositoryBase method setApplicationContext.

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    SessionFactory jcrSessionFactory = (SessionFactory) applicationContext.getBean("jcrSessionFactory");
    testJcrTemplate = new JcrTemplate(jcrSessionFactory);
    testJcrTemplate.setAllowCreate(true);
    testJcrTemplate.setExposeNativeSession(true);
    jcrTemplate = (JcrTemplate) applicationContext.getBean("jcrTemplate");
    repositoryAdminUsername = (String) applicationContext.getBean("repositoryAdminUsername");
    singleTenantAdminUserName = (String) applicationContext.getBean("singleTenantAdminUserName");
    superAdminRoleName = (String) applicationContext.getBean("superAdminAuthorityName");
    sysAdminUserName = (String) applicationContext.getBean("superAdminUserName");
    tenantAuthenticatedRoleName = (String) applicationContext.getBean("singleTenantAuthenticatedAuthorityName");
    tenantAdminRoleName = (String) applicationContext.getBean("singleTenantAdminAuthorityName");
    tenantManager = (ITenantManager) applicationContext.getBean("tenantMgrProxy");
    pathConversionHelper = (IPathConversionHelper) applicationContext.getBean("pathConversionHelper");
    roleBindingDao = (IRoleAuthorizationPolicyRoleBindingDao) applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTxn");
    roleBindingDaoTarget = (IRoleAuthorizationPolicyRoleBindingDao) applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTarget");
    authorizationPolicy = (IAuthorizationPolicy) applicationContext.getBean("authorizationPolicy");
    repo = (IUnifiedRepository) applicationContext.getBean("unifiedRepository");
    userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDao");
    jcrTransactionTemplate = (TransactionTemplate) applicationContext.getBean("jcrTransactionTemplate");
    defaultBackingRepositoryLifecycleManager = (IBackingRepositoryLifecycleManager) applicationContext.getBean("defaultBackingRepositoryLifecycleManager");
    repositoryFileDao = (IRepositoryFileDao) applicationContext.getBean("repositoryFileDao");
    repositoryFileAclDao = (IRepositoryFileAclDao) applicationContext.getBean("repositoryFileAclDao");
    testUserRoleDao = userRoleDao;
    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 8 with SessionFactory

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

the class PentahoTransactionManagerTest method isCreatingTransaction.

@Test
public void isCreatingTransaction() throws Exception {
    PentahoTransactionManager transactionManager = new PentahoTransactionManager();
    SessionFactory sessionFactory = mock(SessionFactory.class);
    XASession xaSession = mock(XASession.class);
    when(xaSession.getXAResource()).thenReturn(mock(XAResource.class));
    transactionManager.setSessionFactory(sessionFactory);
    TransactionDefinition transactionDefinition = mock(TransactionDefinition.class);
    when(transactionDefinition.getIsolationLevel()).thenReturn(-1);
    // All of our assertions must be done while doBegin is being called
    when(sessionFactory.getSession()).then(invocation -> {
        List<Integer> transDefs = Arrays.asList(TransactionDefinition.PROPAGATION_NESTED, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        for (Integer transDef : transDefs) {
            when(transactionDefinition.getPropagationBehavior()).thenReturn(transDef);
            assertTrue(transactionManager.isCreatingTransaction());
        }
        return xaSession;
    });
    // Calls doBegin
    transactionManager.getTransaction(transactionDefinition);
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) TransactionDefinition(org.springframework.transaction.TransactionDefinition) XAResource(javax.transaction.xa.XAResource) XASession(org.apache.jackrabbit.api.XASession) Test(org.junit.Test)

Example 9 with SessionFactory

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

the class PentahoTransactionManagerTest method getTransactionDefinition.

@Test
public void getTransactionDefinition() throws Exception {
    PentahoTransactionManager transactionManager = new PentahoTransactionManager();
    SessionFactory sessionFactory = mock(SessionFactory.class);
    XASession xaSession = mock(XASession.class);
    when(xaSession.getXAResource()).thenReturn(mock(XAResource.class));
    transactionManager.setSessionFactory(sessionFactory);
    TransactionDefinition transactionDefinition = mock(TransactionDefinition.class);
    when(transactionDefinition.getIsolationLevel()).thenReturn(-1);
    // Main assertion. While doBegin is being called, the transactionDefinition can be reached.
    AtomicBoolean wasAvailable = new AtomicBoolean(false);
    when(sessionFactory.getSession()).then(invocation -> {
        assertEquals(transactionDefinition, transactionManager.getTransactionDefinition());
        wasAvailable.set(true);
        return xaSession;
    });
    transactionManager.getTransaction(transactionDefinition);
    assertTrue(wasAvailable.get());
    // after life of doBegin call the definition is not available
    assertNull(transactionManager.getTransactionDefinition());
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) TransactionDefinition(org.springframework.transaction.TransactionDefinition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) XAResource(javax.transaction.xa.XAResource) XASession(org.apache.jackrabbit.api.XASession) Test(org.junit.Test)

Example 10 with SessionFactory

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

the class UserRoleDaoEncodeIT 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");
    authenticatedRoleName = (String) applicationContext.getBean("singleTenantAuthenticatedAuthorityName");
    adminRoleName = (String) applicationContext.getBean("singleTenantAdminAuthorityName");
    roleBindingDaoTarget = (IRoleAuthorizationPolicyRoleBindingDao) applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTarget");
    sysAdminRoleName = (String) applicationContext.getBean("superAdminAuthorityName");
    sysAdminUserName = (String) applicationContext.getBean("superAdminUserName");
    authorizationPolicy = (IAuthorizationPolicy) applicationContext.getBean("authorizationPolicy");
    tenantManager = (ITenantManager) applicationContext.getBean("tenantMgrProxy");
    repositoryFileDao = (IRepositoryFileDao) applicationContext.getBean("repositoryFileDao");
    userRoleDaoProxy = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
    userRoleDaoTestProxy = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
    tenantedUserNameUtils = (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedUserNameUtils");
    tenantedRoleNameUtils = (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedRoleNameUtils");
    TestPrincipalProvider.userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
    TestPrincipalProvider.adminCredentialsStrategy = (CredentialsStrategy) applicationContext.getBean("jcrAdminCredentialsStrategy");
    TestPrincipalProvider.repository = (Repository) applicationContext.getBean("jcrRepository");
    jcrTemplate = (JcrTemplate) applicationContext.getBean("jcrTemplate");
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) JcrTemplate(org.springframework.extensions.jcr.JcrTemplate)

Aggregations

SessionFactory (org.springframework.extensions.jcr.SessionFactory)11 JcrTemplate (org.springframework.extensions.jcr.JcrTemplate)9 XAResource (javax.transaction.xa.XAResource)2 XASession (org.apache.jackrabbit.api.XASession)2 Test (org.junit.Test)2 TransactionDefinition (org.springframework.transaction.TransactionDefinition)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)1 ITenantManager (org.pentaho.platform.api.mt.ITenantManager)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1