@Override public Repository connect( String repositoryName ) throws KettleException { IPentahoSession session = PentahoSessionHolder.getSession(); if ( session == null ) { logger.debug( "No active Pentaho Session, attempting to load PDI repository unauthenticated." ); throw new KettleException( "Attempting to create PDI Repository with no Active PentahoSession. " + "This is not allowed." ); } ICacheManager cacheManager = PentahoSystem.getCacheManager( session ); String sessionName = session.getName(); Repository repository = (Repository) cacheManager.getFromRegionCache( REGION, sessionName ); if ( repository == null ) { logger.debug( "Repository not cached for user: " + sessionName + ". Creating new Repository." ); repository = delegate.connect( repositoryName ); if ( !cacheManager.cacheEnabled( REGION ) ) { cacheManager.addCacheRegion( REGION ); } cacheManager.putInRegionCache( REGION, sessionName, repository ); } else { logger.debug( "Repository was cached for user: " + sessionName ); } return repository; } }
@Override public Object getParameter( final String name ) { if ( "name".equals( name ) ) { //$NON-NLS-1$ return session.getName(); } return session.getAttribute( name ); }
private String getCorrectedKey( final IPentahoSession session, final String key ) { String sessionId = session.getId(); String newKey = null; if ( sessionId != null ) { newKey = sessionId + "\t" + key; //$NON-NLS-1$ } return newKey; }
&& PentahoSessionHolder.getSession().isAuthenticated() ) { if ( inProcess() ) { log.logDebug( BaseMessages.getString( PKG, "PurRepositoryConnector.ConnectInProgress.Begin" ) ); String name = PentahoSessionHolder.getSession().getName(); user1 = new EEUserInfo(); user1.setLogin( name );
public void genLogIdFromSession( final IPentahoSession sess ) { genLogIdFromInfo( sess.getId(), sess.getProcessId(), sess.getActionName() ); }
public void onApplicationEvent( final ApplicationEvent event ) { if ( event instanceof AuthenticationSuccessEvent ) { logger.debug( "received " + event.getClass().getSimpleName() ); //$NON-NLS-1$ logger.debug( "synchronizing current IPentahoSession with SecurityContext" ); //$NON-NLS-1$ 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, null ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ logger.info( "The user \"" + pentahoSession.getName() + "\"" + " connected to server with session ID " + pentahoSession.getId() ); } catch ( Exception e ) { logger.error( e.getLocalizedMessage(), e ); } } }
final ACLTemplate ancestorAcl, final ACLTemplate acl ) throws RepositoryException { if ( PentahoSessionHolder.getSession() == null || PentahoSessionHolder.getSession().getId() == null || PentahoSessionHolder.getSession().getId().trim().equals( "" ) ) { //$NON-NLS-1$ if ( log.isDebugEnabled() ) { log.debug( "no PentahoSession so no magic ACEs" ); //$NON-NLS-1$ new MagicPrincipal( JcrTenantUtils.getTenantedUser( PentahoSessionHolder.getSession().getName() ) );
public Object get( String name, ObjectFactory objectFactory ) { IPentahoSession session = SpringScopeSessionHolder.SESSION.get(); if ( session == null ) { return null; } Object object = session.getAttribute( name ); if ( object == null ) { object = objectFactory.getObject(); session.setAttribute( name, object ); } return object; }
session.setProcessId( processId ); session.setActionName( actionPath ); if ( runtimeRepository == null ) { String id = UUIDUtil.getUUIDAsString(); runtimeData = new SimpleRuntimeElement( id, session.getId(), IParameterProvider.SCOPE_SESSION ); } else { runtimeRepository.setLoggingLevel( loggingLevel ); runtimeRepository.newRuntimeElement( session.getId(), IParameterProvider.SCOPE_SESSION, !persisted ); } catch ( Throwable t ) { error( Messages.getInstance().getErrorString( "SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId ), t ); //$NON-NLS-1$ AuditHelper.audit( session.getId(), session.getName(), actionPath, getObjectName(), processId, MessageTypes.INSTANCE_START, instanceId, "", 0, this ); //$NON-NLS-1$
public void cancelLoad( IPentahoSession session ) { Trans trans = (Trans) session.getAttribute( TRANS_SESSION_ATTR ); trans.stopAll(); }
/** * 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 ); }
if ( !session.isAuthenticated() ) { return; Boolean startupActionsFired = (Boolean) session.getAttribute( "StartupActionsFired" ); if ( ( startupActionsFired == null ) || ( !startupActionsFired ) ) { try { session.removeAttribute( attributeName ); session.setAttribute( attributeName, data ); session.setAttribute( "StartupActionsFired", true );
throw new ActionValidationException( Messages.getInstance().getErrorString( "RuntimeContext.ERROR_0011_NO_VALID_ACTIONS" ), //$NON-NLS-1$ session.getName(), instanceId, getActionSequence().getSequenceName(), null ); } else { if ( IParameterProvider.SCOPE_SESSION.equals( returnParam.destinationName ) ) { session.setAttribute( returnParam.destinationParameter, returnParam.value ); if ( RuntimeContext.debug ) { debug( paramName + " - session - " + returnParam.destinationParameter ); //$NON-NLS-1$
/** * Hi-jacks the system for the named user. <p/> <p> This is for unit tests only. </p> */ @Override public void becomeUser( final String principalName, final IParameterProvider paramProvider ) { UserSession session = null; tenantedUserNameUtils = getTenantedUserNameUtils(); if ( tenantedUserNameUtils != null ) { session = new UserSession( principalName, null, false, paramProvider ); ITenant tenant = tenantedUserNameUtils.getTenant( principalName ); session.setAttribute( IPentahoSession.TENANT_ID_KEY, tenant.getId() ); session.setAuthenticated( tenant.getId(), principalName ); } else { session = new UserSession( principalName, null, false, paramProvider ); session.setAuthenticated( principalName ); } PentahoSessionHolder.setSession( session ); Authentication auth = createAuthentication( principalName ); // TODO We need to figure out how to inject this // Get the tenant id from the principle name and set it as an attribute of the pentaho session // Clearing the SecurityContext to force the subsequent call to getContext() to generate a new SecurityContext. // This prevents us from modifying the Authentication on a SecurityContext isntance which may be shared between // threads. PentahoSessionHolder.getSession().setAttribute( IPentahoSession.SESSION_ROLES, auth.getAuthorities() ); SecurityContextHolder.clearContext(); SecurityContextHolder.getContext().setAuthentication( auth ); PentahoSystem.sessionStartup( PentahoSessionHolder.getSession(), paramProvider ); }
pentahoSession.setAttribute( statsKey, stats ); CsvTransformGenerator csvTransformGenerator = new CsvTransformGenerator( modelInfo, AgileHelper.getDatabaseMeta() ); } finally { if ( pentahoSession != null ) { pentahoSession.destroy();
@Test public void testSessionStartup() throws ObjectFactoryException { int oldLogLevel = Logger.getLogLevel(); Logger.setLogLevel( ILogger.TRACE ); final ISolutionEngine engine = mock( ISolutionEngine.class ); pentahoObjectFactory = mock( IPentahoObjectFactory.class ); when( pentahoObjectFactory.objectDefined( anyString() ) ).thenReturn( true ); when( pentahoObjectFactory.get( this.anyClass(), anyString(), any( IPentahoSession.class ) ) ).thenAnswer( new Answer<Object>() { @Override public ISolutionEngine answer( InvocationOnMock invocation ) throws Throwable { return engine; } } ); PentahoSystem.registerObjectFactory( pentahoObjectFactory ); ISessionStartupAction action = mock( ISessionStartupAction.class ); when( action.getActionOutputScope() ).thenReturn( PentahoSystem.SCOPE_SESSION ); when( action.getSessionType() ).thenReturn( session.getClass().getName() ); when( session.isAuthenticated() ).thenReturn( true ); PentahoSystem.setSessionStartupActions( Arrays.asList( action ) ); PentahoSystem.sessionStartup( session, null ); System.out.flush(); assertNotNull( baos ); assertTrue( baos.toString().contains( "Process session startup actions" ) ); Logger.setLogLevel( oldLogLevel ); } /**
@Override public <T> T runAsUser( final String principalName, final IParameterProvider paramProvider, final Callable<T> callable ) throws Exception { IPentahoSession origSession = PentahoSessionHolder.getSession(); Authentication origAuth = SecurityContextHolder.getContext().getAuthentication(); try { becomeUser( principalName ); return callable.call(); } finally { IPentahoSession sessionToDestroy = PentahoSessionHolder.getSession(); if ( sessionToDestroy != null && sessionToDestroy != origSession ) { try { sessionToDestroy.destroy(); } catch ( Exception e ) { e.printStackTrace(); } } PentahoSessionHolder.setSession( origSession ); SecurityContextHolder.getContext().setAuthentication( origAuth ); } }
status = IRuntimeContext.RUNTIME_STATUS_FAILURE; long end = System.currentTimeMillis(); AuditHelper.audit( session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), Messages.getInstance().getErrorString( "SolutionEngine.ERROR_0007_ACTION_EXECUTION_FAILED" ), ( (float) ( end - start ) / 1000 ), this ); //$NON-NLS-1$ if ( instanceEnds ) { long end = System.currentTimeMillis(); AuditHelper.audit( session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_END, runtime.getInstanceId(), "", ( (float) ( end - start ) / 1000 ), this ); //$NON-NLS-1$ AuditHelper.audit( session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), errorMsg, ( (float) ( end - start ) / 1000 ), this ); // $NON-NLS-1$
public Object getSessionInstance( String key, IPentahoSession session ) throws ObjectFactoryException { if ( null == session ) { throw new IllegalArgumentException( Messages.getInstance().getErrorString( "SessionObjectCreator.ERROR_0001_INVALID_SESSION" ) ); //$NON-NLS-1$ } Object instance = session.getAttribute( key ); if ( ( instance == null ) ) { instance = createObject(); if ( instance instanceof IPentahoInitializer ) { ( (IPentahoInitializer) instance ).init( session ); } session.setAttribute( key, instance ); } return instance; }
@Override public String getTenantId() { IPentahoSession session = PentahoSessionHolder.getSession(); // get the session Object tenantId = session.getAttribute( getTenantSessionVariableName() ); // get the variable if ( tenantId != null ) { return tenantId.toString(); // Convert to string } else { return null; // Return null if not in the session. } }