Search in sources :

Example 1 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesTokenWithReadForInternalStreamsWhenRequestedIsSame.

@Test
public void supplierCreatesTokenWithReadForInternalStreamsWhenRequestedIsSame() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String streamResource = new AuthorizationResourceImpl().ofStreamInScope("testScope", "_testStream");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "_testStream", AccessOperation.READ);
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(streamResource, AuthHandler.Permissions.READ);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(request).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 2 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesTokenWithRequestedReadPermission.

@Test
public void supplierCreatesTokenWithRequestedReadPermission() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String streamResource = new AuthorizationResourceImpl().ofStreamInScope("testScope", "testStream");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "testStream", AccessOperation.READ);
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(streamResource, AuthHandler.Permissions.READ);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(request).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 3 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesTokenWithReadWritePermissionByDefault.

@Test
public void supplierCreatesTokenWithReadWritePermissionByDefault() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String streamResource = new AuthorizationResourceImpl().ofStreamInScope("testScope", "testStream");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "testStream", null);
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ_UPDATE);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(streamResource, AuthHandler.Permissions.READ_UPDATE);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(request).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 4 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierForMarkStreams.

@Test
public void supplierForMarkStreams() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    AuthorizationResource authResource = new AuthorizationResourceImpl();
    String markStreamResource = authResource.ofStreamInScope("testScope", "_MARKtestStream");
    String streamResource = authResource.ofStreamInScope("testScope", "testStream");
    Controller.StreamInfo readRequest = createStreamInfoProtobufMessage("testScope", "_MARKtestStream", AccessOperation.READ);
    Controller.StreamInfo writeRequest = createStreamInfoProtobufMessage("testScope", "_MARKtestStream", AccessOperation.READ_WRITE);
    // For mark streams, authorization is done against the corresponding stream
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ);
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ_UPDATE);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(markStreamResource, AuthHandler.Permissions.READ);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(markStreamResource, AuthHandler.Permissions.READ_UPDATE);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(readRequest).get());
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(writeRequest).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AuthorizationResource(io.pravega.shared.security.auth.AuthorizationResource) Test(org.junit.Test)

Example 5 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesAppropriateTokenForRGStreamsBasedOnAccessOperation.

@Test
public void supplierCreatesAppropriateTokenForRGStreamsBasedOnAccessOperation() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String resource = new AuthorizationResourceImpl().ofInternalStream("testScope", "_RGtestApp");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "_RGtestApp", AccessOperation.READ_WRITE);
    doReturn("").when(mockAuthHelper).checkAuthorization(resource, AuthHandler.Permissions.READ);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken("prn::/scope:testScope/stream:_RGtestApp", AuthHandler.Permissions.READ_UPDATE);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(request).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Aggregations

GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)8 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)8 AuthorizationResourceImpl (io.pravega.shared.security.auth.AuthorizationResourceImpl)8 Test (org.junit.Test)8 AuthorizationResource (io.pravega.shared.security.auth.AuthorizationResource)1