Search in sources :

Example 16 with Tenant

use of org.pentaho.platform.core.mt.Tenant 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 17 with Tenant

use of org.pentaho.platform.core.mt.Tenant 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 18 with Tenant

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

the class SolutionImportHandler method importRoles.

protected void importRoles(List<RoleExport> roles, Map<String, List<String>> roleToUserMap) {
    IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class);
    ITenant tenant = new Tenant("/pentaho/" + TenantUtils.getDefaultTenant(), true);
    IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = PentahoSystem.get(IRoleAuthorizationPolicyRoleBindingDao.class);
    Set<String> existingRoles = new HashSet<>();
    if (roles != null) {
        for (RoleExport role : roles) {
            log.debug("Importing role: " + role.getRolename());
            try {
                List<String> users = roleToUserMap.get(role.getRolename());
                String[] userarray = users == null ? new String[] {} : users.toArray(new String[] {});
                IPentahoRole role1 = roleDao.createRole(tenant, role.getRolename(), null, userarray);
            } catch (AlreadyExistsException e) {
                existingRoles.add(role.getRolename());
                // it's ok if the role already exists, it is probably a default role
                log.info(Messages.getInstance().getString("ROLE.Already.Exists", role.getRolename()));
            }
            try {
                if (existingRoles.contains(role.getRolename())) {
                    // Only update an existing role if the overwrite flag is set
                    if (isOverwriteFile()) {
                        roleBindingDao.setRoleBindings(tenant, role.getRolename(), role.getPermissions());
                    }
                } else {
                    // Always write a roles permissions that were not previously existing
                    roleBindingDao.setRoleBindings(tenant, role.getRolename(), role.getPermissions());
                }
            } catch (Exception e) {
                log.info(Messages.getInstance().getString("ERROR.SettingRolePermissions", role.getRolename()), e);
            }
        }
    }
}
Also used : IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) RoleExport(org.pentaho.platform.plugin.services.importexport.RoleExport) HashSet(java.util.HashSet)

Example 19 with Tenant

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

the class JdbcUserRoleListServiceTest method testGetAllUsernamesInRoleForTenant.

@Test
public void testGetAllUsernamesInRoleForTenant() throws Exception {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("admin", defaultTenant);
    JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
    dao.setAllUsernamesInRoleQuery(// $NON-NLS-1$
    "SELECT DISTINCT(USERNAME) AS USERNAME FROM AUTHORITIES WHERE AUTHORITY = ? ORDER BY 1");
    dao.afterPropertiesSet();
    // $NON-NLS-1$
    List<String> allUsers = dao.getUsersInRole(defaultTenant, "ROLE_TELLER");
    // $NON-NLS-1$
    assertTrue("User List should not be empty", allUsers.size() > 0);
    for (String username : allUsers) {
        // $NON-NLS-1$
        System.out.println("ROLE_TELLER User: " + username);
    }
    try {
        allUsers = dao.getUsersInRole(new Tenant("/pentaho", true), "ROLE_TELLER");
    } 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 20 with Tenant

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

the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole1ForTenant.

@Test
public void testGetUsernamesInRole1ForTenant() {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("suzy", defaultTenant);
    SearchControls con1 = new SearchControls();
    // $NON-NLS-1$
    con1.setReturningAttributes(new String[] { "uid" });
    LdapSearchParamsFactory paramFactory = // $NON-NLS-1$//$NON-NLS-2$
    new LdapSearchParamsFactoryImpl("ou=users", "(businessCategory=cn={0}*)", con1);
    // $NON-NLS-1$
    Transformer transformer1 = new SearchResultToAttrValueList("uid");
    GrantedAuthorityToString transformer2 = new GrantedAuthorityToString();
    LdapSearch usernamesInRoleSearch = new GenericLdapSearch(getContextSource(), paramFactory, transformer1, transformer2);
    DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
    userRoleListService.setUsernamesInRoleSearch(usernamesInRoleSearch);
    // $NON-NLS-1$
    List<String> res = userRoleListService.getUsersInRole(defaultTenant, "DEV");
    // $NON-NLS-1$
    assertTrue(res.contains("pat"));
    // $NON-NLS-1$
    assertTrue(res.contains("tiffany"));
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug("results of getUsernamesInRole1(): " + res);
    }
    try {
        userRoleListService.getUsersInRole(new Tenant("/pentaho", true), "DEV");
    } 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) GenericLdapSearch(org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch) GrantedAuthorityToString(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString) 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) GrantedAuthorityToString(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString) 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)

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