use of io.pravega.controller.server.security.auth.handler.AuthContext in project pravega by pravega.
the class ControllerServiceImpl method listStreamsInScope.
@Override
public void listStreamsInScope(Controller.StreamsInScopeRequest request, StreamObserver<Controller.StreamsInScopeResponse> responseObserver) {
String scopeName = request.getScope().getScope();
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), LIST_STREAMS_IN_SCOPE, scopeName);
log.info(requestTag.getRequestId(), "listStream called for scope {}.", scopeName);
final AuthContext ctx = this.grpcAuthHelper.isAuthEnabled() ? AuthContext.current() : null;
Function<String, CompletableFuture<Controller.StreamsInScopeResponse>> streamsFn = delegationToken -> listWithFilter(request.getContinuationToken().getToken(), pageLimit, (x, y) -> controllerService.listStreams(scopeName, x, y, requestTag.getRequestId()), x -> grpcAuthHelper.isAuthorized(authorizationResource.ofStreamInScope(scopeName, x), AuthHandler.Permissions.READ, ctx), x -> StreamInfo.newBuilder().setScope(scopeName).setStream(x).build(), requestTag.getRequestId()).handle((response, ex) -> {
if (ex != null) {
if (Exceptions.unwrap(ex) instanceof StoreException.DataNotFoundException) {
return Controller.StreamsInScopeResponse.newBuilder().setStatus(Controller.StreamsInScopeResponse.Status.SCOPE_NOT_FOUND).build();
} else {
throw new CompletionException(ex);
}
} else {
return Controller.StreamsInScopeResponse.newBuilder().addAllStreams(response.getKey()).setContinuationToken(Controller.ContinuationToken.newBuilder().setToken(response.getValue()).build()).setStatus(Controller.StreamsInScopeResponse.Status.SUCCESS).build();
}
});
authenticateExecuteAndProcessResults(() -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofScope(scopeName), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScope(scopeName), result);
return result;
}, streamsFn, responseObserver, requestTag);
}
use of io.pravega.controller.server.security.auth.handler.AuthContext in project pravega by pravega.
the class ControllerServiceImpl method getStreamConfiguration.
@Override
public void getStreamConfiguration(StreamInfo request, StreamObserver<StreamConfig> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), GET_STREAM_CONFIGURATION);
String scope = request.getScope();
String stream = request.getStream();
log.info(requestTag.getRequestId(), "{} called for {}/{}.", GET_STREAM_CONFIGURATION, scope, stream);
final AuthContext ctx;
if (this.grpcAuthHelper.isAuthEnabled()) {
ctx = AuthContext.current();
} else {
ctx = null;
}
Supplier<String> stringSupplier = () -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(scope, stream), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScopes(), result);
return result;
};
Function<String, CompletableFuture<StreamConfig>> streamFn = delegationToken -> controllerService.getStream(scope, stream, requestTag.getRequestId()).handle((response, e) -> {
if (e != null) {
throw new CompletionException(e);
} else {
return decode(scope, stream, response);
}
});
authenticateExecuteAndProcessResults(stringSupplier, streamFn, responseObserver, requestTag);
}
Aggregations