Search in sources :

Example 1 with AMAuditServiceConfiguration

use of org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration in project OpenAM by OpenRock.

the class AuditServiceProviderImplTest method shouldNotRegisterHandlersWhenRealmAuditServiceDisabled.

@Test
public void shouldNotRegisterHandlersWhenRealmAuditServiceDisabled() throws Exception {
    // Given
    auditServiceConfig = new AMAuditServiceConfiguration(false);
    // When
    configListener.realmConfigurationChanged("anyRealm");
    // Then
    assertThat(provider.getAuditService("anyRealm").getRegisteredHandler("Mock Handler")).isNull();
}
Also used : AMAuditServiceConfiguration(org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration) Test(org.testng.annotations.Test)

Example 2 with AMAuditServiceConfiguration

use of org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration in project OpenAM by OpenRock.

the class AuditServiceProviderImplTest method setUp.

@BeforeMethod
protected void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Map<String, Set<String>> configAttributes = new HashMap<>();
    configAttributes.put("handlerFactory", singleton(MockAuditEventHandlerFactory.class.getName()));
    configAttributes.put("topics", singleton("access"));
    configAttributes.put("enabled", singleton("true"));
    AuditEventHandlerConfiguration configuration = AuditEventHandlerConfiguration.builder().withName("Mock Handler").withAttributes(configAttributes).withEventTopicsMetaData(EventTopicsMetaDataBuilder.coreTopicSchemas().build()).build();
    handlerConfigs.add(configuration);
    configAttributes = new HashMap<>();
    configAttributes.put("handlerFactory", singleton("no.such.class"));
    configAttributes.put("topics", singleton("access"));
    configAttributes.put("enabled", singleton("true"));
    configuration = AuditEventHandlerConfiguration.builder().withName("No such handler").withAttributes(configAttributes).withEventTopicsMetaData(EventTopicsMetaDataBuilder.coreTopicSchemas().build()).build();
    handlerConfigs.add(configuration);
    auditServiceConfig = new AMAuditServiceConfiguration(true);
    provider = new AuditServiceProviderImpl(new MockAuditServiceConfigurationProvider(), mockShutdownManager);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AuditEventHandlerConfiguration(org.forgerock.openam.audit.configuration.AuditEventHandlerConfiguration) AMAuditServiceConfiguration(org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with AMAuditServiceConfiguration

use of org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration 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());
}
Also used : Context(org.forgerock.services.context.Context) AuditServiceBuilder(org.forgerock.audit.AuditServiceBuilder) AuditEvent(org.forgerock.audit.events.AuditEvent) AuditEventHandler(org.forgerock.audit.events.handlers.AuditEventHandler) AMAuditServiceConfiguration(org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration) Test(org.testng.annotations.Test)

Example 4 with AMAuditServiceConfiguration

use of org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration 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);
    }
}
Also used : AuditServiceBuilder(org.forgerock.audit.AuditServiceBuilder) AMAuditServiceConfiguration(org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration) ServiceUnavailableException(org.forgerock.json.resource.ServiceUnavailableException)

Example 5 with AMAuditServiceConfiguration

use of org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration in project OpenAM by OpenRock.

the class AbstractRestletAccessAuditFilterTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    restlet = mock(Restlet.class);
    AMAuditServiceConfiguration serviceConfig = new AMAuditServiceConfiguration(true);
    AuditServiceBuilder builder = AuditServiceBuilder.newAuditService().withConfiguration(serviceConfig);
    AMAuditService auditService = new DefaultAuditServiceProxy(builder.build(), serviceConfig);
    auditService.startup();
    auditServiceProvider = mock(AuditServiceProvider.class);
    when(auditServiceProvider.getDefaultAuditService()).thenReturn(auditService);
    eventFactory = new AuditEventFactory();
    eventPublisher = mock(AuditEventPublisher.class);
    auditFilter = new RestletAccessAuditFilterTest(restlet, eventPublisher, eventFactory, null, null);
}
Also used : AuditServiceBuilder(org.forgerock.audit.AuditServiceBuilder) DefaultAuditServiceProxy(org.forgerock.openam.audit.DefaultAuditServiceProxy) AuditServiceProvider(org.forgerock.openam.audit.AuditServiceProvider) Restlet(org.restlet.Restlet) AMAuditService(org.forgerock.openam.audit.AMAuditService) AuditEventFactory(org.forgerock.openam.audit.AuditEventFactory) AMAuditServiceConfiguration(org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration) AuditEventPublisher(org.forgerock.openam.audit.AuditEventPublisher) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

AMAuditServiceConfiguration (org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration)10 AuditServiceBuilder (org.forgerock.audit.AuditServiceBuilder)7 ServiceUnavailableException (org.forgerock.json.resource.ServiceUnavailableException)3 Test (org.testng.annotations.Test)3 BeforeMethod (org.testng.annotations.BeforeMethod)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AuditEvent (org.forgerock.audit.events.AuditEvent)1 AuditEventHandler (org.forgerock.audit.events.handlers.AuditEventHandler)1 AMAuditService (org.forgerock.openam.audit.AMAuditService)1 AuditEventFactory (org.forgerock.openam.audit.AuditEventFactory)1 AuditEventPublisher (org.forgerock.openam.audit.AuditEventPublisher)1 AuditServiceProvider (org.forgerock.openam.audit.AuditServiceProvider)1 DefaultAuditServiceProxy (org.forgerock.openam.audit.DefaultAuditServiceProxy)1 AuditEventHandlerConfiguration (org.forgerock.openam.audit.configuration.AuditEventHandlerConfiguration)1 Context (org.forgerock.services.context.Context)1 Restlet (org.restlet.Restlet)1