Search in sources :

Example 21 with ServerRegistry

use of org.apache.cxf.endpoint.ServerRegistry 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 22 with ServerRegistry

use of org.apache.cxf.endpoint.ServerRegistry in project tesb-rt-se by Talend.

the class SAMServiceSecurityProvider method init.

@PostConstruct
public void init() {
    final EsbSecurityConstants esbSecurity = EsbSecurityConstants.fromString(authenticationType);
    if (EsbSecurityConstants.NO == esbSecurity) {
        return;
    }
    Bus bus = serviceEndpoint.getBus();
    List<Policy> policies = new ArrayList<Policy>();
    WSPolicyFeature policyFeature = new WSPolicyFeature();
    policyFeature.setPolicies(policies);
    Map<String, Object> properties = serviceEndpoint.getProperties();
    if (null == properties) {
        properties = new HashMap<String, Object>();
    }
    if (EsbSecurityConstants.BASIC == esbSecurity) {
        JAASLoginInterceptor interceptor = new JAASLoginInterceptor();
        interceptor.setContextName("karaf");
        serviceEndpoint.getInInterceptors().add(interceptor);
    } else if (EsbSecurityConstants.USERNAMETOKEN == esbSecurity) {
        policies.add(loadPolicy(policyUsernameToken, bus));
        JAASUsernameTokenValidator jaasUTValidator = new JAASUsernameTokenValidator();
        jaasUTValidator.setContextName("karaf");
        properties.put(SecurityConstants.USERNAME_TOKEN_VALIDATOR, jaasUTValidator);
        serviceEndpoint.setProperties(properties);
    } else if (EsbSecurityConstants.SAML == esbSecurity) {
        policies.add(loadPolicy(policySaml, bus));
        properties.put(SecurityConstants.SIGNATURE_PROPERTIES, getSignatureProperties());
        properties.put(SecurityConstants.SIGNATURE_USERNAME, getSignatureUsername());
        properties.put(ENDPOINT_SIGNATURE_PASSWORD, getSignaturePassword());
        properties.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(getSignatureUsername(), getSignaturePassword()));
        serviceEndpoint.setProperties(properties);
    }
    serviceEndpoint.getFeatures().add(policyFeature);
    ServerRegistry registry = bus.getExtension(ServerRegistry.class);
    List<Server> servers = registry.getServers();
    for (Server server : servers) {
        if (server.getEndpoint().getService() == serviceEndpoint.getService()) {
            policyFeature.initialize(server, bus);
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) WSPolicyFeature(org.apache.cxf.ws.policy.WSPolicyFeature) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) ArrayList(java.util.ArrayList) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) JAASUsernameTokenValidator(org.apache.wss4j.dom.validate.JAASUsernameTokenValidator) PostConstruct(javax.annotation.PostConstruct)

Example 23 with ServerRegistry

use of org.apache.cxf.endpoint.ServerRegistry in project tesb-rt-se by Talend.

the class SamEnablingInterceptorProvider method process.

