use of com.thinkbiganalytics.security.AccessControlled in project kylo by Teradata.
the class DatasourceController method getDatasource.
/**
* Gets the datasource with the id provided.
*
* @param idStr the datasource id
* @param sensitive {@code true} to include sensitive fields in the response, or {@code false} otherwise
* @return the datasource object
* @throws AccessControlException if the user does not have the {@code ACCESS_DATASOURCES} permission
*/
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the data source with the provided id.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the data source.", response = Datasource.class), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "The data source does not exist.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Kylo is unavailable.", response = RestResponseStatus.class) })
public Datasource getDatasource(@PathParam("id") String idStr, @QueryParam("sensitive") boolean sensitive) {
return this.metadata.read(() -> {
// Check permissions
accessController.checkPermission(AccessController.SERVICES, sensitive ? FeedServicesAccessControl.ADMIN_DATASOURCES : FeedServicesAccessControl.ACCESS_DATASOURCES);
com.thinkbiganalytics.metadata.api.datasource.Datasource.ID id = this.datasourceProvider.resolve(idStr);
com.thinkbiganalytics.metadata.api.datasource.Datasource ds = this.datasourceProvider.getDatasource(id);
if (ds != null) {
final Datasource restModel = datasourceTransform.toDatasource(ds, sensitive ? DatasourceModelTransform.Level.ADMIN : DatasourceModelTransform.Level.FULL);
if (ds instanceof AccessControlled) {
accessController.checkPermission((AccessControlled) ds, DatasourceAccessControl.ACCESS_DETAILS);
securityTransform.applyAccessControl((AccessControlled) ds, restModel);
}
return restModel;
} else {
// .orElseThrow(() -> new NotFoundException("No datasource exists with the given ID: " + idStr));
throw new NotFoundException("No datasource exists with the given ID: " + idStr);
}
});
}
Aggregations