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;
}
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");
}
}
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());
}
}
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());
}
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);
}
Aggregations