Search in sources :

Example 1 with ITenantedPrincipleNameResolver

use of org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver in project pentaho-kettle by pentaho.

the class PurRepositoryIT method getPrincipalName.

protected String getPrincipalName(String principalId, boolean isUser) {
    String principalName = null;
    ITenantedPrincipleNameResolver nameUtils = isUser ? userNameUtils : roleNameUtils;
    if (nameUtils != null) {
        principalName = nameUtils.getPrincipleName(principalId);
    }
    return principalName;
}
Also used : ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver) Matchers.anyString(org.mockito.Matchers.anyString)

Example 2 with ITenantedPrincipleNameResolver

use of org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver in project pentaho-kettle by pentaho.

the class UIEERepositoryDirectoryIT method getTenant.

private ITenant getTenant(String principalId, boolean isUser) {
    ITenant tenant = null;
    ITenantedPrincipleNameResolver nameUtils = isUser ? userNameUtils : roleNameUtils;
    if (nameUtils != null) {
        tenant = nameUtils.getTenant(principalId);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    return tenant;
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)

Example 3 with ITenantedPrincipleNameResolver

use of org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver in project pentaho-platform by pentaho.

the class TenantUtils method getCurrentTenant.

/**
 * 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);
}
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) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)

Example 4 with ITenantedPrincipleNameResolver

use of org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver in project pentaho-platform by pentaho.

the class JcrTenantUtils method getPrincipalName.

public static String getPrincipalName(String principalId, boolean isUser) {
    String principalName = null;
    ITenantedPrincipleNameResolver nameUtils = isUser ? getUserNameUtils() : getRoleNameUtils();
    if (nameUtils != null) {
        principalName = nameUtils.getPrincipleName(principalId);
    }
    return principalName;
}
Also used : ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)

Example 5 with ITenantedPrincipleNameResolver

use of org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver in project pentaho-platform by pentaho.

the class AbstractJcrBackedUserRoleDaoTest method testConvertToPentahoUserEnableCache.

@Test
public void testConvertToPentahoUserEnableCache() throws RepositoryException {
    AbstractJcrBackedUserRoleDao abstractJcrBackedUserRoleDaoMock = mock(AbstractJcrBackedUserRoleDao.class);
    doCallRealMethod().when(abstractJcrBackedUserRoleDaoMock).convertToPentahoUser(nullable(User.class));
    ITenantedPrincipleNameResolver resolverMock = mock(ITenantedPrincipleNameResolver.class);
    when(abstractJcrBackedUserRoleDaoMock.getTenantedUserNameUtils()).thenReturn(resolverMock);
    when(abstractJcrBackedUserRoleDaoMock.isUseJackrabbitUserCache()).thenReturn(true);
    // Cache mocking
    LRUMap cacheMock = mock(LRUMap.class);
    when(abstractJcrBackedUserRoleDaoMock.getUserCache()).thenReturn(cacheMock);
    User userMock = mock(User.class);
    abstractJcrBackedUserRoleDaoMock.convertToPentahoUser(userMock);
    verify(cacheMock).put(any(), any());
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.apache.jackrabbit.api.security.user.User) LRUMap(org.apache.commons.collections.map.LRUMap) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver) Test(org.junit.Test)

Aggregations

ITenantedPrincipleNameResolver (org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)14 ITenant (org.pentaho.platform.api.mt.ITenant)7 LRUMap (org.apache.commons.collections.map.LRUMap)2 User (org.apache.jackrabbit.api.security.user.User)2 Test (org.junit.Test)2 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)2 Locale (java.util.Locale)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 Tenant (org.pentaho.platform.core.mt.Tenant)1 UserSession (org.pentaho.platform.engine.core.system.UserSession)1 Authentication (org.springframework.security.core.Authentication)1