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();
}
}
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);
}
}
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);
}
}
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();
}
}
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);
}
}
Aggregations