Search in sources :

Example 26 with Tenant

use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.

the class BackingRepositoryLifecycleManagerAuthenticationSuccessListenerTest method testOnApplicationEvent.

public void testOnApplicationEvent() throws Exception {
    final BackingRepositoryLifecycleManagerAuthenticationSuccessListener listener = new BackingRepositoryLifecycleManagerAuthenticationSuccessListener();
    // Test the getters and setters
    final int order = listener.getOrder() + 1;
    listener.setOrder(order);
    assertEquals(order, listener.getOrder());
    assertEquals(SecurityHelper.getInstance(), listener.getSecurityHelper());
    final MockSecurityHelper mockSecurityHelper = new MockSecurityHelper();
    listener.setSecurityHelper(mockSecurityHelper);
    assertEquals(mockSecurityHelper, listener.getSecurityHelper());
    final MockBackingRepositoryLifecycleManager mockLifecycleManager = new MockBackingRepositoryLifecycleManager(mockSecurityHelper);
    mockLifecycleManager.setThrowException(false);
    listener.setLifecycleManager(mockLifecycleManager);
    assertEquals(mockLifecycleManager, listener.getLifecycleManager());
    // Test that the "newTenant() method is executed as the system currentUser and the
    String principleName = usernamePrincipleUtils.getPrincipleId(new Tenant(CURRENT_TENANT, true), CURRENT_USER);
    listener.onApplicationEvent(new MockAbstractAuthenticationEvent(new MockAuthentication(principleName)));
    final List<MethodTrackingData> methodTrackerHistory1 = mockLifecycleManager.getMethodTrackerHistory();
    assertEquals(4, methodTrackerHistory1.size());
    assertEquals("newTenant", methodTrackerHistory1.get(0).getMethodName());
    assertEquals(2, methodTrackerHistory1.get(0).getParameters().size());
    assertEquals(principleName, methodTrackerHistory1.get(3).getParameters().get(USER_PARAMETER));
    assertEquals(CURRENT_TENANT, usernamePrincipleUtils.getTenant((String) methodTrackerHistory1.get(3).getParameters().get(USER_PARAMETER)).getId());
    assertEquals("newUser", methodTrackerHistory1.get(1).getMethodName());
    assertEquals(3, methodTrackerHistory1.get(1).getParameters().size());
    // Make sure both methods get called when exceptions are thrown
    mockLifecycleManager.resetCallHistory();
    mockLifecycleManager.setThrowException(true);
    listener.onApplicationEvent(new MockAbstractAuthenticationEvent(new MockAuthentication(principleName)));
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) MethodTrackingData(org.pentaho.test.platform.MethodTrackingData) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant)

Example 27 with Tenant

use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.

the class UserRoleDaoResource method getTenant.

protected ITenant getTenant(String tenantId) throws NotFoundException {
    ITenant tenant = null;
    if (tenantId != null) {
        tenant = tenantManager.getTenant(tenantId);
        if (tenant == null) {
            throw new NotFoundException("Tenant not found.");
        }
    } else {
        IPentahoSession session = getSession();
        String tenantPath = (String) session.getAttribute(IPentahoSession.TENANT_ID_KEY);
        if (tenantPath != null) {
            tenant = new Tenant(tenantPath, true);
        }
    }
    return tenant;
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) NotFoundException(com.sun.jersey.api.NotFoundException)

Example 28 with Tenant

use of org.pentaho.platform.core.mt.Tenant in project data-access by pentaho.

the class MetadataDatasourceServiceTest method clearRoleBindings.

protected void clearRoleBindings() throws Exception {
    loginAsRepositoryAdmin();
    SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getTenantRootFolderPath(new Tenant("duff", true)) + ".authz");
    SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getTenantRootFolderPath(new Tenant("duff", true)) + ".authz");
}
Also used : Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant)

Aggregations

Tenant (org.pentaho.platform.core.mt.Tenant)28 ITenant (org.pentaho.platform.api.mt.ITenant)26 Test (org.junit.Test)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 ArrayList (java.util.ArrayList)5 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)5 JdbcUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService)5 List (java.util.List)4 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)4 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)4 IOException (java.io.IOException)3 Node (javax.jcr.Node)3 SearchControls (javax.naming.directory.SearchControls)3 Transformer (org.apache.commons.collections.Transformer)3 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)3 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 PropertyIterator (javax.jcr.PropertyIterator)2 RepositoryException (javax.jcr.RepositoryException)2