Search in sources :

Example 1 with EsbSecurity

use of org.talend.esb.locator.service.LocatorServiceConstants.EsbSecurity 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

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 Bus (org.apache.cxf.Bus)1 Server (org.apache.cxf.endpoint.Server)1 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)1 PolicyBuilder (org.apache.cxf.ws.policy.PolicyBuilder)1 WSPolicyFeature (org.apache.cxf.ws.policy.WSPolicyFeature)1 Policy (org.apache.neethi.Policy)1 JAASUsernameTokenValidator (org.apache.wss4j.dom.validate.JAASUsernameTokenValidator)1 EsbSecurity (org.talend.esb.locator.service.LocatorServiceConstants.EsbSecurity)1