Search in sources :

Example 1 with AccessControlled

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);
        }
    });
}
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.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

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 AccessControlled (com.thinkbiganalytics.security.AccessControlled)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