Search in sources :

Example 1 with PolicyBuilder

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);
    }
}
Also used : Fault(org.apache.cxf.interceptor.Fault) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder)

Example 2 with PolicyBuilder

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();
}
Also used : Policy(org.apache.neethi.Policy) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) URL(java.net.URL)

Example 3 with PolicyBuilder

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);
    }
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) WSPolicyFeature(org.apache.cxf.ws.policy.WSPolicyFeature) ArrayList(java.util.ArrayList) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) JAASUsernameTokenValidator(org.apache.wss4j.dom.validate.JAASUsernameTokenValidator) EsbSecurity(org.talend.esb.locator.service.LocatorServiceConstants.EsbSecurity) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) PostConstruct(javax.annotation.PostConstruct)

Example 4 with PolicyBuilder

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();
}
Also used : Policy(org.apache.neethi.Policy) QName(javax.xml.namespace.QName) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 5 with PolicyBuilder

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();
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) UrlResource(org.springframework.core.io.UrlResource) Element(org.w3c.dom.Element) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) URL(java.net.URL) Test(org.junit.Test)

Aggregations

PolicyBuilder (org.apache.cxf.ws.policy.PolicyBuilder)6 Policy (org.apache.neethi.Policy)5 Element (org.w3c.dom.Element)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)2 Bus (org.apache.cxf.Bus)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 QName (javax.xml.namespace.QName)1 Server (org.apache.cxf.endpoint.Server)1 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)1 Fault (org.apache.cxf.interceptor.Fault)1 DescriptionInfo (org.apache.cxf.service.model.DescriptionInfo)1 EffectivePolicy (org.apache.cxf.ws.policy.EffectivePolicy)1 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)1 WSPolicyFeature (org.apache.cxf.ws.policy.WSPolicyFeature)1 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)1 RemoteReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver)1