Search in sources :

Example 1 with MondrianLookupMapUserRoleListMapper

use of org.pentaho.platform.plugin.action.mondrian.mapper.MondrianLookupMapUserRoleListMapper in project pentaho-platform by pentaho.

the class UserRoleMapperIT method testNoMatchLookupMapUserRoleListMapper.

@Test
public void testNoMatchLookupMapUserRoleListMapper() throws Exception {
    Map<String, String> lookup = new HashMap<String, String>();
    lookup.put("No Match", "Role1");
    lookup.put("No Match Here Either", "Role2");
    final MondrianLookupMapUserRoleListMapper mapper = new MondrianLookupMapUserRoleListMapper();
    mapper.setLookupMap(lookup);
    mapper.setFailOnEmptyRoleList(true);
    try {
        SecurityHelper.getInstance().runAsUser("admin", new Callable<String[]>() {

            @Override
            public String[] call() throws Exception {
                return mapper.mapConnectionRoles(PentahoSessionHolder.getSession(), "SteelWheelsRoles");
            }
        });
        Assert.fail();
    } catch (PentahoAccessControlException e) {
    // no op.
    }
    mapper.setFailOnEmptyRoleList(false);
    try {
        String[] roles = SecurityHelper.getInstance().runAsUser("admin", new Callable<String[]>() {

            @Override
            public String[] call() throws Exception {
                return mapper.mapConnectionRoles(PentahoSessionHolder.getSession(), "SteelWheelsRoles");
            }
        });
        Assert.assertNull(roles);
    } catch (PentahoAccessControlException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : MondrianLookupMapUserRoleListMapper(org.pentaho.platform.plugin.action.mondrian.mapper.MondrianLookupMapUserRoleListMapper) HashMap(java.util.HashMap) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) DataAccessException(org.springframework.dao.DataAccessException) Test(org.junit.Test)

Example 2 with MondrianLookupMapUserRoleListMapper

use of org.pentaho.platform.plugin.action.mondrian.mapper.MondrianLookupMapUserRoleListMapper in project pentaho-platform by pentaho.

the class UserRoleMapperIT method testLookupMapUserRoleListMapper.

@Test
public void testLookupMapUserRoleListMapper() throws Exception {
    Map<String, String> lookup = new HashMap<String, String>();
    lookup.put("ceo", "Role1");
    lookup.put("Not Pentaho", "Role2");
    lookup.put("Not Mondrian or Pentaho", "Role3");
    final MondrianLookupMapUserRoleListMapper mapper = new MondrianLookupMapUserRoleListMapper();
    mapper.setLookupMap(lookup);
    try {
        String[] roles = SecurityHelper.getInstance().runAsUser("admin", new Callable<String[]>() {

            @Override
            public String[] call() throws Exception {
                return mapper.mapConnectionRoles(PentahoSessionHolder.getSession(), "SteelWheelsRoles");
            }
        });
        Assert.assertNotNull(roles);
        Assert.assertEquals(1, roles.length);
        Assert.assertEquals("Role1", roles[0]);
    } catch (PentahoAccessControlException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : MondrianLookupMapUserRoleListMapper(org.pentaho.platform.plugin.action.mondrian.mapper.MondrianLookupMapUserRoleListMapper) HashMap(java.util.HashMap) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) DataAccessException(org.springframework.dao.DataAccessException) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 Test (org.junit.Test)2 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)2 PlatformInitializationException (org.pentaho.platform.engine.core.system.boot.PlatformInitializationException)2 MondrianLookupMapUserRoleListMapper (org.pentaho.platform.plugin.action.mondrian.mapper.MondrianLookupMapUserRoleListMapper)2 DataAccessException (org.springframework.dao.DataAccessException)2 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)2