Search in sources :

Example 1 with AuditEventType

use of org.cloudfoundry.identity.uaa.audit.AuditEventType in project uaa by cloudfoundry.

the class AuditCheckMockMvcTests method assertSingleClientAdminAuditEventFiredWith.

private void assertSingleClientAdminAuditEventFiredWith(AuditEventType expectedEventType, String[] expectedScopes, String[] expectedAuthorities) {
    List<AbstractUaaEvent> events = testListener.getEvents().stream().filter(e -> e instanceof AbstractClientAdminEvent).collect(Collectors.toList());
    assertNotNull(events);
    assertEquals(1, events.size());
    AbstractUaaEvent event = events.get(0);
    assertEquals(expectedEventType, event.getAuditEvent().getType());
    ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
    verify(mockAuditService, atLeast(1)).log(captor.capture(), anyString());
    List<AuditEvent> auditEvents = captor.getAllValues().stream().filter(e -> e.getType() == expectedEventType).collect(Collectors.toList());
    assertNotNull(auditEvents);
    assertEquals(1, auditEvents.size());
    AuditEvent auditEvent = auditEvents.get(0);
    String auditEventData = auditEvent.getData();
    assertNotNull(auditEventData);
    Map<String, Object> map = JsonUtils.readValue(auditEventData, new TypeReference<Map<String, Object>>() {
    });
    List<String> auditScopes = (List<String>) map.get("scopes");
    List<String> auditAuthorities = (List<String>) map.get("authorities");
    assertNotNull(auditScopes);
    assertNotNull(auditAuthorities);
    assertThat(auditScopes, containsInAnyOrder(expectedScopes));
    assertThat(auditAuthorities, containsInAnyOrder(expectedAuthorities));
}
Also used : TokenIssuedEvent(org.cloudfoundry.identity.uaa.audit.event.TokenIssuedEvent) BeforeEach(org.junit.jupiter.api.BeforeEach) org.cloudfoundry.identity.uaa.test(org.cloudfoundry.identity.uaa.test) FilterChainProxy(org.springframework.security.web.FilterChainProxy) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditListener(org.cloudfoundry.identity.uaa.audit.event.AuditListener) Base64(org.apache.commons.codec.binary.Base64) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) OriginKeys(org.cloudfoundry.identity.uaa.constants.OriginKeys) ResultActions(org.springframework.test.web.servlet.ResultActions) Matcher(java.util.regex.Matcher) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) LostPasswordChangeRequest(org.cloudfoundry.identity.uaa.account.LostPasswordChangeRequest) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationListener(org.springframework.context.ApplicationListener) MockHttpSession(org.springframework.mock.web.MockHttpSession) MockMvcResultMatchers(org.springframework.test.web.servlet.result.MockMvcResultMatchers) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Test(org.junit.jupiter.api.Test) CookieCsrfPostProcessor.cookieCsrf(org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.CookieCsrfPostProcessor.cookieCsrf) DefaultTestContext(org.cloudfoundry.identity.uaa.DefaultTestContext) AuthzAuthenticationManager(org.cloudfoundry.identity.uaa.authentication.manager.AuthzAuthenticationManager) Stream(java.util.stream.Stream) RegexMatcher.matchesRegex(org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils.RegexMatcher.matchesRegex) ApprovalModifiedEvent(org.cloudfoundry.identity.uaa.audit.event.ApprovalModifiedEvent) JsonUtils(org.cloudfoundry.identity.uaa.util.JsonUtils) Pattern(java.util.regex.Pattern) AuditEventType(org.cloudfoundry.identity.uaa.audit.AuditEventType) Base64Utils.encode(org.springframework.util.Base64Utils.encode) Authentication(org.springframework.security.core.Authentication) org.cloudfoundry.identity.uaa.audit(org.cloudfoundry.identity.uaa.audit) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) PasswordChangeEvent(org.cloudfoundry.identity.uaa.account.event.PasswordChangeEvent) java.util(java.util) MessageDigest(java.security.MessageDigest) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) MultitenantClientServices(org.cloudfoundry.identity.uaa.zone.MultitenantClientServices) UaaAuthenticationDetails(org.cloudfoundry.identity.uaa.authentication.UaaAuthenticationDetails) MockMvcUtils(org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils) Nested(org.junit.jupiter.api.Nested) Utf8(org.springframework.security.crypto.codec.Utf8) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Value(org.springframework.beans.factory.annotation.Value) MockMvc(org.springframework.test.web.servlet.MockMvc) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) MockMvcUtils.httpBearer(org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.httpBearer) MvcResult(org.springframework.test.web.servlet.MvcResult) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractClientAdminEvent(org.cloudfoundry.identity.uaa.client.event.AbstractClientAdminEvent) Approval(org.cloudfoundry.identity.uaa.approval.Approval) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) org.cloudfoundry.identity.uaa.scim(org.cloudfoundry.identity.uaa.scim) Logger(org.slf4j.Logger) AbstractUaaEvent(org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent) InterceptingLogger(org.cloudfoundry.identity.uaa.mock.util.InterceptingLogger) JdbcScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning) Matchers(org.hamcrest.Matchers) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) UserModifiedEvent(org.cloudfoundry.identity.uaa.scim.event.UserModifiedEvent) ApplicationEvent(org.springframework.context.ApplicationEvent) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) org.cloudfoundry.identity.uaa.authentication.event(org.cloudfoundry.identity.uaa.authentication.event) ResetPasswordRequestEvent(org.cloudfoundry.identity.uaa.account.event.ResetPasswordRequestEvent) Assertions(org.junit.jupiter.api.Assertions) GroupModifiedEvent(org.cloudfoundry.identity.uaa.scim.event.GroupModifiedEvent) PasswordChangeFailureEvent(org.cloudfoundry.identity.uaa.account.event.PasswordChangeFailureEvent) StringUtils(org.springframework.util.StringUtils) AbstractClientAdminEvent(org.cloudfoundry.identity.uaa.client.event.AbstractClientAdminEvent) AbstractUaaEvent(org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 MessageDigest (java.security.MessageDigest)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Collectors.joining (java.util.stream.Collectors.joining)1 Stream (java.util.stream.Stream)1 Base64 (org.apache.commons.codec.binary.Base64)1 DefaultTestContext (org.cloudfoundry.identity.uaa.DefaultTestContext)1 LostPasswordChangeRequest (org.cloudfoundry.identity.uaa.account.LostPasswordChangeRequest)1 PasswordChangeEvent (org.cloudfoundry.identity.uaa.account.event.PasswordChangeEvent)1 PasswordChangeFailureEvent (org.cloudfoundry.identity.uaa.account.event.PasswordChangeFailureEvent)1 ResetPasswordRequestEvent (org.cloudfoundry.identity.uaa.account.event.ResetPasswordRequestEvent)1 Approval (org.cloudfoundry.identity.uaa.approval.Approval)1 org.cloudfoundry.identity.uaa.audit (org.cloudfoundry.identity.uaa.audit)1 AuditEventType (org.cloudfoundry.identity.uaa.audit.AuditEventType)1