Search in sources :

Example 1 with JAASLoginInterceptor

use of org.apache.cxf.interceptor.security.JAASLoginInterceptor in project wildfly-camel by wildfly-extras.

the class CXFWSJAASAuthenticationIntegrationTest method configureCamelContext.

private CamelContext configureCamelContext(String password) throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    CxfComponent component = new CxfComponent(camelctx);
    CxfEndpoint consumerEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting", component);
    consumerEndpoint.setServiceClass(Endpoint.class);
    List<Interceptor<? extends Message>> inInterceptors = consumerEndpoint.getInInterceptors();
    JAASLoginInterceptor interceptor = new JAASLoginInterceptor();
    interceptor.setContextName("other");
    inInterceptors.add(interceptor);
    CxfEndpoint producerEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting", component);
    producerEndpoint.setServiceClass(Endpoint.class);
    producerEndpoint.setUsername("user1");
    producerEndpoint.setPassword(password);
    Map<String, Object> properties = producerEndpoint.getProperties();
    if (properties == null) {
        producerEndpoint.setProperties(new HashMap<>());
    }
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to(producerEndpoint);
            from(consumerEndpoint).process(exchange -> {
                Object[] args = exchange.getIn().getBody(Object[].class);
                exchange.getOut().setBody("Hello " + args[0]);
            });
        }
    });
    return camelctx;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Interceptor(org.apache.cxf.interceptor.Interceptor) Arquillian(org.jboss.arquillian.junit.Arquillian) Message(org.apache.cxf.message.Message) RunWith(org.junit.runner.RunWith) CamelExecutionException(org.apache.camel.CamelExecutionException) HashMap(java.util.HashMap) Test(org.junit.Test) Endpoint(org.wildfly.camel.test.common.types.Endpoint) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) List(java.util.List) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) CamelAware(org.wildfly.extension.camel.CamelAware) RouteBuilder(org.apache.camel.builder.RouteBuilder) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Map(java.util.Map) ProducerTemplate(org.apache.camel.ProducerTemplate) CxfComponent(org.apache.camel.component.cxf.CxfComponent) Assert(org.junit.Assert) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Message(org.apache.cxf.message.Message) RouteBuilder(org.apache.camel.builder.RouteBuilder) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) CxfComponent(org.apache.camel.component.cxf.CxfComponent) Interceptor(org.apache.cxf.interceptor.Interceptor) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor)

Example 2 with JAASLoginInterceptor

use of org.apache.cxf.interceptor.security.JAASLoginInterceptor in project cxf by apache.

the class JAASServer method createTestJaasLoginInterceptor.

private JAASLoginInterceptor createTestJaasLoginInterceptor() {
    JAASLoginInterceptor jaasInt = new JAASLoginInterceptor();
    jaasInt.setReportFault(true);
    Configuration config = new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            Map<String, String> options = new HashMap<>();
            AppConfigurationEntry configEntry = new AppConfigurationEntry(TestUserPasswordLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, options);
            return Collections.singleton(configEntry).toArray(new AppConfigurationEntry[] {});
        }
    };
    jaasInt.setLoginConfig(config);
    return jaasInt;
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) HashMap(java.util.HashMap)

Example 3 with JAASLoginInterceptor

use of org.apache.cxf.interceptor.security.JAASLoginInterceptor 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)

Aggregations

JAASLoginInterceptor (org.apache.cxf.interceptor.security.JAASLoginInterceptor)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)1 Configuration (javax.security.auth.login.Configuration)1 CamelContext (org.apache.camel.CamelContext)1 CamelExecutionException (org.apache.camel.CamelExecutionException)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 CxfComponent (org.apache.camel.component.cxf.CxfComponent)1 CxfEndpoint (org.apache.camel.component.cxf.CxfEndpoint)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 Bus (org.apache.cxf.Bus)1 Server (org.apache.cxf.endpoint.Server)1 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 Message (org.apache.cxf.message.Message)1