Search in sources :

Example 6 with AuthorisationServiceSupplier

use of io.aeron.security.AuthorisationServiceSupplier in project Aeron by real-logic.

the class ArchiveTest method shouldErrorWhenUnauthorised.

@Test
@InterruptAfter(10)
public void shouldErrorWhenUnauthorised() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
    final AuthorisationServiceSupplier authorisationServiceSupplier = () -> (protocolId, actionId, type, encodedPrincipal) -> {
        return actionId != TruncateRecordingRequestDecoder.TEMPLATE_ID;
    };
    final Archive.Context archiveCtx = new Archive.Context().deleteArchiveOnStart(true).authorisationServiceSupplier(authorisationServiceSupplier).threadingMode(SHARED);
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
        AeronArchive archive = AeronArchive.connect()) {
        try {
            archive.truncateRecording(0, 0);
        } catch (final ArchiveException ex) {
            assertEquals(ArchiveException.UNAUTHORISED_ACTION, ex.errorCode());
            return;
        }
        fail("Expected exception");
    } finally {
        archiveCtx.deleteDirectory();
        driverCtx.deleteDirectory();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) RecordingSubscriptionDescriptorConsumer(io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer) IntConsumer(java.util.function.IntConsumer) LOCAL(io.aeron.archive.codecs.SourceLocation.LOCAL) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronArchive(io.aeron.archive.client.AeronArchive) DEDICATED(io.aeron.archive.ArchiveThreadingMode.DEDICATED) Publication(io.aeron.Publication) MediaDriver(io.aeron.driver.MediaDriver) ManyToOneConcurrentLinkedQueue(org.agrona.concurrent.ManyToOneConcurrentLinkedQueue) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) TruncateRecordingRequestDecoder(io.aeron.archive.codecs.TruncateRecordingRequestDecoder) EXCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) DirectBuffer(org.agrona.DirectBuffer) Mockito.mock(org.mockito.Mockito.mock) Tests(io.aeron.test.Tests) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountersReader(org.agrona.concurrent.status.CountersReader) EnumSource(org.junit.jupiter.params.provider.EnumSource) ArrayList(java.util.ArrayList) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) Context(io.aeron.archive.Archive.Context) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) ValueSource(org.junit.jupiter.params.provider.ValueSource) RecordingPos(io.aeron.archive.status.RecordingPos) Aeron(io.aeron.Aeron) FileStore(java.nio.file.FileStore) SHARED(io.aeron.archive.ArchiveThreadingMode.SHARED) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MIN_CAPACITY(io.aeron.archive.Catalog.MIN_CAPACITY) ArchiveException(io.aeron.archive.client.ArchiveException) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions(org.junit.jupiter.api.Assertions) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) ArchiveException(io.aeron.archive.client.ArchiveException) AeronArchive(io.aeron.archive.client.AeronArchive) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 7 with AuthorisationServiceSupplier

use of io.aeron.security.AuthorisationServiceSupplier in project Aeron by real-logic.

the class ArchiveContextTests method shouldInstantiateAuthorisationServiceSupplierBasedOnTheSystemProperty.

@Test
void shouldInstantiateAuthorisationServiceSupplierBasedOnTheSystemProperty() {
    System.setProperty(AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME, TestAuthorisationSupplier.class.getName());
    try {
        context.conclude();
        final AuthorisationServiceSupplier supplier = context.authorisationServiceSupplier();
        assertNotSame(DEFAULT_AUTHORISATION_SERVICE_SUPPLIER, supplier);
        assertInstanceOf(TestAuthorisationSupplier.class, supplier);
    } finally {
        System.clearProperty(AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME);
    }
}
Also used : AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) Test(org.junit.jupiter.api.Test)

Example 8 with AuthorisationServiceSupplier

use of io.aeron.security.AuthorisationServiceSupplier in project Aeron by real-logic.

the class ArchiveContextTests method shouldUseProvidedAuthorisationServiceSupplierInstance.

@Test
void shouldUseProvidedAuthorisationServiceSupplierInstance() {
    final AuthorisationServiceSupplier providedSupplier = mock(AuthorisationServiceSupplier.class);
    context.authorisationServiceSupplier(providedSupplier);
    assertSame(providedSupplier, context.authorisationServiceSupplier());
    System.setProperty(AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME, TestAuthorisationSupplier.class.getName());
    try {
        context.conclude();
        assertSame(providedSupplier, context.authorisationServiceSupplier());
    } finally {
        System.clearProperty(AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME);
    }
}
Also used : AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) Test(org.junit.jupiter.api.Test)

Example 9 with AuthorisationServiceSupplier

use of io.aeron.security.AuthorisationServiceSupplier in project aeron by real-logic.

the class ArchiveTest method shouldErrorWhenUnauthorised.

