Search in sources :

Example 6 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)

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