use of org.apache.cxf.message.Message in project ddf by codice.
the class MetricsInInterceptorTest method testHandleMessageWithTwoWayClientMessageWithLatencyTimeRecorder.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsInInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithTwoWayClientMessageWithLatencyTimeRecorder() {
// Setup
MetricsInInterceptor inInterceptor = new MetricsInInterceptor();
Message mockMessage = mock(Message.class);
Exchange ex = new ExchangeImpl();
Bus mockBus = mock(Bus.class);
LatencyTimeRecorder mockLtr = mock(LatencyTimeRecorder.class);
ex.put(Bus.class, mockBus);
ex.put(LatencyTimeRecorder.class, mockLtr);
when(mockBus.getId()).thenReturn("bus_id");
when(mockMessage.getExchange()).thenReturn(ex);
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
// Perform test
inInterceptor.handleMessage(mockMessage);
// validate that LatencyTimeRecorder.beginHandling was called once
verify(mockLtr, times(1)).endHandling();
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class MetricsInInterceptorTest method testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsInInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder() {
// Setup
MetricsInInterceptor inInterceptor = new MetricsInInterceptor();
Message mockMessage = mock(Message.class);
Exchange ex = new ExchangeImpl();
Bus mockBus = mock(Bus.class);
ex.put(Bus.class, mockBus);
when(mockBus.getId()).thenReturn("bus_id");
when(mockMessage.getExchange()).thenReturn(ex);
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
// Perform test
inInterceptor.handleMessage(mockMessage);
// validate that there is not an instance of LatencyTimeRecorder on the
// exchange
assertNull(ex.get(LatencyTimeRecorder.class));
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class CrlInterceptorTest method testErrorThrownWithFailedCert.
/**
* Tests that the interceptor will throw an error if the cert fails the CrlChecker
*/
@Test(expected = AccessDeniedException.class)
public void testErrorThrownWithFailedCert() throws CertificateException {
Message message = createMockMessageWithCert(getTestCertString());
CrlChecker crlChecker = mock(CrlChecker.class);
when(crlChecker.passesCrlCheck(anyObject())).thenReturn(false);
CrlInterceptor crlInterceptor = new CrlInterceptor(crlChecker);
crlInterceptor.handleMessage(message);
verify(crlChecker).passesCrlCheck(getTestCerts());
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class CrlInterceptorTest method testErrorNotThrownWithPassingCert.
/**
* Tests that the interceptor will NOT throw an error if the cert passes the CrlChecker
*/
@Test
public void testErrorNotThrownWithPassingCert() throws CertificateException {
Message message = createMockMessageWithCert(getTestCertString());
CrlChecker crlChecker = mock(CrlChecker.class);
when(crlChecker.passesCrlCheck(anyObject())).thenReturn(true);
CrlInterceptor crlInterceptor = new CrlInterceptor(crlChecker);
crlInterceptor.handleMessage(message);
verify(crlChecker).passesCrlCheck(getTestCerts());
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class GuestInterceptor method internalHandleMessage.
private void internalHandleMessage(SoapMessage message, SOAPMessage soapMessage) throws Fault {
//Check if security header exists; if not, execute GuestInterceptor logic
String actor = (String) getOption(WSHandlerConstants.ACTOR);
if (actor == null) {
actor = (String) message.getContextualProperty(SecurityConstants.ACTOR);
}
Element existingSecurityHeader = null;
try {
LOGGER.debug("Checking for security header.");
existingSecurityHeader = WSSecurityUtil.getSecurityHeader(soapMessage.getSOAPPart(), actor);
} catch (WSSecurityException e1) {
LOGGER.debug("Issue with getting security header", e1);
}
if (existingSecurityHeader != null) {
LOGGER.debug("SOAP message contains security header, no action taken by the GuestInterceptor.");
return;
}
LOGGER.debug("Current request has no security header, continuing with GuestInterceptor");
AssertionInfoMap assertionInfoMap = message.get(AssertionInfoMap.class);
boolean hasAddressingAssertion = assertionInfoMap.entrySet().stream().flatMap(p -> p.getValue().stream()).filter(info -> MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(info.getAssertion().getName())).findFirst().isPresent();
if (hasAddressingAssertion) {
createAddressing(message, soapMessage);
}
LOGGER.debug("Creating guest security token.");
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
SecurityToken securityToken = createSecurityToken(request.getRemoteAddr());
message.put(SecurityConstants.TOKEN, securityToken);
if (!MessageUtils.isRequestor(message)) {
try {
message.put(Message.REQUESTOR_ROLE, true);
policyBasedWss4jOutInterceptor.handleMessage(message);
} finally {
message.remove(Message.REQUESTOR_ROLE);
}
} else {
policyBasedWss4jOutInterceptor.handleMessage(message);
}
}
Aggregations