Search in sources :

Example 1 with Saml2BearerAuthOutInterceptor

use of org.apache.cxf.rs.security.oauth2.auth.saml.Saml2BearerAuthOutInterceptor in project cxf by apache.

the class JAXRSOAuth2Test method createWebClientWithProps.

private WebClient createWebClientWithProps(String address) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(address);
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAXRSOAuth2Test.class.getResource("client.xml");
    Bus springBus = bf.createBus(busFile.toString());
    bean.setBus(springBus);
    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
    SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true);
    samlCallbackHandler.setIssuer("alice");
    String audienceURI = "https://localhost:" + port + "/oauth2-auth/token";
    samlCallbackHandler.setAudience(audienceURI);
    properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, samlCallbackHandler);
    properties.put(SecurityConstants.SIGNATURE_USERNAME, "alice");
    properties.put(SecurityConstants.SIGNATURE_PROPERTIES, CRYPTO_RESOURCE_PROPERTIES);
    bean.setProperties(properties);
    bean.getOutInterceptors().add(new Saml2BearerAuthOutInterceptor());
    WebClient wc = bean.createWebClient();
    wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON);
    return wc;
}
Also used : Bus(org.apache.cxf.Bus) SamlCallbackHandler(org.apache.cxf.systest.jaxrs.security.oauth2.common.SamlCallbackHandler) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) HashMap(java.util.HashMap) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Saml2BearerAuthOutInterceptor(org.apache.cxf.rs.security.oauth2.auth.saml.Saml2BearerAuthOutInterceptor)

Aggregations

URL (java.net.URL)1 HashMap (java.util.HashMap)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 Saml2BearerAuthOutInterceptor (org.apache.cxf.rs.security.oauth2.auth.saml.Saml2BearerAuthOutInterceptor)1 SamlCallbackHandler (org.apache.cxf.systest.jaxrs.security.oauth2.common.SamlCallbackHandler)1