use of org.apache.cxf.ws.policy.PolicyBuilder in project ddf by codice.
the class AbstractOverrideInterceptor method handleMessage.
/**
* Adds the policy retrieved from the configured policy loader to this message as the override
* policy.
*
* @param message
*/
@Override
public void handleMessage(Message message) {
if (policy == null) {
PolicyBuilder builder = message.getExchange().getBus().getExtension(PolicyBuilder.class);
try {
policy = builder.getPolicy(loader.getPolicy().getDocumentElement());
LOGGER.trace("Read in policy, adding to policy override of message.");
message.put(PolicyConstants.POLICY_OVERRIDE, policy);
} catch (Exception e) {
throw new Fault(e);
}
} else {
message.put(PolicyConstants.POLICY_OVERRIDE, policy);
}
}
use of org.apache.cxf.ws.policy.PolicyBuilder in project cxf by apache.
the class ReferenceResolverTest method doTestRemoteResolver.
private void doTestRemoteResolver(String policyNs) {
URL url = ReferenceResolverTest.class.getResource("referring.wsdl");
String baseURI = url.toString();
PolicyBuilder builder = control.createMock(PolicyBuilder.class);
RemoteReferenceResolver resolver = new RemoteReferenceResolver(baseURI, builder);
assertNull(resolver.resolveReference("referred.wsdl#PolicyB"));
Policy p = control.createMock(Policy.class);
EasyMock.expect(builder.getPolicy(EasyMock.isA(Element.class))).andReturn(p);
control.replay();
assertSame(p, resolver.resolveReference("referred.wsdl#PolicyA"));
control.verify();
control.reset();
}
use of org.apache.cxf.ws.policy.PolicyBuilder in project tesb-rt-se by Talend.
the class PolicyProviderImpl method init.
@PostConstruct
public void init() {
final EsbSecurity esbSecurity = EsbSecurity.fromString((String) serviceAutentication);
if (EsbSecurity.NO == esbSecurity)
return;
Bus currentBus = BusFactory.getThreadDefaultBus();
policyBuilder = currentBus.getExtension(PolicyBuilder.class);
List<Policy> policies = new ArrayList<Policy>();
if (EsbSecurity.TOKEN == esbSecurity) {
policies.add(getTokenPolicy());
} else if (EsbSecurity.SAML == esbSecurity) {
policies.add(getSamlPolicy());
}
Map<String, Object> endpointProps = new HashMap<String, Object>();
if (EsbSecurity.TOKEN == esbSecurity) {
JAASUsernameTokenValidator jaasUTValidator = new JAASUsernameTokenValidator();
jaasUTValidator.setContextName("karaf");
endpointProps.put(SecurityConstants.USERNAME_TOKEN_VALIDATOR, jaasUTValidator);
}
if (EsbSecurity.SAML == esbSecurity) {
endpointProps.put(SecurityConstants.SIGNATURE_PROPERTIES, getSignatureProperties());
endpointProps.put(SecurityConstants.SIGNATURE_USERNAME, getSignatureUsername());
endpointProps.put(ENDPOINT_SIGNATURE_PASSWORD, getSignaturePassword());
endpointProps.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(getSignatureUsername(), getSignaturePassword()));
}
locatorEndpoint.setProperties(endpointProps);
WSPolicyFeature policyFeature = new WSPolicyFeature();
policyFeature.setPolicies(policies);
locatorEndpoint.getFeatures().add(policyFeature);
ServerRegistry registry = currentBus.getExtension(ServerRegistry.class);
List<Server> servers = registry.getServers();
for (Server sr : servers) {
if (sr.getEndpoint().getService() == locatorEndpoint.getService())
policyFeature.initialize(sr, currentBus);
}
}
use of org.apache.cxf.ws.policy.PolicyBuilder in project cxf by apache.
the class ReferenceResolverTest method testLocalServiceModelReferenceResolver.
@Test
public void testLocalServiceModelReferenceResolver() {
DescriptionInfo di = control.createMock(DescriptionInfo.class);
PolicyBuilder builder = control.createMock(PolicyBuilder.class);
LocalServiceModelReferenceResolver resolver = new LocalServiceModelReferenceResolver(di, builder);
List<UnknownExtensibilityElement> extensions = new ArrayList<>();
EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions);
control.replay();
assertNull(resolver.resolveReference("A"));
control.verify();
control.reset();
UnknownExtensibilityElement extension = control.createMock(UnknownExtensibilityElement.class);
extensions.add(extension);
EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions);
Element e = control.createMock(Element.class);
QName qn = new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY);
EasyMock.expect(extension.getElementType()).andReturn(qn).anyTimes();
EasyMock.expect(extension.getElement()).andReturn(e).times(1);
Document ownerDocument = control.createMock(Document.class);
EasyMock.expect(e.getOwnerDocument()).andReturn(ownerDocument);
EasyMock.expect(e.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_ID_ATTR_NAME)).andReturn("A");
Policy p = control.createMock(Policy.class);
EasyMock.expect(builder.getPolicy(e)).andReturn(p);
control.replay();
assertSame(p, resolver.resolveReference("A"));
control.verify();
}
use of org.apache.cxf.ws.policy.PolicyBuilder in project cxf by apache.
the class ExternalAttachmentProviderTest method testReadDocumentEPRDomainExpression.
@Test
public void testReadDocumentEPRDomainExpression() throws MalformedURLException {
Bus bus = control.createMock(Bus.class);
DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class);
EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr);
DomainExpression de = control.createMock(DomainExpression.class);
EasyMock.expect(debr.build(EasyMock.isA(Element.class))).andReturn(de);
PolicyBuilder pb = control.createMock(PolicyBuilder.class);
EasyMock.expect(bus.getExtension(PolicyBuilder.class)).andReturn(pb).anyTimes();
Policy p = control.createMock(Policy.class);
EasyMock.expect(pb.getPolicy(EasyMock.isA(Element.class))).andReturn(p);
control.replay();
ExternalAttachmentProvider eap = new ExternalAttachmentProvider(bus);
URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments4.xml");
String uri = url.toExternalForm();
eap.setLocation(new UrlResource(uri));
eap.readDocument();
assertEquals(1, eap.getAttachments().size());
PolicyAttachment pa = eap.getAttachments().iterator().next();
assertSame(p, pa.getPolicy());
assertEquals(1, pa.getDomainExpressions().size());
assertSame(de, pa.getDomainExpressions().iterator().next());
control.verify();
}
Aggregations