use of org.forgerock.audit.AuditServiceBuilder in project OpenAM by OpenRock.
the class AuditEventPublisherImplTest method shouldFallBackToDefaultAuditServiceWhenRealmHasShutDown.
@Test
public void shouldFallBackToDefaultAuditServiceWhenRealmHasShutDown() throws Exception {
// Given
AuditEvent auditEvent = getAuditEvent("deadRealm");
givenDefaultAuditService();
when(mockHandler.publishEvent(any(Context.class), eq("access"), auditEventCaptor.capture())).thenReturn(dummyPromise);
AMAuditServiceConfiguration serviceConfig = new AMAuditServiceConfiguration(true);
AuditServiceBuilder builder = AuditServiceBuilder.newAuditService().withConfiguration(serviceConfig).withAuditEventHandler(mock(AuditEventHandler.class));
AMAuditService auditService = new RealmAuditServiceProxy(builder.build(), mock(AMAuditService.class), serviceConfig);
auditService.startup();
auditService.shutdown();
when(auditServiceProvider.getAuditService("deadRealm")).thenReturn(auditService);
// When
auditEventPublisher.tryPublish("access", auditEvent);
// Then
assertThat(auditEventCaptor.getValue()).isEqualTo(auditEvent.getValue());
}
use of org.forgerock.audit.AuditServiceBuilder in project OpenAM by OpenRock.
the class AuditServiceProviderImpl method refreshDefaultAuditService.
private void refreshDefaultAuditService() {
AMAuditServiceConfiguration configuration = configProvider.getDefaultConfiguration();
AuditServiceBuilder builder = AuditServiceBuilder.newAuditService().withEventTopicsMetaData(eventTopicsMetaData).withConfiguration(configuration);
if (configuration.isAuditEnabled()) {
configureEventHandlers(builder, configProvider.getDefaultEventHandlerConfigurations());
}
try {
defaultAuditService.setDelegate(builder.build(), configuration);
} catch (ServiceUnavailableException e) {
debug.error("Default Audit Service configuration failed.", e);
}
}
use of org.forgerock.audit.AuditServiceBuilder in project OpenAM by OpenRock.
the class AuditEventPublisherImplTest method givenDefaultAuditService.
private void givenDefaultAuditService() throws ServiceUnavailableException, AuditException {
AMAuditServiceConfiguration serviceConfig = new AMAuditServiceConfiguration(true);
AuditServiceBuilder builder = AuditServiceBuilder.newAuditService().withConfiguration(serviceConfig).withAuditEventHandler(mockHandler);
AMAuditService auditService = new DefaultAuditServiceProxy(builder.build(), serviceConfig);
auditService.startup();
when(auditServiceProvider.getDefaultAuditService()).thenReturn(auditService);
}
use of org.forgerock.audit.AuditServiceBuilder in project OpenAM by OpenRock.
the class AuditEventPublisherImplTest method givenSuppressedFailureAuditService.
private void givenSuppressedFailureAuditService() throws ServiceUnavailableException, AuditException {
AMAuditServiceConfiguration serviceConfig = new AMAuditServiceConfiguration(true);
AuditServiceBuilder builder = AuditServiceBuilder.newAuditService().withConfiguration(serviceConfig).withAuditEventHandler(mockHandler);
AMAuditService auditService = new RealmAuditServiceProxy(builder.build(), mock(AMAuditService.class), serviceConfig);
auditService.startup();
when(auditServiceProvider.getAuditService(FAILURE_SUPPRESSED_REALM)).thenReturn(auditService);
}
use of org.forgerock.audit.AuditServiceBuilder in project OpenAM by OpenRock.
the class AuditServiceProviderImpl method refreshRealmAuditService.
private void refreshRealmAuditService(String realm) {
AMAuditServiceConfiguration configuration = configProvider.getRealmConfiguration(realm);
AuditServiceBuilder builder = AuditServiceBuilder.newAuditService().withEventTopicsMetaData(eventTopicsMetaData).withConfiguration(configuration);
if (configuration.isAuditEnabled()) {
configureEventHandlers(builder, configProvider.getRealmEventHandlerConfigurations(realm));
}
AMAuditService auditService = auditServices.get(realm);
try {
if (auditService == null) {
auditService = new RealmAuditServiceProxy(builder.build(), defaultAuditService, configuration);
auditService.startup();
auditServices.put(realm, auditService);
} else {
auditService.setDelegate(builder.build(), configuration);
}
} catch (ServiceUnavailableException e) {
debug.error("New Audit Service configuration for realm {} failed.", e, realm);
// remove it so that we can fall back to the default service
auditServices.remove(realm);
}
}
Aggregations