use of org.apache.cxf.ws.policy.PolicyEngine 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.PolicyEngine in project cxf by apache.
the class FirstAlternativeSelectorTest method testChooseAlternative.
@Test
public void testChooseAlternative() {
AlternativeSelector selector = new FirstAlternativeSelector();
PolicyEngine engine = control.createMock(PolicyEngine.class);
Assertor assertor = control.createMock(Assertor.class);
Policy policy = new Policy();
ExactlyOne ea = new ExactlyOne();
All all = new All();
PolicyAssertion a1 = new TestAssertion();
all.addAssertion(a1);
ea.addPolicyComponent(all);
Collection<PolicyAssertion> firstAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
policy.addPolicyComponent(ea);
Message m = new MessageImpl();
EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false);
control.replay();
assertNull(selector.selectAlternative(policy, engine, assertor, null, m));
control.verify();
control.reset();
EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(true);
control.replay();
Collection<Assertion> chosen = selector.selectAlternative(policy, engine, assertor, null, m);
assertSame(1, chosen.size());
assertSame(chosen.size(), firstAlternative.size());
assertSame(chosen.iterator().next(), firstAlternative.iterator().next());
control.verify();
control.reset();
All other = new All();
other.addAssertion(a1);
ea.addPolicyComponent(other);
Collection<PolicyAssertion> secondAlternative = CastUtils.cast(other.getPolicyComponents(), PolicyAssertion.class);
EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false);
EasyMock.expect(engine.supportsAlternative(secondAlternative, assertor, m)).andReturn(true);
control.replay();
chosen = selector.selectAlternative(policy, engine, assertor, null, m);
assertSame(1, chosen.size());
assertSame(chosen.size(), secondAlternative.size());
assertSame(chosen.iterator().next(), secondAlternative.iterator().next());
control.verify();
}
use of org.apache.cxf.ws.policy.PolicyEngine in project cxf by apache.
the class MinimalMaximalAlternativeSelectorTest method testChooseMinAlternative.
@Test
public void testChooseMinAlternative() {
Message m = new MessageImpl();
AlternativeSelector selector = new MinimalAlternativeSelector();
PolicyEngine engine = control.createMock(PolicyEngine.class);
Assertor assertor = control.createMock(Assertor.class);
Policy policy = new Policy();
ExactlyOne ea = new ExactlyOne();
All all = new All();
PolicyAssertion a1 = new TestAssertion();
all.addAssertion(a1);
ea.addPolicyComponent(all);
Collection<PolicyAssertion> maxAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
all = new All();
ea.addPolicyComponent(all);
Collection<PolicyAssertion> minAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
policy.addPolicyComponent(ea);
EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor, m)).andReturn(true);
EasyMock.expect(engine.supportsAlternative(minAlternative, assertor, m)).andReturn(true);
control.replay();
Collection<Assertion> choice = selector.selectAlternative(policy, engine, assertor, null, m);
assertEquals(0, choice.size());
control.verify();
}
use of org.apache.cxf.ws.policy.PolicyEngine in project cxf by apache.
the class SimpleBatchSTSClient method findOperation.
protected BindingOperationInfo findOperation(String suffix) {
BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
for (BindingOperationInfo boi : bi.getOperations()) {
SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
if (soi != null && soi.getAction() != null && soi.getAction().endsWith(suffix)) {
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
Conduit conduit = client.getConduit();
EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
setPolicyInternal(effectivePolicy.getPolicy());
return boi;
}
}
// we can at least find it by name and then set the action and such manually later.
for (BindingOperationInfo boi : bi.getOperations()) {
if (boi.getInput().getMessageInfo().getMessageParts().size() > 0) {
MessagePartInfo mpi = boi.getInput().getMessageInfo().getMessagePart(0);
if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
return boi;
}
}
}
return null;
}
Aggregations