Search in sources :

Example 1 with AccessControlled

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);
        }
    });
}
Also used : JdbcDatasource(com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource) UserDatasource(com.thinkbiganalytics.metadata.rest.model.data.UserDatasource) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) AccessControlled(com.thinkbiganalytics.metadata.api.security.AccessControlled) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

AccessControlled (com.thinkbiganalytics.metadata.api.security.AccessControlled)1 Datasource (com.thinkbiganalytics.metadata.rest.model.data.Datasource)1 JdbcDatasource (com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource)1 UserDatasource (com.thinkbiganalytics.metadata.rest.model.data.UserDatasource)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1