Search in sources :

Example 16 with AuthenticationException

use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.

the class PravegaAuthManager method authenticate.

/**
 * API to authenticate and authroize access to a given resource.
 * @param resource The resource identifier for which the access needs to be controlled.
 * @param paramMap  Custom headers used for authentication.
 * @param level    Expected level of access.
 * @return         Returns true if the entity represented by the custom auth headers had given level of access to the resource.
 * @throws AuthenticationException Exception faced during authentication/authorization.
 */
public boolean authenticate(String resource, Map<String, String> paramMap, AuthHandler.Permissions level) throws AuthenticationException {
    boolean retVal = false;
    try {
        String method = paramMap.get("method");
        AuthHandler handler = getHandler(method);
        retVal = handler.authenticate(paramMap) && handler.authorize(resource, paramMap).ordinal() >= level.ordinal();
    } catch (RuntimeException e) {
        throw new AuthenticationException(e);
    }
    return retVal;
}
Also used : AuthHandler(io.pravega.auth.AuthHandler) AuthenticationException(io.pravega.common.auth.AuthenticationException)

Example 17 with AuthenticationException

use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.

the class SegmentHelper method sealSegment.

/**
 * This method sends segment sealed message for the specified segment.
 * It owns up the responsibility of retrying the operation on failures until success.
 *
 * @param scope               stream scope
 * @param stream              stream name
 * @param segmentNumber       number of segment to be sealed
 * @param hostControllerStore host controller store
 * @param clientCF            connection factory
 * @param delegationToken     the token to be presented to segmentstore.
 * @return void
 */
public CompletableFuture<Boolean> sealSegment(final String scope, final String stream, final int segmentNumber, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final CompletableFuture<Boolean> result = new CompletableFuture<>();
    final WireCommandType type = WireCommandType.SEAL_SEGMENT;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            log.warn("sealSegment {}/{}/{} connectionDropped", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            log.warn("sealSegment {}/{}/{} wrongHost", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
        }

        @Override
        public void segmentSealed(WireCommands.SegmentSealed segmentSealed) {
            log.info("sealSegment {}/{}/{} segmentSealed", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void segmentIsSealed(WireCommands.SegmentIsSealed segmentIsSealed) {
            log.info("sealSegment {}/{}/{} SegmentIsSealed", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("sealSegment {}/{}/{} failed", scope, stream, segmentNumber, error);
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
        }
    };
    WireCommands.SealSegment request = new WireCommands.SealSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), delegationToken);
    sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 18 with AuthenticationException

use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.

the class SegmentHelper method deleteSegment.

public CompletableFuture<Boolean> deleteSegment(final String scope, final String stream, final int segmentNumber, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
    final CompletableFuture<Boolean> result = new CompletableFuture<>();
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final WireCommandType type = WireCommandType.DELETE_SEGMENT;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            log.warn("deleteSegment {}/{}/{} Connection dropped", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            log.warn("deleteSegment {}/{}/{} wrong host", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
        }

        @Override
        public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
            log.info("deleteSegment {}/{}/{} NoSuchSegment", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void segmentDeleted(WireCommands.SegmentDeleted segmentDeleted) {
            log.info("deleteSegment {}/{}/{} SegmentDeleted", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("deleteSegment {}/{}/{} failed", scope, stream, segmentNumber, error);
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
        }
    };
    WireCommands.DeleteSegment request = new WireCommands.DeleteSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), delegationToken);
    sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 19 with AuthenticationException

use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.

the class SegmentHelper method getSegmentInfo.

public CompletableFuture<WireCommands.StreamSegmentInfo> getSegmentInfo(String scope, String stream, int segmentNumber, HostControllerStore hostControllerStore, ConnectionFactory clientCF, String delegationToken) {
    final CompletableFuture<WireCommands.StreamSegmentInfo> result = new CompletableFuture<>();
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final WireCommandType type = WireCommandType.GET_STREAM_SEGMENT_INFO;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            log.warn("getSegmentInfo {}/{}/{} connectionDropped", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            log.warn("getSegmentInfo {}/{}/{} WrongHost", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
        }

        @Override
        public void streamSegmentInfo(WireCommands.StreamSegmentInfo streamInfo) {
            log.info("getSegmentInfo {}/{}/{} got response", scope, stream, segmentNumber);
            result.complete(streamInfo);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("getSegmentInfo {}/{}/{} failed", scope, stream, segmentNumber, error);
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
        }
    };
    WireCommands.GetStreamSegmentInfo request = new WireCommands.GetStreamSegmentInfo(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), delegationToken);
    sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 20 with AuthenticationException

use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.

the class SegmentHelper method truncateSegment.

public CompletableFuture<Boolean> truncateSegment(final String scope, final String stream, final int segmentNumber, final long offset, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
    final CompletableFuture<Boolean> result = new CompletableFuture<>();
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final WireCommandType type = WireCommandType.TRUNCATE_SEGMENT;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            log.warn("truncateSegment {}/{}/{} Connection dropped", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            log.warn("truncateSegment {}/{}/{} Wrong host", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
        }

        @Override
        public void segmentTruncated(WireCommands.SegmentTruncated segmentTruncated) {
            log.info("truncateSegment {}/{}/{} SegmentTruncated", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void segmentIsTruncated(WireCommands.SegmentIsTruncated segmentIsTruncated) {
            log.info("truncateSegment {}/{}/{} SegmentIsTruncated", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("truncateSegment {}/{}/{} error", scope, stream, segmentNumber, error);
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
        }
    };
    WireCommands.TruncateSegment request = new WireCommands.TruncateSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), offset, delegationToken);
    sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Aggregations

AuthenticationException (io.pravega.common.auth.AuthenticationException)24 CompletableFuture (java.util.concurrent.CompletableFuture)19 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)14 WireCommands (io.pravega.shared.protocol.netty.WireCommands)10 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)9 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)9 WireCommandType (io.pravega.shared.protocol.netty.WireCommandType)9 AuthHandler (io.pravega.auth.AuthHandler)6 READ (io.pravega.auth.AuthHandler.Permissions.READ)5 READ_UPDATE (io.pravega.auth.AuthHandler.Permissions.READ_UPDATE)5 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)5 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)5 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)5 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)5 ReaderGroup (io.pravega.client.stream.ReaderGroup)5 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)5 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)5 LoggerHelpers (io.pravega.common.LoggerHelpers)5 ControllerService (io.pravega.controller.server.ControllerService)5 LocalController (io.pravega.controller.server.eventProcessor.LocalController)5