Search in sources :

Example 1 with HttpURLConnectionWrapper

use of org.forgerock.openam.sts.HttpURLConnectionWrapper in project OpenAM by OpenRock.

the class AuditEventPublisherTest method mockHttpURLConnectionWrapper.

@SuppressWarnings("unchecked")
private HttpURLConnectionWrapper mockHttpURLConnectionWrapper(final ArgumentCaptor<Map> headersCaptor, final ArgumentCaptor<String> methodCaptor, final ArgumentCaptor<String> payloadCaptor) throws ProtocolException {
    HttpURLConnectionWrapper httpURLConnectionWrapper = mock(HttpURLConnectionWrapper.class);
    given(httpURLConnectionWrapper.withoutAuditTransactionIdHeader()).willReturn(httpURLConnectionWrapper);
    given(httpURLConnectionWrapper.setRequestHeaders(headersCaptor.capture())).willReturn(httpURLConnectionWrapper);
    given(httpURLConnectionWrapper.setRequestMethod(methodCaptor.capture())).willReturn(httpURLConnectionWrapper);
    given(httpURLConnectionWrapper.setRequestPayload(payloadCaptor.capture())).willReturn(httpURLConnectionWrapper);
    return httpURLConnectionWrapper;
}
Also used : HttpURLConnectionWrapper(org.forgerock.openam.sts.HttpURLConnectionWrapper)

Example 2 with HttpURLConnectionWrapper

use of org.forgerock.openam.sts.HttpURLConnectionWrapper in project OpenAM by OpenRock.

the class AuditEventPublisherTest method publishesAuditEventsToAMAuditServiceEndpoint.

@Test
public void publishesAuditEventsToAMAuditServiceEndpoint() throws Exception {
    ArgumentCaptor<URL> urlCaptor = ArgumentCaptor.forClass(URL.class);
    ArgumentCaptor<Map> headersCaptor = ArgumentCaptor.forClass(Map.class);
    ArgumentCaptor<String> methodCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
    // Given
    AuditEvent auditEvent = mockAuditEvent("event-as-json");
    HttpURLConnectionWrapper httpURLConnectionWrapper = mockHttpURLConnectionWrapper(headersCaptor, methodCaptor, payloadCaptor);
    given(soapSTSAccessTokenProvider.getAccessToken()).willReturn("ssoTokenId");
    given(httpURLConnectionWrapperFactory.httpURLConnectionWrapper(urlCaptor.capture())).willReturn(httpURLConnectionWrapper);
    // When
    auditEventPublisher.tryPublish(AuditConstants.ACCESS_TOPIC, auditEvent);
    // Then
    verify(soapSTSAccessTokenProvider, times(1)).getAccessToken();
    assertThat(urlCaptor.getValue()).isEqualTo(new URL("http://openam.example.com:8080/openam/json/audit/access/?_action=create"));
    assertThat(headersCaptor.getValue().get(AMSTSConstants.CONTENT_TYPE)).isEqualTo(AMSTSConstants.APPLICATION_JSON);
    assertThat(headersCaptor.getValue().get(AMSTSConstants.CREST_VERSION_HEADER_KEY)).isEqualTo("protocol=1.0, resource=1.0");
    assertThat(headersCaptor.getValue().get(AMSTSConstants.COOKIE)).isEqualTo("iPlanetDirectoryPro=ssoTokenId");
    assertThat(methodCaptor.getValue()).isEqualToIgnoringCase(AMSTSConstants.GET);
    assertThat(payloadCaptor.getValue()).isEqualToIgnoringCase("event-as-json");
    verify(soapSTSAccessTokenProvider, times(1)).invalidateAccessToken("ssoTokenId");
}
Also used : HttpURLConnectionWrapper(org.forgerock.openam.sts.HttpURLConnectionWrapper) AuditEvent(org.forgerock.audit.events.AuditEvent) Map(java.util.Map) URL(java.net.URL) Test(org.testng.annotations.Test)

Aggregations

HttpURLConnectionWrapper (org.forgerock.openam.sts.HttpURLConnectionWrapper)2 URL (java.net.URL)1 Map (java.util.Map)1 AuditEvent (org.forgerock.audit.events.AuditEvent)1 Test (org.testng.annotations.Test)1