Search in sources :

Example 6 with IPentahoSession

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

the class SqlMetadataQueryExec method getConnection.

protected SQLConnection getConnection(DatabaseMeta databaseMeta) {
    // use the connection specified in the query
    SQLConnection localConnection = null;
    try {
        IPentahoSession session = PentahoSessionHolder.getSession();
        if (databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI) {
            String jndiName = databaseMeta.getDatabaseName();
            if (jndiName != null) {
                SimpleLogger simpleLogger = new SimpleLogger(this);
                localConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, jndiName, session, simpleLogger);
            }
        }
        if (localConnection == null) {
            String driver = databaseMeta.getDriverClass();
            String userId = databaseMeta.getUsername();
            String password = databaseMeta.getPassword();
            String connectionInfo = databaseMeta.getURL();
            if (StringUtils.isEmpty(databaseMeta.getDatabaseName())) {
                String genericDBMetaDriver = databaseMeta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, "");
                if (!StringUtils.isEmpty(genericDBMetaDriver)) {
                    driver = genericDBMetaDriver;
                }
                String genericDBMetaURL = databaseMeta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, "");
                if (!StringUtils.isEmpty(genericDBMetaURL)) {
                    connectionInfo = genericDBMetaURL;
                }
            }
            SimpleLogger simpleLogger = new SimpleLogger(this);
            localConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, driver, connectionInfo, userId, password, session, simpleLogger);
        }
        // localConnection = getConnection(localConnection);
        return localConnection;
    } catch (Exception e) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getErrorString("MetadataQueryComponent.ERROR_0006_EXECUTE_FAILED"), e);
    }
    return null;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) SimpleLogger(org.pentaho.platform.util.logging.SimpleLogger) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 7 with IPentahoSession

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

the class JcrRepositoryFileUtilsTest method testCheckinNearestVersionableNodeIfNecessary.

@Test
public void testCheckinNearestVersionableNodeIfNecessary() throws Exception {
    String versionMessage = "Version message";
    String username = "admin";
    Date curDate = new Date();
    Node mockNode = mock(Node.class);
    Node parentNode = mock(Node.class);
    IPentahoSession pentahoSession = mock(IPentahoSession.class);
    when(pentahoSession.getName()).thenReturn(username);
    JcrRepositoryFileUtils.setRepositoryVersionManager(repositoryVersionManagerMockTrue);
    VersionManagerImpl versionManager = mock(VersionManagerImpl.class);
    when(workspaceMock.getVersionManager()).thenReturn(versionManager);
    when(mockNode.getParent()).thenReturn(parentNode);
    PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(sessionMock);
    when(mockNode.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())).thenReturn(Boolean.TRUE);
    PentahoSessionHolder.setSession(pentahoSession);
    JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(sessionMock, pentahoJcrConstants, mockNode, versionMessage, curDate, true);
    Calendar cal = Calendar.getInstance();
    if (curDate != null) {
        cal.setTime(curDate);
    } else {
        cal.setTime(new Date());
    }
    // validate checkin was called
    verify(versionManager).checkin(mockNode.getPath(), cal);
}
Also used : VersionManagerImpl(org.apache.jackrabbit.core.VersionManagerImpl) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(javax.jcr.Node) Calendar(java.util.Calendar) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with IPentahoSession

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

the class TenantUtils method getCurrentTenant.

/**
 * Returns the tenant ID of the current user.
 */
public static ITenant getCurrentTenant() {
    IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
    if (pentahoSession == null) {
        throw new IllegalStateException();
    }
    String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
    if (tenantId == null) {
        ITenantedPrincipleNameResolver tenantedUserNameUtils = PentahoSystem.get(ITenantedPrincipleNameResolver.class, "tenantedUserNameUtils", pentahoSession);
        if (tenantedUserNameUtils != null) {
            ITenant tenant = tenantedUserNameUtils.getTenant(pentahoSession.getId());
            pentahoSession.setAttribute(IPentahoSession.TENANT_ID_KEY, tenant.getId());
            return new Tenant(tenant.getId(), true);
        }
    }
    return new Tenant(tenantId, true);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)

Example 9 with IPentahoSession

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

the class PentahoAuthenticationSuccessListener method onApplicationEvent.

// ~ Methods
// =========================================================================================================
public void onApplicationEvent(final ApplicationEvent event) {
    if (event instanceof AuthenticationSuccessEvent) {
        // $NON-NLS-1$
        logger.debug("received " + event.getClass().getSimpleName());
        // $NON-NLS-1$
        logger.debug("synchronizing current IPentahoSession with SecurityContext");
        try {
            Authentication authentication = ((AbstractAuthenticationEvent) event).getAuthentication();
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            Assert.notNull(pentahoSession, "PentahoSessionHolder doesn't have a session");
            pentahoSession.setAuthenticated(authentication.getName());
            pentahoSession.setAttribute(IPentahoSession.SESSION_ROLES, authentication.getAuthorities());
            // audit session creation
            AuditHelper.audit(pentahoSession.getId(), pentahoSession.getName(), pentahoSession.getActionName(), pentahoSession.getObjectName(), "", MessageTypes.SESSION_START, "", "", 0, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            null);
            logger.info("The user \"" + pentahoSession.getName() + "\"" + " connected to server with session ID " + pentahoSession.getId());
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
}
Also used : Authentication(org.springframework.security.core.Authentication) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) AbstractAuthenticationEvent(org.springframework.security.authentication.event.AbstractAuthenticationEvent)

Example 10 with IPentahoSession

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

the class PentahoSessionStartupAuthenticationSuccessListener method onApplicationEvent.

// ~ Methods
// =========================================================================================================
public void onApplicationEvent(final ApplicationEvent event) {
    if (event instanceof InteractiveAuthenticationSuccessEvent) {
        // $NON-NLS-1$
        logger.debug("received InteractiveAuthenticationSuccessEvent");
        // $NON-NLS-1$
        logger.debug("calling PentahoSystem.sessionStartup");
        try {
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            Assert.notNull(pentahoSession, "PentahoSessionHolder doesn't have a session");
            IParameterProvider sessionParameters = new PentahoSessionParameterProvider(pentahoSession);
            PentahoSystem.sessionStartup(pentahoSession, sessionParameters);
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
}
Also used : InteractiveAuthenticationSuccessEvent(org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

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