use of org.apache.cxf.ws.policy.PolicyEngine in project cxf by apache.
the class MinimalMaximalAlternativeSelectorTest method testChooseMaxAlternative.
@Test
public void testChooseMaxAlternative() {
Message m = new MessageImpl();
AlternativeSelector selector = new MaximalAlternativeSelector();
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(1, choice.size());
assertSame(a1, choice.iterator().next());
control.verify();
}
use of org.apache.cxf.ws.policy.PolicyEngine in project cxf by apache.
the class PolicyBeansTest method testParse.
@Test
public void testParse() {
Bus bus = new SpringBusFactory().createBus("org/apache/cxf/ws/policy/spring/beans.xml");
try {
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
assertTrue("Policy engine is not enabled", pe.isEnabled());
assertTrue("Unknown assertions are not ignored", pe.isIgnoreUnknownAssertions());
assertEquals(MaximalAlternativeSelector.class.getName(), pe.getAlternativeSelector().getClass().getName());
PolicyEngineImpl pei = (PolicyEngineImpl) pe;
Collection<PolicyProvider> providers = pei.getPolicyProviders();
assertEquals(4, providers.size());
int n = 0;
for (PolicyProvider pp : providers) {
if (pp instanceof ExternalAttachmentProvider) {
n++;
}
}
assertEquals("Unexpected number of external providers", 2, n);
} finally {
bus.shutdown(true);
}
}
use of org.apache.cxf.ws.policy.PolicyEngine in project cxf by apache.
the class AbstractPolicyProvider method setBus.
public final void setBus(Bus b) {
bus = b;
if (null != bus) {
setBuilder(bus.getExtension(PolicyBuilder.class));
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (pe != null) {
setRegistry(pe.getRegistry());
((PolicyEngineImpl) pe).addPolicyProvider(this);
}
}
}
use of org.apache.cxf.ws.policy.PolicyEngine in project cxf by apache.
the class AbstractSTSClient method findOperation.
protected BindingOperationInfo findOperation(String suffix) {
BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
for (BindingOperationInfo boi : bi.getOperations()) {
SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
String soapAction = soi != null ? soi.getAction() : null;
Object o = boi.getOperationInfo().getInput().getExtensionAttribute(new QName("http://www.w3.org/2007/05/addressing/metadata", "Action"));
if (o instanceof QName) {
o = ((QName) o).getLocalPart();
}
String wsamAction = o == null ? null : o.toString();
if ((soapAction != null && soapAction.endsWith(suffix)) || (wsamAction != null && wsamAction.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 (suffix.endsWith(boi.getName().getLocalPart())) {
return boi;
}
}
// Still didn't find anything useful
for (BindingOperationInfo boi : bi.getOperations()) {
if (boi.getInput().getMessageInfo().getMessagePartsNumber() > 0) {
MessagePartInfo mpi = boi.getInput().getMessageInfo().getFirstMessagePart();
if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
return boi;
}
}
}
return null;
}
use of org.apache.cxf.ws.policy.PolicyEngine in project cxf by apache.
the class RMEndpoint method setPolicies.
void setPolicies(Message message) {
// use same WS-policies as for application endpoint
PolicyEngine engine = manager.getBus().getExtension(PolicyEngine.class);
if (null == engine || !engine.isEnabled()) {
return;
}
for (Endpoint endpoint : endpoints.values()) {
EndpointInfo ei = endpoint.getEndpointInfo();
EndpointPolicy epi = null == conduit ? engine.getServerEndpointPolicy(applicationEndpoint.getEndpointInfo(), null, message) : engine.getClientEndpointPolicy(applicationEndpoint.getEndpointInfo(), conduit, message);
if (conduit != null) {
engine.setClientEndpointPolicy(ei, epi);
} else {
engine.setServerEndpointPolicy(ei, epi);
}
EffectivePolicyImpl effectiveOutbound = new EffectivePolicyImpl();
effectiveOutbound.initialise(epi, engine, false, false, message);
EffectivePolicyImpl effectiveInbound = new EffectivePolicyImpl();
effectiveInbound.initialise(epi, engine, true, false, message);
BindingInfo bi = ei.getBinding();
Collection<BindingOperationInfo> bois = bi.getOperations();
for (BindingOperationInfo boi : bois) {
engine.setEffectiveServerRequestPolicy(ei, boi, effectiveInbound);
engine.setEffectiveServerResponsePolicy(ei, boi, effectiveOutbound);
engine.setEffectiveClientRequestPolicy(ei, boi, effectiveOutbound);
engine.setEffectiveClientResponsePolicy(ei, boi, effectiveInbound);
}
}
// TODO: FaultPolicy (SequenceFault)
}
Aggregations