use of com.thinkbiganalytics.metadata.api.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.datasetProvider.resolve(idStr);
com.thinkbiganalytics.metadata.api.datasource.Datasource ds = this.datasetProvider.getDatasource(id);
if (ds != null) {
final Datasource restModel = datasourceTransform.toDatasource(ds, sensitive ? DatasourceModelTransform.Level.ADMIN : DatasourceModelTransform.Level.FULL);
if (ds instanceof AccessControlled) {
securityTransform.applyAccessControl((AccessControlled) ds, restModel);
}
return restModel;
} else {
throw new NotFoundException("No datasource exists with the given ID: " + idStr);
}
});
}
Aggregations