Search in sources :

Example 26 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project pentaho-platform by pentaho.

the class MondrianOneToOneUserRoleListMapper method mapRoles.

/**
 * This mapper maps directly from a Hitachi Vantara to a Mondrian role. This is useful when your roles exist both in the
 * platform and identically named in the mondrian catalog.
 */
protected String[] mapRoles(String[] mondrianRoles, String[] platformRoles) throws PentahoAccessControlException {
    // 
    // This class assumes that the platform roles list contains roles that
    // are defined in the mondrian schema. All roles that the user has
    // that are defined in the mondrian schema are returned.
    // 
    // Note - this mapper doesn't need the mondrian catalog to do the mapping
    ArrayList<String> rtnRoles = new ArrayList<String>();
    int posn;
    // For each platform role...
    for (int i = 0; i < platformRoles.length; i++) {
        // Find the role in the Mondrian roles for this catalog
        posn = Arrays.binarySearch(mondrianRoles, platformRoles[i]);
        if (posn >= 0) {
            // For each one found, add it to the returned array of roles
            rtnRoles.add(mondrianRoles[posn]);
        }
    }
    if (rtnRoles.size() > 0) {
        return rtnRoles.toArray(new String[rtnRoles.size()]);
    } else if (failOnEmptyRoleList) {
        throw new PentahoAccessControlException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "MondrianOneToOneUserRoleListMapper.ERROR_001_NO_CORRESPONDENCE"));
    } else {
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException)

Example 27 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project pentaho-platform by pentaho.

the class UserRoleMapperIT method testMondrianOneToOneUserRoleListMapper.

@Test
public void testMondrianOneToOneUserRoleListMapper() throws Exception {
    final IConnectionUserRoleMapper mapper = new MondrianOneToOneUserRoleListMapper();
    try {
        String[] roles = SecurityHelper.getInstance().runAsUser("simplebob", new Callable<String[]>() {

            @Override
            public String[] call() throws Exception {
                return mapper.mapConnectionRoles(PentahoSessionHolder.getSession(), "SteelWheelsRoles");
            }
        });
        Assert.assertNotNull(roles);
        Assert.assertEquals(2, roles.length);
        Assert.assertEquals("Role1", roles[0]);
        Assert.assertEquals("Role2", roles[1]);
    } catch (PentahoAccessControlException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : IConnectionUserRoleMapper(org.pentaho.platform.api.engine.IConnectionUserRoleMapper) MondrianOneToOneUserRoleListMapper(org.pentaho.platform.plugin.action.mondrian.mapper.MondrianOneToOneUserRoleListMapper) 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 28 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException 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 29 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project pentaho-platform by pentaho.

the class UserRoleMapperIT method testNoMatchMondrianOneToOneUserRoleListMapper.

@Test
public void testNoMatchMondrianOneToOneUserRoleListMapper() throws Exception {
    final MondrianOneToOneUserRoleListMapper mapper = new MondrianOneToOneUserRoleListMapper();
    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("simplebob", new Callable<String[]>() {

            @Override
            public String[] call() throws Exception {
                return mapper.mapConnectionRoles(PentahoSessionHolder.getSession(), "SteelWheelsRoles");
            }
        });
        Assert.assertArrayEquals(new String[] { "Role1", "Role2" }, roles);
    } catch (PentahoAccessControlException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : MondrianOneToOneUserRoleListMapper(org.pentaho.platform.plugin.action.mondrian.mapper.MondrianOneToOneUserRoleListMapper) 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 30 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException 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

PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)48 Test (org.junit.Test)28 InputStream (java.io.InputStream)13 Response (javax.ws.rs.core.Response)13 FileNotFoundException (java.io.FileNotFoundException)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)6 PlatformInitializationException (org.pentaho.platform.engine.core.system.boot.PlatformInitializationException)6 PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)6 DataAccessException (org.springframework.dao.DataAccessException)6 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)6 Domain (org.pentaho.metadata.model.Domain)5 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)5 FileInputStream (java.io.FileInputStream)4 Consumes (javax.ws.rs.Consumes)4 Facet (org.codehaus.enunciate.Facet)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)4 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)3