@Test
@InterruptAfter(10)
public void shouldErrorWhenUnauthorised() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
    final AuthorisationServiceSupplier authorisationServiceSupplier = () -> (protocolId, actionId, type, encodedPrincipal) -> {
        return actionId != TruncateRecordingRequestDecoder.TEMPLATE_ID;
    };
    final Archive.Context archiveCtx = new Archive.Context().deleteArchiveOnStart(true).authorisationServiceSupplier(authorisationServiceSupplier).threadingMode(SHARED);
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
        AeronArchive archive = AeronArchive.connect()) {
        try {
            archive.truncateRecording(0, 0);
        } catch (final ArchiveException ex) {
            assertEquals(ArchiveException.UNAUTHORISED_ACTION, ex.errorCode());
            return;
        }
        fail("Expected exception");
    } finally {
        archiveCtx.deleteDirectory();
        driverCtx.deleteDirectory();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) RecordingSubscriptionDescriptorConsumer(io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer) IntConsumer(java.util.function.IntConsumer) LOCAL(io.aeron.archive.codecs.SourceLocation.LOCAL) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronArchive(io.aeron.archive.client.AeronArchive) DEDICATED(io.aeron.archive.ArchiveThreadingMode.DEDICATED) Publication(io.aeron.Publication) MediaDriver(io.aeron.driver.MediaDriver) ManyToOneConcurrentLinkedQueue(org.agrona.concurrent.ManyToOneConcurrentLinkedQueue) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) TruncateRecordingRequestDecoder(io.aeron.archive.codecs.TruncateRecordingRequestDecoder) EXCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) DirectBuffer(org.agrona.DirectBuffer) Mockito.mock(org.mockito.Mockito.mock) Tests(io.aeron.test.Tests) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountersReader(org.agrona.concurrent.status.CountersReader) EnumSource(org.junit.jupiter.params.provider.EnumSource) ArrayList(java.util.ArrayList) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) Context(io.aeron.archive.Archive.Context) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) ValueSource(org.junit.jupiter.params.provider.ValueSource) RecordingPos(io.aeron.archive.status.RecordingPos) Aeron(io.aeron.Aeron) FileStore(java.nio.file.FileStore) SHARED(io.aeron.archive.ArchiveThreadingMode.SHARED) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MIN_CAPACITY(io.aeron.archive.Catalog.MIN_CAPACITY) ArchiveException(io.aeron.archive.client.ArchiveException) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions(org.junit.jupiter.api.Assertions) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) ArchiveException(io.aeron.archive.client.ArchiveException) AeronArchive(io.aeron.archive.client.AeronArchive) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 10 with AuthorisationServiceSupplier

use of io.aeron.security.AuthorisationServiceSupplier in project aeron by real-logic.

the class ArchiveContextTests method shouldUseProvidedAuthorisationServiceSupplierInstance.

@Test
void shouldUseProvidedAuthorisationServiceSupplierInstance() {
    final AuthorisationServiceSupplier providedSupplier = mock(AuthorisationServiceSupplier.class);
    context.authorisationServiceSupplier(providedSupplier);
    assertSame(providedSupplier, context.authorisationServiceSupplier());
    System.setProperty(AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME, TestAuthorisationSupplier.class.getName());
    try {
        context.conclude();
        assertSame(providedSupplier, context.authorisationServiceSupplier());
    } finally {
        System.clearProperty(AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME);
    }
}
Also used : AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) Test(org.junit.jupiter.api.Test)

Aggregations

AuthorisationServiceSupplier (io.aeron.security.AuthorisationServiceSupplier)10 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Aeron (io.aeron.Aeron)2 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)2 CommonContext (io.aeron.CommonContext)2 Publication (io.aeron.Publication)2 Context (io.aeron.archive.Archive.Context)2 DEDICATED (io.aeron.archive.ArchiveThreadingMode.DEDICATED)2 SHARED (io.aeron.archive.ArchiveThreadingMode.SHARED)2 MIN_CAPACITY (io.aeron.archive.Catalog.MIN_CAPACITY)2 Checksum (io.aeron.archive.checksum.Checksum)2 AeronArchive (io.aeron.archive.client.AeronArchive)2 AeronArchive.segmentFileBasePosition (io.aeron.archive.client.AeronArchive.segmentFileBasePosition)2 ArchiveException (io.aeron.archive.client.ArchiveException)2 RecordingSubscriptionDescriptorConsumer (io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer)2 LOCAL (io.aeron.archive.codecs.SourceLocation.LOCAL)2 TruncateRecordingRequestDecoder (io.aeron.archive.codecs.TruncateRecordingRequestDecoder)2 RecordingPos (io.aeron.archive.status.RecordingPos)2 MediaDriver (io.aeron.driver.MediaDriver)2