use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class PolicyUtilsTest method testAssertServerPolicy.
void testAssertServerPolicy(boolean outbound) {
Message message = control.createMock(Message.class);
HTTPServerPolicy ep = new HTTPServerPolicy();
HTTPServerPolicy mp = new HTTPServerPolicy();
HTTPServerPolicy cmp = new HTTPServerPolicy();
cmp.setReceiveTimeout(60000L);
HTTPServerPolicy icmp = new HTTPServerPolicy();
icmp.setSuppressClientSendErrors(true);
AssertionInfo eai = getServerPolicyAssertionInfo(ep);
AssertionInfo mai = getServerPolicyAssertionInfo(mp);
AssertionInfo cmai = getServerPolicyAssertionInfo(cmp);
AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
Collection<AssertionInfo> ais = new ArrayList<>();
ais.add(eai);
ais.add(mai);
ais.add(cmai);
ais.add(icmai);
AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
if (!outbound) {
EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
}
control.replay();
new PolicyDataEngineImpl(null).assertMessage(message, ep, new ServerPolicyCalculator());
assertTrue(eai.isAsserted());
assertTrue(mai.isAsserted());
assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
control.verify();
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class MTOMPolicyInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
// extract Assertion information
if (aim != null) {
Collection<AssertionInfo> ais = aim.get(MetadataConstants.MTOM_ASSERTION_QNAME);
for (AssertionInfo ai : ais) {
if (MessageUtils.isRequestor(message)) {
// just turn on MTOM
message.put(Message.MTOM_ENABLED, Boolean.TRUE);
ai.setAsserted(true);
} else {
// set mtom enabled and assert the policy if we find an mtom request
String contentType = (String) message.getExchange().getInMessage().get(Message.CONTENT_TYPE);
if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) {
ai.setAsserted(true);
message.put(Message.MTOM_ENABLED, Boolean.TRUE);
}
}
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class PolicyUtilsTest method testGetRMConfiguration.
@Test
public void testGetRMConfiguration() {
RMConfiguration cfg = new RMConfiguration();
cfg.setBaseRetransmissionInterval(Long.valueOf(3000));
cfg.setExponentialBackoff(true);
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
control.replay();
assertSame(cfg, RMPolicyUtilities.getRMConfiguration(cfg, message));
control.verify();
control.reset();
AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
Collection<AssertionInfo> ais = new ArrayList<>();
EasyMock.expect(aim.get(RM10Constants.RMASSERTION_QNAME)).andReturn(ais);
control.replay();
assertSame(cfg, RMPolicyUtilities.getRMConfiguration(cfg, message));
control.verify();
control.reset();
RMAssertion b = new RMAssertion();
BaseRetransmissionInterval bbri = new RMAssertion.BaseRetransmissionInterval();
bbri.setMilliseconds(Long.valueOf(2000));
b.setBaseRetransmissionInterval(bbri);
JaxbAssertion<RMAssertion> assertion = new JaxbAssertion<>();
assertion.setName(RM10Constants.RMASSERTION_QNAME);
assertion.setData(b);
AssertionInfo ai = new AssertionInfo(assertion);
ais.add(ai);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
EasyMock.expect(aim.get(RM10Constants.RMASSERTION_QNAME)).andReturn(ais);
control.replay();
RMConfiguration cfg1 = RMPolicyUtilities.getRMConfiguration(cfg, message);
assertNull(cfg1.getAcknowledgementInterval());
assertNull(cfg1.getInactivityTimeout());
assertEquals(2000L, cfg1.getBaseRetransmissionInterval().longValue());
assertTrue(cfg1.isExponentialBackoff());
control.verify();
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class NegotiationUtils method recalcEffectivePolicy.
static void recalcEffectivePolicy(SoapMessage message, String namespace, Policy policy, Invoker invoker, boolean secConv) {
Exchange ex = message.getExchange();
Bus bus = ex.getBus();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
Destination destination = ex.getDestination();
try {
Endpoint endpoint = message.getExchange().getEndpoint();
TokenStore store = TokenStoreUtils.getTokenStore(message);
if (secConv) {
endpoint = STSUtils.createSCEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy);
} else {
endpoint = STSUtils.createSTSEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy, null);
}
endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
message.getExchange().put(TokenStore.class.getName(), store);
EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination, message);
List<Interceptor<? extends Message>> interceptors = ep.getInterceptors(message);
message.getInterceptorChain().add(interceptors);
Collection<Assertion> assertions = ep.getVocabulary(message);
if (null != assertions) {
message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
endpoint.getService().setInvoker(invoker);
ex.put(Endpoint.class, endpoint);
ex.put(Service.class, endpoint.getService());
ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
ex.remove(BindingOperationInfo.class);
message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
} catch (Exception exc) {
throw new Fault(exc);
}
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class SecurityVerificationOutInterceptor method handleMessage.
/**
* Checks if some security assertions are specified without binding assertion and cannot be fulfilled.
* Throw PolicyException in this case
*
* @param message
* @throws PolicyException if assertions are specified without binding
*/
public void handleMessage(SoapMessage message) throws Fault {
if (MessageUtils.isRequestor(message)) {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (aim != null && PolicyUtils.getSecurityBinding(aim) == null) {
AssertionInfo assertion = getSecuredPart(aim);
if (assertion != null) {
String error = String.format("%s assertion cannot be fulfilled without binding. " + "At least one binding assertion (%s, %s, %s) must be specified in policy.", assertion.getAssertion().getName(), SP12Constants.TRANSPORT_BINDING.getLocalPart(), SP12Constants.ASYMMETRIC_BINDING.getLocalPart(), SP12Constants.SYMMETRIC_BINDING.getLocalPart());
assertion.setNotAsserted(error);
LOG.severe(error);
throw new PolicyException(assertion);
}
}
}
}
Aggregations