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