Search in sources :

Example 36 with PentahoAccessControlException

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

the class AnalysisDatasourceService method putMondrianSchema.

/**
 * This is used by PUC to use a Jersey put to import a Mondrian Schema XML into PUR
 *
 * @param dataInputStream
 * @param schemaFileInfo
 * @param catalogName
 * @param datasourceName
 * @param overwrite
 * @param xmlaEnabledFlag
 * @param parameters
 * @param acl acl information for the data source. This parameter is optional.
 * @return this method returns a response of "3" for success, 8 if exists, etc.
 * @throws PentahoAccessControlException
 */
@PUT
@Path("/putSchema")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response putMondrianSchema(@FormDataParam(UPLOAD_ANALYSIS) InputStream dataInputStream, @FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo, // Optional
@FormDataParam(CATALOG_NAME) String catalogName, // Optional
@FormDataParam(ORIG_CATALOG_NAME) String origCatalogName, // Optional
@FormDataParam(DATASOURCE_NAME) String datasourceName, @FormDataParam(OVERWRITE_IN_REPOS) String overwrite, @FormDataParam(XMLA_ENABLED_FLAG) String xmlaEnabledFlag, @FormDataParam(PARAMETERS) String parameters, @FormDataParam(DATASOURCE_ACL) RepositoryFileAclDto acl) throws PentahoAccessControlException {
    Response response = null;
    int statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
    try {
        AnalysisService service = new AnalysisService();
        boolean overWriteInRepository = "True".equalsIgnoreCase(overwrite) ? true : false;
        boolean xmlaEnabled = "True".equalsIgnoreCase(xmlaEnabledFlag) ? true : false;
        service.putMondrianSchema(dataInputStream, schemaFileInfo, catalogName, origCatalogName, datasourceName, overWriteInRepository, xmlaEnabled, parameters, acl);
        statusCode = SUCCESS;
    } catch (PentahoAccessControlException pac) {
        logger.error(pac.getMessage());
        statusCode = PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL;
    } catch (PlatformImportException pe) {
        statusCode = pe.getErrorStatus();
        logger.error("Error putMondrianSchema " + pe.getMessage() + " status = " + statusCode);
    } catch (Exception e) {
        logger.error("Error putMondrianSchema " + e.getMessage());
        statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
    }
    response = Response.ok().status(statusCode).type(MediaType.TEXT_PLAIN).build();
    logger.debug("putMondrianSchema Response " + response);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Example 37 with PentahoAccessControlException

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

the class ConnectionService method validateAccess.

/**
 * internal validation of authorization
 *
 * @throws PentahoAccessControlException
 */
private void validateAccess() throws PentahoAccessControlException {
    IAuthorizationPolicy policy = PentahoSystem.get(IAuthorizationPolicy.class);
    boolean isAdmin = policy.isAllowed(RepositoryReadAction.NAME) && policy.isAllowed(RepositoryCreateAction.NAME) && (policy.isAllowed(AdministerSecurityAction.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 38 with PentahoAccessControlException

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

the class DataSourceWizardResourceTest method doGetAnalysisAcl.

@Test
public void doGetAnalysisAcl() throws Exception {
    String domainId = "domainId";
    doReturn(new RepositoryFileAclDto()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    // no exception thrown
    dataSourceWizardResource.doGetDSWAcl(domainId);
    // 
    doThrow(new PentahoAccessControlException()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    try {
        dataSourceWizardResource.doGetDSWAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), e.getResponse().getStatus());
    }
    // 
    doThrow(new FileNotFoundException()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    try {
        dataSourceWizardResource.doGetDSWAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.CONFLICT.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FileNotFoundException(java.io.FileNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 39 with PentahoAccessControlException

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

the class JdbcDatasourceResourceTest method testAddOrUpdateNoPublishPermission.

@Test
public void testAddOrUpdateNoPublishPermission() throws Exception {
    doThrow(new PentahoAccessControlException()).when(jdbcDatasourceResource).validateAccess();
    DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
    try {
        jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(401, e.getResponse().getStatus());
    }
    verify(jdbcDatasourceResource.service, never()).addConnection(any());
    verify(jdbcDatasourceResource.service, never()).updateConnection(any());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 40 with PentahoAccessControlException

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

the class MetadataResourceTest method testImportMetadataDatasourceError.

@Test
public void testImportMetadataDatasourceError() throws Exception {
    Response mockResponse = mock(Response.class);
    FileResource mockFileResource = mock(FileResource.class);
    String domainId = "domainId";
    InputStream metadataFile = mock(InputStream.class);
    FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
    String overwrite = "overwrite";
    List<FormDataBodyPart> localeFiles = mock(List.class);
    List<FormDataContentDisposition> localeFilesInfo = mock(List.class);
    // Test 1
    PentahoAccessControlException mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
    doThrow(mockPentahoAccessControlException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, false, localeFiles, localeFilesInfo, null);
    doReturn(mockResponse).when(metadataResource).buildServerErrorResponse(mockPentahoAccessControlException);
    Response response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
    assertEquals(mockResponse, response);
    // Test 2
    PlatformImportException mockPlatformImportException = mock(PlatformImportException.class);
    doThrow(mockPlatformImportException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, localeFiles, localeFilesInfo, null);
    doReturn(10).when(mockPlatformImportException).getErrorStatus();
    doReturn(mockFileResource).when(metadataResource).createFileResource();
    doReturn(mockResponse).when(metadataResource).buildServerError003Response(domainId, mockFileResource);
    response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
    assertEquals(mockResponse, response);
    // Test 3
    RuntimeException mockException = mock(RuntimeException.class);
    doThrow(mockPlatformImportException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, localeFiles, localeFilesInfo, null);
    doReturn(1).when(mockPlatformImportException).getErrorStatus();
    doReturn(mockResponse).when(metadataResource).buildOkResponse("1");
    doReturn(mockException).when(mockPlatformImportException).getCause();
    response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
    assertEquals(mockResponse, response);
    // Test
    doThrow(mockException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, localeFiles, localeFilesInfo, null);
    doReturn(mockResponse).when(metadataResource).buildServerError001Response();
    response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
    assertEquals(mockResponse, response);
    verify(metadataResource, times(4)).importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) InputStream(java.io.InputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) 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