Search in sources :

Example 6 with JdbcUserRoleListService

use of org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService 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 7 with JdbcUserRoleListService

use of org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService 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 8 with JdbcUserRoleListService

use of org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService in project pentaho-platform by pentaho.

the class JdbcUserRoleListServiceTest method testGetAllUsernamesInRole.

@Test
public void testGetAllUsernamesInRole() throws Exception {
    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("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);
    }
}
Also used : JdbcUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService) Test(org.junit.Test)

Example 9 with JdbcUserRoleListService

use of org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService in project pentaho-platform by pentaho.

the class JdbcUserRoleListServiceTest method testGetAllAuthorities.

@Test
public void testGetAllAuthorities() throws Exception {
    JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
    // $NON-NLS-1$
    dao.setAllAuthoritiesQuery("SELECT DISTINCT(AUTHORITY) AS AUTHORITY FROM AUTHORITIES ORDER BY 1");
    dao.afterPropertiesSet();
    List<String> auths = dao.getAllRoles();
    // $NON-NLS-1$
    assertTrue("Authorities list should not be empty", auths.size() > 0);
    for (String auth : auths) {
        // $NON-NLS-1$
        System.out.println("Authority: " + auth);
    }
}
Also used : JdbcUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService) Test(org.junit.Test)

Example 10 with JdbcUserRoleListService

use of org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService in project pentaho-platform by pentaho.

the class JdbcUserRoleListServiceTest method makePopulatedJdbcUserRoleListService.

protected JdbcUserRoleListService makePopulatedJdbcUserRoleListService() throws Exception {
    List<String> systemRoles = new ArrayList<String>();
    systemRoles.add("Admin");
    JdbcUserRoleListService dao = new JdbcUserRoleListService(makePopulatedJdbcDao(), systemRoles);
    dao.setDataSource(PopulatedDatabase.getDataSource());
    return dao;
}
Also used : ArrayList(java.util.ArrayList) JdbcUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService)

Aggregations

JdbcUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService)11 Test (org.junit.Test)10 ITenant (org.pentaho.platform.api.mt.ITenant)5 Tenant (org.pentaho.platform.core.mt.Tenant)5 ArrayList (java.util.ArrayList)1