Search in sources :

Example 31 with ITenant

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

the class JdbcUserRoleListServiceTest method testGetRolesForUserForTenant.

@Test
public void testGetRolesForUserForTenant() throws Exception {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("admin", defaultTenant);
    JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
    dao.setUserDetailsService(makePopulatedJdbcDao());
    dao.afterPropertiesSet();
    // $NON-NLS-1$
    List<String> roles = dao.getRolesForUser(defaultTenant, "rod");
    // $NON-NLS-1$
    assertTrue(roles.contains("ROLE_TELLER"));
    // $NON-NLS-1$
    assertTrue(roles.contains("ROLE_SUPERVISOR"));
    try {
        roles = dao.getRolesForUser(new Tenant("/pentaho", true), "rod");
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) JdbcUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService) Test(org.junit.Test)

Example 32 with ITenant

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

the class JdbcUserRoleListServiceTest method testGetAllAuthoritiesWithRolePrefixForTenant.

@Test
public void testGetAllAuthoritiesWithRolePrefixForTenant() throws Exception {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("admin", defaultTenant);
    JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
    // $NON-NLS-1$
    dao.setAllAuthoritiesQuery("SELECT DISTINCT(AUTHORITY) AS AUTHORITY FROM AUTHORITIES ORDER BY 1");
    // $NON-NLS-1$
    dao.setRolePrefix("ARBITRARY_PREFIX_");
    dao.afterPropertiesSet();
    List<String> auths = dao.getAllRoles(defaultTenant);
    // $NON-NLS-1$
    assertTrue("Authorities list should not be empty", auths.size() > 0);
    for (String role : auths) {
        // $NON-NLS-1$
        System.out.println("Authority with prefix: " + role);
    }
    try {
        auths = dao.getAllRoles(new Tenant("/pentaho", true));
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) JdbcUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService) Test(org.junit.Test)

Example 33 with ITenant

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

the class DefaultLdapUserRoleListServiceTest method testGetAuthoritiesForUser1ForTenant.

@Test
public void testGetAuthoritiesForUser1ForTenant() throws Exception {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("suzy", defaultTenant);
    // $NON-NLS-1$//$NON-NLS-2$
    LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})");
    LdapUserDetailsService service = new LdapUserDetailsService(userSearch, new NoOpLdapAuthoritiesPopulator());
    RolePreprocessingMapper mapper = new RolePreprocessingMapper();
    // $NON-NLS-1$
    mapper.setRoleAttributes(new String[] { "uniqueMember" });
    // $NON-NLS-1$
    mapper.setTokenName("cn");
    service.setUserDetailsMapper(mapper);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setUserDetailsService(service);
    // $NON-NLS-1$
    List res = userRoleListService.getRolesForUser(defaultTenant, "suzy");
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_A"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAuthoritiesForUser1(): " + res);
    }
    try {
        userRoleListService.getRolesForUser(new Tenant("/pentaho", true), "suzy");
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }
}
Also used : LdapUserDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService) DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) NoOpLdapAuthoritiesPopulator(org.pentaho.platform.plugin.services.security.userrole.ldap.NoOpLdapAuthoritiesPopulator) RolePreprocessingMapper(org.pentaho.platform.plugin.services.security.userrole.ldap.RolePreprocessingMapper) ArrayList(java.util.ArrayList) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) List(java.util.List) LdapUserSearch(org.springframework.security.ldap.search.LdapUserSearch) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) Test(org.junit.Test)

Example 34 with ITenant

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

the class DefaultLdapUserRoleListServiceTest method testGetAllAuthorities1ForTenant.

@Test
public void testGetAllAuthorities1ForTenant() {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("suzy", defaultTenant);
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "cn" });
    LdapSearchParamsFactory paramsFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=roles", "(objectClass=organizationalRole)", con1);
    // $NON-NLS-1$
    Transformer one = new SearchResultToAttrValueList("cn");
    Transformer two = new StringToGrantedAuthority();
    Transformer[] transformers = { one, two };
    Transformer transformer = new ChainedTransformer(transformers);
    LdapSearch rolesSearch = new GenericLdapSearch(getContextSource(), paramsFactory, transformer);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setAllAuthoritiesSearch(rolesSearch);
    List res = userRoleListService.getAllRoles(defaultTenant);
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_CTO"));
    // $NON-NLS-1$
    assertTrue(res.contains("ROLE_CEO"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getAllAuthorities1(): " + res);
    }
    try {
        userRoleListService.getAllRoles(new Tenant("/pentaho", true));
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }
}
Also used : DefaultLdapUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) Transformer(org.apache.commons.collections.Transformer) StringToGrantedAuthority(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) LdapSearchParamsFactory(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory) SearchControls(javax.naming.directory.SearchControls) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) ArrayList(java.util.ArrayList) SearchResultToAttrValueList(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList) List(java.util.List) UnionizingLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch) LdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearch) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) LdapSearchParamsFactoryImpl(org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl) Test(org.junit.Test)

Example 35 with ITenant

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

the class AbstractJcrBackedUserRoleDao method createRole.

public IPentahoRole createRole(Session session, final ITenant theTenant, final String roleName, final String description, final String[] memberUserNames) throws AuthorizableExistsException, RepositoryException {
    ITenant tenant = theTenant;
    String role = roleName;
    if (tenant == null) {
        tenant = JcrTenantUtils.getTenant(roleName, false);
        role = JcrTenantUtils.getPrincipalName(roleName, false);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = JcrTenantUtils.getCurrentTenant();
    }
    if (!TenantUtils.isAccessibleTenant(tenant)) {
        throw new NotFoundException(Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.ERROR_0006_TENANT_NOT_FOUND", theTenant.getId()));
    }
    String roleId = tenantedRoleNameUtils.getPrincipleId(tenant, role);
    UserManager tenantUserMgr = getUserManager(tenant, session);
    // Intermediate path will always be an empty string. The path is already provided while creating a user manager
    // $NON-NLS-1$
    tenantUserMgr.createGroup(new PrincipalImpl(roleId), "");
    setRoleMembers(session, tenant, role, memberUserNames);
    setRoleDescription(session, tenant, role, description);
    return getRole(session, theTenant, roleName);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UserManager(org.apache.jackrabbit.api.security.user.UserManager) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl)

Aggregations

ITenant (org.pentaho.platform.api.mt.ITenant)174 Test (org.junit.Test)120 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)86 Matchers.anyString (org.mockito.Matchers.anyString)47 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)27 ArrayList (java.util.ArrayList)21 Tenant (org.pentaho.platform.core.mt.Tenant)21 ByteArrayInputStream (java.io.ByteArrayInputStream)17 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)17 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)15 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)14 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)14 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)12 WebResource (com.sun.jersey.api.client.WebResource)11 JerseyTest (com.sun.jersey.test.framework.JerseyTest)11 ITenantedPrincipleNameResolver (org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)10 SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)10 Serializable (java.io.Serializable)9 Date (java.util.Date)9 HashMap (java.util.HashMap)9