Search in sources :

Example 31 with PentahoAccessControlException

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

the class UserRoleMapperIT method testMondrianUserSessionUserRoleListMapper.

@Test
public void testMondrianUserSessionUserRoleListMapper() throws Exception {
    final MondrianUserSessionUserRoleListMapper mapper = new MondrianUserSessionUserRoleListMapper();
    mapper.setSessionProperty("rolesAttribute");
    try {
        String[] roles = SecurityHelper.getInstance().runAsUser("admin", new Callable<String[]>() {

            @Override
            public String[] call() throws Exception {
                IPentahoSession session = PentahoSessionHolder.getSession();
                session.setAttribute("rolesAttribute", new Object[] { "mondrianRole1", "mondrianRole2", "mondrianRole3" });
                return mapper.mapConnectionRoles(session, "SteelWheelsRoles");
            }
        });
        Assert.assertNotNull(roles);
        Assert.assertEquals(3, roles.length);
        Assert.assertEquals("mondrianRole1", roles[0]);
        Assert.assertEquals("mondrianRole2", roles[1]);
        Assert.assertEquals("mondrianRole3", roles[2]);
    } catch (PentahoAccessControlException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) MondrianUserSessionUserRoleListMapper(org.pentaho.platform.plugin.action.mondrian.mapper.MondrianUserSessionUserRoleListMapper) 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 32 with PentahoAccessControlException

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

the class UserRoleMapperIT method testNoMatchMondrianUserSessionUserRoleListMapper.

@Test
public void testNoMatchMondrianUserSessionUserRoleListMapper() throws Exception {
    final MondrianUserSessionUserRoleListMapper mapper = new MondrianUserSessionUserRoleListMapper();
    mapper.setSessionProperty("rolesAttribute");
    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 : PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) MondrianUserSessionUserRoleListMapper(org.pentaho.platform.plugin.action.mondrian.mapper.MondrianUserSessionUserRoleListMapper) 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 33 with PentahoAccessControlException

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

the class AnalysisService method doGetAnalysisFilesAsDownload.

public Map<String, InputStream> doGetAnalysisFilesAsDownload(String analysisId) throws PentahoAccessControlException {
    if (!canManageACL()) {
        throw new PentahoAccessControlException();
    }
    MondrianCatalogRepositoryHelper helper = createNewMondrianCatalogRepositoryHelper();
    Map<String, InputStream> fileData = helper.getModrianSchemaFiles(analysisId);
    super.parseMondrianSchemaName(analysisId, fileData);
    return fileData;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException)

Example 34 with PentahoAccessControlException

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

the class DatasourceService method validateAccess.

public static void validateAccess() throws PentahoAccessControlException {
    IAuthorizationPolicy policy = PentahoSystem.get(IAuthorizationPolicy.class);
    boolean isAdmin = policy.isAllowed(RepositoryReadAction.NAME) && policy.isAllowed(RepositoryCreateAction.NAME) && policy.isAllowed(PublishAction.NAME);
    if (!isAdmin) {
        throw new PentahoAccessControlException("Access Denied");
    }
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException)

Example 35 with PentahoAccessControlException

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

the class JDBCDatasourceResource method addOrUpdate.

/**
 * Add or update a JDBC datasource connection
 *
 * <p><b>Example Request:</b><br />
 *    PUT pentaho/plugin/data-access/api/datasource/jdbc/connection/TestDatasource
 * </p>
 * <br /><b>POST data:</b>
 *  <pre function="syntax.xml">
 *    {
 *      "changed": true,
 *      "usingConnectionPool": true,
 *      "connectSql": "",
 *      "databaseName": "SampleData",
 *      "databasePort": "9001",
 *      "hostname": "localhost",
 *      "name": "TestDataSourceResource",
 *      "password": "password",
 *      "username": "pentaho_user",
 *      "attributes": {},
 *      "connectionPoolingProperties": {},
 *      "extraOptions": {},
 *      "accessType": "NATIVE",
 *      "databaseType": {
 *        "defaultDatabasePort": 9001,
 *        "extraOptionsHelpUrl": "http://hsqldb.sourceforge.net/doc/guide/ch04.html#N109DA",
 *        "name": "Hypersonic",
 *        "shortName": "HYPERSONIC",
 *        "supportedAccessTypes": [
 *          "NATIVE",
 *          "ODBC",
 *          "JNDI"
 *        ]
 *      }
 *    }
 *  </pre>
 * </p>
 *
 * @param connection A DatabaseConnection in JSON representation
 *
 * @return A jax-rs Response object with the appropriate status code, header, and body.
 *
 * <p><b>Example Response:</b></p>
 *    <pre function="syntax.xml">
 *      This response does not contain data.
 *    </pre>
 */
@PUT
@Path("/{connectionId : .+}")
@Consumes({ APPLICATION_JSON })
@StatusCodes({ @ResponseCode(code = 200, condition = "JDBC datasource added successfully."), @ResponseCode(code = 403, condition = "User is not authorized to add JDBC datasources."), @ResponseCode(code = 304, condition = "Datasource was not modified"), @ResponseCode(code = 500, condition = "An unexected error occurred while adding the JDBC datasource.") })
public Response addOrUpdate(@PathParam("connectionId") String connectionName, DatabaseConnection connection) {
    try {
        validateAccess();
        // Prefer the path name over the one in the DTO object
        connection.setId(connectionName);
        IDatabaseConnection savedConn = null;
        try {
            savedConn = service.getConnectionByName(connectionName);
        } catch (ConnectionServiceException e) {
        // unfortunatley getConnectionById throws an exception not returning null when the conneciton is not present.
        } catch (NullPointerException e) {
        // unfortunatley getConnectionById throws an exception not returning null when the conneciton is not present.
        }
        boolean success = false;
        if (savedConn != null) {
            if (StringUtils.isBlank(connection.getPassword())) {
                connection.setPassword(savedConn.getPassword());
            }
            connection.setId(savedConn.getId());
            success = service.updateConnection(connection);
        } else {
            success = service.addConnection(connection);
        }
        if (success) {
            return buildOkResponse();
        } else {
            return buildNotModifiedResponse();
        }
    } catch (PentahoAccessControlException t) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    } catch (Throwable t) {
        logger.error("Error " + t.getMessage());
        return buildServerErrorResponse();
    }
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) PUT(javax.ws.rs.PUT)

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