Search in sources :

Example 1 with SamlHeaderInHandler

use of org.apache.cxf.rs.security.saml.SamlHeaderInHandler in project tesb-rt-se by Talend.

the class AuxiliaryStorageRestServiceSecurityProvider method init.

public void init() {
    if (Authentication.NO == auxiliaryStorageAuthentication) {
        return;
    }
    // TODO: !!! find more correct way to enable/switch(?) security on provider endpoint
    Bus serverBus = server.getBus();
    ServerRegistry registry = serverBus.getExtension(ServerRegistry.class);
    List<Server> servers = registry.getServers();
    for (Server sr : servers) {
        EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
        if (null != ei && ei.getAddress().endsWith(server.getAddress())) {
            registry.unregister(sr);
            sr.destroy();
        }
    }
    @SuppressWarnings("unchecked") List<Object> providers = (List<Object>) server.getProviders();
    if (Authentication.BASIC == auxiliaryStorageAuthentication) {
        JAASAuthenticationFilter jaasAuthFilter = new JAASAuthenticationFilter();
        jaasAuthFilter.setContextName("karaf");
        providers.add(jaasAuthFilter);
        server.setProviders(providers);
    }
    if (Authentication.SAML == auxiliaryStorageAuthentication) {
        Map<String, Object> endpointProps = new HashMap<String, Object>();
        endpointProps.put(SecurityConstants.SIGNATURE_PROPERTIES, signatureProperties);
        endpointProps.put(SecurityConstants.SIGNATURE_USERNAME, signatureUsername);
        endpointProps.put(ENDPOINT_SIGNATURE_PASSWORD, signaturePassword);
        endpointProps.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(signatureUsername, signaturePassword));
        Map<String, Object> properties = server.getProperties();
        if (null == properties) {
            properties = new HashMap<String, Object>();
        }
        properties.putAll(endpointProps);
        server.setProperties(properties);
        SamlHeaderInHandler samlHandler = new SamlHeaderInHandler();
        providers.add(samlHandler);
        server.setProviders(providers);
    }
    server.create();
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SamlHeaderInHandler(org.apache.cxf.rs.security.saml.SamlHeaderInHandler) JAASAuthenticationFilter(org.apache.cxf.jaxrs.security.JAASAuthenticationFilter) List(java.util.List)

Example 2 with SamlHeaderInHandler

use of org.apache.cxf.rs.security.saml.SamlHeaderInHandler in project tesb-rt-se by Talend.

the class SAMServiceSecurityProvider method init.

public void init() {
    final EsbSecurityConstants esbSecurity = EsbSecurityConstants.fromString(authenticationType);
    if (EsbSecurityConstants.NO == esbSecurity) {
        return;
    }
    Bus serverBus = server.getBus();
    ServerRegistry registry = serverBus.getExtension(ServerRegistry.class);
    List<Server> servers = registry.getServers();
    for (Server sr : servers) {
        EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
        if (null != ei && ei.getAddress().endsWith(server.getAddress())) {
            registry.unregister(sr);
            sr.destroy();
        }
    }
    @SuppressWarnings("unchecked") List<Object> providers = (List<Object>) server.getProviders();
    Map<String, Object> endpointProperties = new HashMap<String, Object>();
    if (EsbSecurityConstants.BASIC == esbSecurity) {
        JAASAuthenticationFilter authenticationFilter = new JAASAuthenticationFilter();
        authenticationFilter.setContextName("karaf");
        providers.add(authenticationFilter);
        server.setProviders(providers);
    } else if (EsbSecurityConstants.SAML == esbSecurity) {
        endpointProperties.put(SecurityConstants.SIGNATURE_PROPERTIES, getSignatureProperties());
        endpointProperties.put(SecurityConstants.SIGNATURE_USERNAME, getSignatureUsername());
        endpointProperties.put(ENDPOINT_SIGNATURE_PASSWORD, getSignaturePassword());
        endpointProperties.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(getSignatureUsername(), getSignaturePassword()));
        Map<String, Object> properties = server.getProperties();
        if (null == properties)
            properties = new HashMap<String, Object>();
        properties.putAll(endpointProperties);
        server.setProperties(properties);
        SamlHeaderInHandler samlHandler = new SamlHeaderInHandler();
        providers.add(samlHandler);
        server.setProviders(providers);
    }
    server.create();
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SamlHeaderInHandler(org.apache.cxf.rs.security.saml.SamlHeaderInHandler) JAASAuthenticationFilter(org.apache.cxf.jaxrs.security.JAASAuthenticationFilter) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with SamlHeaderInHandler

use of org.apache.cxf.rs.security.saml.SamlHeaderInHandler in project tesb-rt-se by Talend.

the class SAMLRESTUtils method configureServer.

public static void configureServer(final AbstractJAXRSFactoryBean serverFactory, final Map<String, Object> securityProps) {
    Map<String, Object> props = serverFactory.getProperties(true);
    String username = (String) securityProps.get(SecurityConstants.SIGNATURE_USERNAME);
    if (username == null) {
        username = (String) securityProps.get("ws-" + SecurityConstants.SIGNATURE_USERNAME);
    }
    props.put(SecurityConstants.SIGNATURE_USERNAME, username);
    props.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(username, (String) securityProps.get(SIGNATURE_PASSWORD)));
    Object sigProps = securityProps.get(SecurityConstants.SIGNATURE_PROPERTIES);
    if (sigProps == null) {
        sigProps = securityProps.get("ws-" + SecurityConstants.SIGNATURE_PROPERTIES);
    }
    props.put(SecurityConstants.SIGNATURE_PROPERTIES, sigProps);
    serverFactory.setProvider(new SamlHeaderInHandler());
}
Also used : SamlHeaderInHandler(org.apache.cxf.rs.security.saml.SamlHeaderInHandler)

Aggregations

SamlHeaderInHandler (org.apache.cxf.rs.security.saml.SamlHeaderInHandler)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Bus (org.apache.cxf.Bus)2 Server (org.apache.cxf.endpoint.Server)2 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)2 JAASAuthenticationFilter (org.apache.cxf.jaxrs.security.JAASAuthenticationFilter)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 Map (java.util.Map)1