Search in sources :

Example 21 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testGetDomain_null_session.

public void testGetDomain_null_session() throws Exception {
    final String SESSION_ID = null;
    // $NON-NLS-1$
    final String ID = "1";
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.storeDomain(getTestDomain(ID), false);
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // $NON-NLS-1$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", SESSION_ID));
    Domain domain = repo.getDomain(ID);
    // Description will equal the id when no description is provided (null session)
    assertEquals(ID, domain.getDescription(TEST_LOCALE));
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) Domain(org.pentaho.metadata.model.Domain)

Example 22 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testRemoveDomain.

/**
 * Make sure removing a domain removes all cached instances of the domain
 */
public void testRemoveDomain() throws Exception {
    // $NON-NLS-1$
    final String ID1 = "1";
    // $NON-NLS-1$
    final String ID2 = "2";
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.storeDomain(getTestDomain(ID1), false);
    mock.storeDomain(getTestDomain(ID2), false);
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
    Domain domainFromSession1 = repo.getDomain(ID1);
    assertNotNull(domainFromSession1);
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("getDomain"));
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "2"));
    Domain domainFromSession2 = repo.getDomain(ID1);
    assertNotNull(domainFromSession2);
    // $NON-NLS-1$
    assertEquals(2, mock.getInvocationCount("getDomain"));
    assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    repo.removeDomain(ID1);
    assertEquals(0, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // Calling getDomain() now should increment the call count to the delegate
    repo.getDomain(ID2);
    // $NON-NLS-1$
    assertEquals(3, mock.getInvocationCount("getDomain"));
    // There should now only be one in the cache
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) Domain(org.pentaho.metadata.model.Domain)

Example 23 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testOnLogout.

public void testOnLogout() throws Exception {
    // $NON-NLS-1$
    final String ID1 = "1";
    // $NON-NLS-1$
    final String ID2 = "2";
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    repo.storeDomain(getTestDomain(ID1), false);
    repo.storeDomain(getTestDomain(ID2), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
    repo.getDomain(ID1);
    // $NON-NLS-1$ //$NON-NLS-2$
    IPentahoSession session2 = new StandaloneSession("Standalone Session", "2");
    PentahoSessionHolder.setSession(session2);
    repo.getDomain(ID2);
    assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // Logging out session 2 should only remove cached domains from session 2
    repo.onLogout(session2);
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository)

Example 24 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class UserRoleDaoEncodeIT method loginAsRepositoryAdmin.

protected void loginAsRepositoryAdmin() {
    StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername);
    pentahoSession.setAuthenticated(repositoryAdminUsername);
    final List<GrantedAuthority> repositoryAdminAuthorities = Arrays.asList(new GrantedAuthority[] { new SimpleGrantedAuthority(sysAdminRoleName) });
    final String password = "ignored";
    UserDetails repositoryAdminUserDetails = new User(repositoryAdminUsername, password, true, true, true, true, repositoryAdminAuthorities);
    Authentication repositoryAdminAuthentication = new UsernamePasswordAuthenticationToken(repositoryAdminUserDetails, password, repositoryAdminAuthorities);
    PentahoSessionHolder.setSession(pentahoSession);
    // this line necessary for Spring Security's MethodSecurityInterceptor
    SecurityContextHolder.getContext().setAuthentication(repositoryAdminAuthentication);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.springframework.security.core.userdetails.User) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 25 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class UserRoleDaoIT method loginAsRepositoryAdmin.

protected void loginAsRepositoryAdmin() {
    StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername);
    pentahoSession.setAuthenticated(repositoryAdminUsername);
    final List<GrantedAuthority> repositoryAdminAuthorities = Arrays.asList(new GrantedAuthority[] { new SimpleGrantedAuthority(sysAdminRoleName) });
    final String password = "ignored";
    UserDetails repositoryAdminUserDetails = new User(repositoryAdminUsername, password, true, true, true, true, repositoryAdminAuthorities);
    Authentication repositoryAdminAuthentication = new UsernamePasswordAuthenticationToken(repositoryAdminUserDetails, password, repositoryAdminAuthorities);
    PentahoSessionHolder.setSession(pentahoSession);
    // this line necessary for Spring Security's MethodSecurityInterceptor
    SecurityContextHolder.getContext().setAuthentication(repositoryAdminAuthentication);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.springframework.security.core.userdetails.User) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)218 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)74 ArrayList (java.util.ArrayList)46 Authentication (org.springframework.security.core.Authentication)39 Test (org.junit.Test)38 OutputStream (java.io.OutputStream)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)30 GrantedAuthority (org.springframework.security.core.GrantedAuthority)30 User (org.springframework.security.core.userdetails.User)30 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)29 UserDetails (org.springframework.security.core.userdetails.UserDetails)29 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)24 File (java.io.File)21 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)21 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)21 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)20 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)20 HashMap (java.util.HashMap)16 Before (org.junit.Before)16