static void process(Message message) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (aim != null) {
        Collection<AssertionInfo> ais = aim.get(SamEnablingPolicyBuilder.SAM_ENABLE);
        if (ais != null) {
            for (AssertionInfo ai : ais) {
                if (ai.getAssertion() instanceof SamEnablingPolicy) {
                    SamEnablingPolicy vPolicy = (SamEnablingPolicy) ai.getAssertion();
                    AppliesToType appliesToType = vPolicy.getAppliesToType();
                    // Service service = ServiceModelUtil.getService(message
                    // .getExchange());
                    Exchange ex = message.getExchange();
                    Bus b = ex.getBus();
                    if (b.getFeatures().contains(EventFeature.class)) {
                        ai.setAsserted(true);
                        return;
                    }
                    Endpoint ep = ex.getEndpoint();
                    Bundle bundle = FrameworkUtil.getBundle(SamEnablingInterceptorProvider.class);
                    EventFeature eventFeature = null;
                    if (bundle != null) {
                        // OSGi
                        BundleContext context = FrameworkUtil.getBundle(SamEnablingInterceptorProvider.class).getBundleContext();
                        ServiceReference sref = context.getServiceReference(EventFeature.class.getName());
                        eventFeature = (EventFeature) context.getService(sref);
                    } else {
                        // non-OSGi
                        if (springContext == null) {
                            throw springContextException;
                        }
                        eventFeature = (EventFeature) springContext.getBean("eventFeature");
                    }
                    if (MessageUtils.isRequestor(message)) {
                        if (MessageUtils.isOutbound(message)) {
                            // REQ_OUT
                            if ((appliesToType == AppliesToType.consumer || appliesToType == AppliesToType.always)) {
                                Client cli = ex.get(Client.class);
                                if (!cli.getOutInterceptors().contains(WireTapOut.class)) {
                                    eventFeature.initialize(cli, b);
                                    List<Interceptor<? extends Message>> outInterceptors = cli.getOutInterceptors();
                                    message.getInterceptorChain().add(outInterceptors);
                                    outInterceptors.getClass();
                                }
                            }
                        } else {
                            // RESP_IN
                            if ((appliesToType == AppliesToType.consumer || appliesToType == AppliesToType.always)) {
                                Client cli = ex.get(Client.class);
                                eventFeature.initialize(cli, b);
                            }
                        }
                    } else {
                        ServerRegistry registry = b.getExtension(ServerRegistry.class);
                        List<Server> servers = registry.getServers();
                        if (MessageUtils.isOutbound(message)) {
                            // RESP_OUT
                            if ((appliesToType == AppliesToType.provider || appliesToType == AppliesToType.always)) {
                                for (Server sr : servers) {
                                    EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
                                    if (null != ei && ei.getAddress().equals(ep.getEndpointInfo().getAddress())) {
                                        eventFeature.initialize(sr, b);
                                    }
                                }
                            }
                        } else {
                            // REQ_IN
                            if ((appliesToType == AppliesToType.provider || appliesToType == AppliesToType.always)) {
                                for (Server sr : servers) {
                                    EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
                                    if (null != ei && ei.getAddress().equals(ep.getEndpointInfo().getAddress()) && (!sr.getEndpoint().getInInterceptors().contains(WireTapIn.class))) {
                                        eventFeature.initialize(sr, b);
                                        List<Interceptor<? extends Message>> inInterceptors = sr.getEndpoint().getInInterceptors();
                                        message.getInterceptorChain().add(inInterceptors);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) Server(org.apache.cxf.endpoint.Server) Bundle(org.osgi.framework.Bundle) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) WireTapIn(org.talend.esb.sam.agent.wiretap.WireTapIn) EventFeature(org.talend.esb.sam.agent.feature.EventFeature) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) ServiceReference(org.osgi.framework.ServiceReference) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) WireTapOut(org.talend.esb.sam.agent.wiretap.WireTapOut) AppliesToType(org.talend.esb.policy.samenabling.SamEnablingPolicy.AppliesToType) Client(org.apache.cxf.endpoint.Client) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) BundleContext(org.osgi.framework.BundleContext)

Aggregations

ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)23 Server (org.apache.cxf.endpoint.Server)18 Bus (org.apache.cxf.Bus)13 ArrayList (java.util.ArrayList)5 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)5 HashMap (java.util.HashMap)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 Test (org.junit.Test)4 Fault (org.apache.cxf.interceptor.Fault)3 List (java.util.List)2 PostConstruct (javax.annotation.PostConstruct)2 JMException (javax.management.JMException)2 QName (javax.xml.namespace.QName)2 ManagedEndpoint (org.apache.cxf.endpoint.ManagedEndpoint)2 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)2 JAASAuthenticationFilter (org.apache.cxf.jaxrs.security.JAASAuthenticationFilter)2 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)2 InstrumentationManagerImpl (org.apache.cxf.management.jmx.InstrumentationManagerImpl)2 Exchange (org.apache.cxf.message.Exchange)2 SamlHeaderInHandler (org.apache.cxf.rs.security.saml.SamlHeaderInHandler)2