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;
}
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);
}
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);
}
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);
}
}
}
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);
}
}
}
Aggregations