use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class IdentityZoneEndpointsMockMvcTests method testDeleteZonePublishesEvent.
@Test
void testDeleteZonePublishesEvent() throws Exception {
String id = generator.generate();
IdentityZone zone = createZone(id, HttpStatus.CREATED, identityClientToken, new IdentityZoneConfiguration());
uaaEventListener.clearEvents();
ResultActions result = mockMvc.perform(delete("/identity-zones/{id}", zone.getId()).header("Authorization", "Bearer " + identityClientToken).accept(APPLICATION_JSON)).andExpect(status().isOk());
IdentityZone deletedZone = JsonUtils.readValue(result.andReturn().getResponse().getContentAsString(), IdentityZone.class);
assertEquals(Collections.EMPTY_MAP, deletedZone.getConfig().getTokenPolicy().getKeys());
assertNull(deletedZone.getConfig().getSamlConfig().getPrivateKey());
assertNull(deletedZone.getConfig().getSamlConfig().getPrivateKeyPassword());
assertEquals(serviceProviderCertificate, deletedZone.getConfig().getSamlConfig().getCertificate());
assertThat(uaaEventListener.getEventCount(), is(1));
AbstractUaaEvent event = uaaEventListener.getLatestEvent();
assertThat(event, instanceOf(EntityDeletedEvent.class));
EntityDeletedEvent deletedEvent = (EntityDeletedEvent) event;
assertThat(deletedEvent.getDeleted(), instanceOf(IdentityZone.class));
deletedZone = (IdentityZone) deletedEvent.getDeleted();
assertThat(deletedZone.getId(), is(id));
assertThat(deletedEvent.getIdentityZoneId(), is(id));
String auditedIdentityZone = deletedEvent.getAuditEvent().getData();
assertThat(auditedIdentityZone, containsString(id));
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class TotpMfaEndpointTest method verifyMfaEvent.
private void verifyMfaEvent(Class<? extends AbstractUaaEvent> eventClass) {
List<ApplicationEvent> values = eventCaptor.getAllValues();
assertEquals(1, values.size());
ApplicationEvent event = values.get(0);
assertThat(event, instanceOf(eventClass));
AbstractUaaEvent mfaEvent = (AbstractUaaEvent) event;
assertEquals("google-authenticator", mfaEvent.getAuditEvent().getAuthenticationType());
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent 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));
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class ClientAdminEndpointsMockMvcTests method testClientCRUDAsAdminUser.
@Test
void testClientCRUDAsAdminUser() throws Exception {
setupAdminUserToken();
ClientDetails client = createClient(adminUserToken, SECRET, new RandomValueStringGenerator().generate(), Collections.singleton("client_credentials"));
verify(mockApplicationEventPublisher, times(2)).publishEvent(abstractUaaEventCaptor.capture());
for (AbstractUaaEvent event : abstractUaaEventCaptor.getAllValues()) {
assertEquals(AuditEventType.ClientCreateSuccess, event.getAuditEvent().getType());
}
MockHttpServletRequestBuilder getClient = get("/oauth/clients/" + client.getClientId()).header("Authorization", "Bearer " + adminUserToken).accept(APPLICATION_JSON);
MvcResult mvcResult = mockMvc.perform(getClient).andExpect(status().isOk()).andReturn();
BaseClientDetails clientDetails = JsonUtils.readValue(mvcResult.getResponse().getContentAsString(), BaseClientDetails.class);
assertEquals(client.getClientId(), clientDetails.getClientId());
clientDetails.setAuthorizedGrantTypes(Collections.singleton(GRANT_TYPE_AUTHORIZATION_CODE));
MockHttpServletRequestBuilder updateClient = put("/oauth/clients/" + client.getClientId()).header("Authorization", "Bearer" + adminUserToken).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(clientDetails));
MvcResult result = mockMvc.perform(updateClient).andExpect(status().isOk()).andReturn();
BaseClientDetails updatedClientDetails = JsonUtils.readValue(result.getResponse().getContentAsString(), BaseClientDetails.class);
assertEquals(client.getClientId(), updatedClientDetails.getClientId());
assertThat(updatedClientDetails.getAuthorizedGrantTypes(), PredicateMatcher.has(m -> m.equals(GRANT_TYPE_AUTHORIZATION_CODE)));
MockHttpServletRequestBuilder deleteClient = delete("/oauth/clients/" + client.getClientId()).header("Authorization", "Bearer" + adminUserToken).accept(APPLICATION_JSON);
MvcResult deleteResult = mockMvc.perform(deleteClient).andExpect(status().isOk()).andReturn();
BaseClientDetails deletedClientDetails = JsonUtils.readValue(deleteResult.getResponse().getContentAsString(), BaseClientDetails.class);
assertEquals(client.getClientId(), deletedClientDetails.getClientId());
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class TotpMfaEndpointMockMvcTests method setup.
@BeforeEach
void setup(@Autowired TestClient testClient, @Autowired ConfigurableApplicationContext configurableApplicationContext, @Autowired ScimUserProvisioning scimUserProvisioning) throws Exception {
adminToken = testClient.getClientCredentialsOAuthAccessToken("admin", "adminsecret", "clients.read clients.write clients.secret clients.admin uaa.admin");
mfaProvider = createMfaProvider(webApplicationContext, IdentityZone.getUaa());
otherMfaProvider = createMfaProvider(webApplicationContext, IdentityZone.getUaa());
uaaZoneConfig = MockMvcUtils.getZoneConfiguration(webApplicationContext, IdentityZone.getUaaZoneId());
uaaZoneConfig.getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
MockMvcUtils.setZoneConfiguration(webApplicationContext, IdentityZone.getUaaZoneId(), uaaZoneConfig);
// noinspection unchecked
applicationListener = (ApplicationListener<AbstractUaaEvent>) mock(ApplicationListener.class);
configurableApplicationContext.addApplicationListener(applicationListener);
password = "sec3Tas";
scimUser = createUser(scimUserProvisioning, password);
mockHttpSession = new MockHttpSession();
}
Aggregations