use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class FileResourceIT method login.
/**
* Logs in with given username.
*
* @param username username of user
* @param tenant tenant to which this user belongs
* @tenantAdmin true to add the tenant admin authority to the user's roles
*/
protected void login(final String username, final ITenant tenant, final boolean tenantAdmin) {
StandaloneSession pentahoSession = new StandaloneSession(username);
pentahoSession.setAuthenticated(username);
pentahoSession.setAttribute(IPentahoSession.TENANT_ID_KEY, tenant.getId());
final String password = "password";
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
authList.add(new SimpleGrantedAuthority(authenticatedAuthorityName));
if (tenantAdmin) {
authList.add(new SimpleGrantedAuthority(adminAuthorityName));
}
UserDetails userDetails = new User(username, password, true, true, true, true, authList);
Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, password, authList);
PentahoSessionHolder.setSession(pentahoSession);
// this line necessary for Spring Security's MethodSecurityInterceptor
SecurityContextHolder.getContext().setAuthentication(auth);
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method testGetDomain_differentSessions.
public void testGetDomain_differentSessions() throws Exception {
// $NON-NLS-1$
final String SESSION_ID1 = "1234";
// $NON-NLS-1$
final String SESSION_ID2 = "5678";
// $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_ID1));
// $NON-NLS-1$
assertEquals(0, mock.getInvocationCount("getDomain"));
Domain d = repo.getDomain(ID);
assertEquals(ID, d.getId());
assertEquals(SESSION_ID1, d.getDescription(TEST_LOCALE));
// $NON-NLS-1$
assertEquals(1, mock.getInvocationCount("getDomain"));
// Cache should contain a domain for this session
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// Get the same domain from a different session
// $NON-NLS-1$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", SESSION_ID2));
d = repo.getDomain(ID);
// Make sure we got a new, session-specific, domain
assertEquals(SESSION_ID2, d.getDescription(TEST_LOCALE));
// Make sure cache was missed and delegate was called
// $NON-NLS-1$
assertEquals(2, mock.getInvocationCount("getDomain"));
// We should now have two objects in the cache (1 domain per session)
assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// Domains in current session
assertEquals(1, repo.getDomainIds().size());
// Switch back to original session
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
// Check for domains available for this session
assertEquals(1, repo.getDomainIds().size());
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method testRemoveModel.
public void testRemoveModel() 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);
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
Domain domain = getTestDomain(ID1);
LogicalModel model = new LogicalModel();
// $NON-NLS-1$
model.setId("test");
domain.addLogicalModel(model);
repo.storeDomain(domain, false);
repo.storeDomain(getTestDomain(ID2), false);
repo.getDomain(ID1);
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
repo.getDomain(ID2);
assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "2"));
repo.getDomain(ID1);
assertEquals(3, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// $NON-NLS-1$
repo.removeModel(ID1, "test");
// Removing a model should remove all domains with that same id, leaving others intact
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// $NON-NLS-1$
assertEquals(1, mock.getInvocationCount("removeModel"));
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method testGetDomain.
public void testGetDomain() throws Exception {
// $NON-NLS-1$
final String SESSION_ID = "1234-5678-90";
// $NON-NLS-1$
final String ID = "1";
// $NON-NLS-1$
final String ID2 = "2";
IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
when(aclNodeHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
MockAclAwareMetadataDomainRepository mock = new MockAclAwareMetadataDomainRepository(aclNodeHelper, null);
mock.storeDomain(getTestDomain(ID), false);
SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
// $NON-NLS-1$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", SESSION_ID));
// $NON-NLS-1$
assertEquals(0, mock.getInvocationCount("getDomain"));
Domain d = repo.getDomain(ID);
assertEquals(ID, d.getId());
// Make sure the domain we got back has our session embedded in it (tests mock repository)
assertEquals(SESSION_ID, d.getDescription(TEST_LOCALE));
// $NON-NLS-1$
assertEquals(1, mock.getInvocationCount("getDomain"));
// Cache should contain a domain for this session
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
repo.getDomain(ID);
// Make sure cache was hit and delegate was not called
// $NON-NLS-1$
assertEquals(1, mock.getInvocationCount("getDomain"));
// Cache should contain a domain for this session
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
mock.storeDomain(getTestDomain(ID2), false);
repo.getDomain(ID2);
// Cache should contain tow domains for this session
assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// Block access to domain ID2. Cache should be cleared for this domain
when(aclNodeHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(false);
repo.getDomain(ID2);
// Make sure cache was hit and delegate was not called
// $NON-NLS-1$
assertEquals(2, mock.getInvocationCount("getDomain"));
// Cache should contain a domain for this session
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 testGetDomainIds_differentSessions.
/**
* Make sure all domain ids are returned in all sessions
*/
public void testGetDomainIds_differentSessions() throws Exception {
// $NON-NLS-1$
final String ID = "1";
MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
Set<String> ids = repo.getDomainIds();
assertEquals(0, ids.size());
// $NON-NLS-1$
assertEquals(1, mock.getInvocationCount("getDomainIds"));
repo.storeDomain(getTestDomain(ID), false);
ids = repo.getDomainIds();
assertEquals(1, ids.size());
// $NON-NLS-1$
assertEquals(2, mock.getInvocationCount("getDomainIds"));
// Switch the session
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "2"));
// Make sure the domain id is returned
ids = repo.getDomainIds();
assertEquals(1, ids.size());
// $NON-NLS-1$
assertEquals(3, mock.getInvocationCount("getDomainIds"));
}
Aggregations