org.apache.cxf.interceptor.LoggingInInterceptor Java Examples

The following examples show how to use org.apache.cxf.interceptor.LoggingInInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoapClient.java    From document-management-software with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Standard service initialization. Concrete implementations can change the
 * client initialization logic
 */
@SuppressWarnings("unchecked")
protected void initClient(Class<T> serviceClass, int gzipThreshold, boolean log) {
	// Needed to get rig of CXF exception
	// "Cannot create a secure XMLInputFactory"
	System.setProperty("org.apache.cxf.stax.allowInsecureParser", "true");

	JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
	if (log) {
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
	}

	if (gzipThreshold >= 0) {
		factory.getInInterceptors().add(new GZIPInInterceptor());
		factory.getOutInterceptors().add(new GZIPOutInterceptor(gzipThreshold));
	}

	factory.setServiceClass(serviceClass);
	factory.setAddress(endpoint);
	client = (T) factory.create();
}
 
Example #2
Source File: SOAPServiceTest.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
    * Tests WSDL generation from a URL.
    *
    * This is similar to another KEW test but it is good to have it as part of the KSB tests.  Note that the
    * {@link Client} modifies the current thread's class loader.
    *
    * @throws Exception for any errors connecting to the client
    */
@Test
public void testWsdlGeneration() throws Exception {
	ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();

       try {
           JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
           Client client = dcf.createClient(new URI(getWsdlUrl()).toString());
           client.getInInterceptors().add(new LoggingInInterceptor());
           client.getOutInterceptors().add(new LoggingOutInterceptor());
           Object[] results = client.invoke("echo", "testing");
           assertNotNull(results);
           assertEquals(1, results.length);
           assertEquals("testing", results[0]);
       } finally {
           Thread.currentThread().setContextClassLoader(originalClassLoader);
       }
}
 
Example #3
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #4
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #5
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #6
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #7
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #8
Source File: LoggingFeature.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void doInitializeProvider(InterceptorProvider provider, Bus bus) {
    if (limit == DEFAULT_LIMIT && inLocation == null
            && outLocation == null && !prettyLogging) {
        provider.getInInterceptors().add(IN);
        provider.getInFaultInterceptors().add(IN);
        provider.getOutInterceptors().add(OUT);
        provider.getOutFaultInterceptors().add(OUT);
    } else {
        LoggingInInterceptor in = new LoggingInInterceptor(limit);
        in.setOutputLocation(inLocation);
        in.setPrettyLogging(prettyLogging);
        in.setShowBinaryContent(showBinary);
        LoggingOutInterceptor out = new LoggingOutInterceptor(limit);
        out.setOutputLocation(outLocation);
        out.setPrettyLogging(prettyLogging);
        out.setShowBinaryContent(showBinary);

        provider.getInInterceptors().add(in);
        provider.getInFaultInterceptors().add(in);
        provider.getOutInterceptors().add(out);
        provider.getOutFaultInterceptors().add(out);
    }
}
 
Example #9
Source File: WebServiceTaskTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
	super.initializeProcessEngine();

	counter = new CounterImpl();
	JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
	svrFactory.setServiceClass(Counter.class);
	svrFactory.setAddress("http://localhost:12345/counter");
	svrFactory.setServiceBean(counter);
	svrFactory.getInInterceptors().add(new LoggingInInterceptor());
	svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
	server = svrFactory.create();
	server.start();
}
 
Example #10
Source File: LeaveWebServiceBusinessTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 不需要总经理审批
 * @throws ParseException
 */
@Test
public void testFalse() throws ParseException {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    factory.setServiceClass(LeaveWebService.class);
    factory.setAddress(LeaveWebserviceUtil.WEBSERVICE_URL);
    LeaveWebService leaveWebService = (LeaveWebService) factory.create();
    boolean audit = leaveWebService.generalManagerAudit("2013-01-01 09:00", "2013-01-04 17:30");
    assertFalse(audit);
}
 
Example #11
Source File: CXFWSInterceptorTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public CountDownInterceptor(CountDownLatch latch) {
    super(Phase.RECEIVE);

    // Verify common interceptors can be added
    getBefore().add(PolicyInInterceptor.class.getName());
    getBefore().add(LoggingInInterceptor.class.getName());
    getBefore().add(AttachmentInInterceptor.class.getName());

    this.latch = latch;
}
 
Example #12
Source File: TrustedIdpFacebookProtocolHandler.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
private String getSubjectName(String apiEndpoint, String accessToken, TrustedIdp trustedIdp) {
    WebClient client = WebClient.create(apiEndpoint,
                              Collections.singletonList(new JsonMapObjectProvider()),
                              "cxf-tls.xml");
    client.path("/me");
    ClientConfiguration config = WebClient.getConfig(client);

    if (LOG.isDebugEnabled()) {
        config.getOutInterceptors().add(new LoggingOutInterceptor());
        config.getInInterceptors().add(new LoggingInInterceptor());
    }

    client.accept("application/json");
    client.query("access_token", accessToken);

    String subjectName = getProperty(trustedIdp, SUBJECT_CLAIM);
    if (subjectName == null || subjectName.isEmpty()) {
        subjectName = "email";
    }
    client.query("fields", subjectName);
    JsonMapObject mapObject = client.get(JsonMapObject.class);

    String parsedSubjectName = (String)mapObject.getProperty(subjectName);
    if (subjectName.contains("email")) {
        parsedSubjectName = parsedSubjectName.replace("\\u0040", "@");
    }
    return parsedSubjectName;
}
 
Example #13
Source File: TrustedIdpFacebookProtocolHandler.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
private ClientAccessToken getAccessTokenUsingCode(String tokenEndpoint, String code, String clientId,
                                                  String clientSecret, String redirectURI) {
    // Here we need to get the AccessToken using the authorization code
    List<Object> providers = new ArrayList<>();
    providers.add(new OAuthJSONProvider());

    WebClient client =
        WebClient.create(tokenEndpoint, providers, "cxf-tls.xml");

    ClientConfiguration config = WebClient.getConfig(client);

    if (LOG.isDebugEnabled()) {
        config.getOutInterceptors().add(new LoggingOutInterceptor());
        config.getInInterceptors().add(new LoggingInInterceptor());
    }

    client.type("application/x-www-form-urlencoded");
    client.accept("application/json");

    Form form = new Form();
    form.param("grant_type", "authorization_code");
    form.param("code", code);
    form.param("client_id", clientId);
    form.param("redirect_uri", redirectURI);
    form.param("client_secret", clientSecret);
    Response response = client.post(form);

    return response.readEntity(ClientAccessToken.class);
}
 
Example #14
Source File: QueryInitServlet.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.apache.cxf.transport.servlet.CXFNonSpringServlet#loadBus(javax.servlet.ServletConfig)
 */
public void loadBus(ServletConfig servletConfig) throws ServletException {
    super.loadBus(servletConfig);
    BusFactory.setDefaultBus(getBus());
    if (LOG.isDebugEnabled()) {
        getBus().getInInterceptors().add(new LoggingInInterceptor());
        getBus().getOutInterceptors().add(new LoggingOutInterceptor());
        getBus().getOutFaultInterceptors().add(new LoggingOutInterceptor());
        getBus().getInFaultInterceptors().add(new LoggingInInterceptor());
    }
    EPCISServicePortType service = setupQueryOperationsModule(servletConfig);

    LOG.debug("Publishing query operations module service at /query");
    Endpoint.publish("/query", service);
}
 
Example #15
Source File: Application.java    From spring-cxf with Apache License 2.0 5 votes vote down vote up
@Bean
// <jaxws:endpoint id="helloWorld" implementor="demo.spring.service.HelloWorldImpl" address="/HelloWorld"/>
public EndpointImpl helloService() {
    Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID);
    Object implementor = new HelloWorldImpl();
    EndpointImpl endpoint = new EndpointImpl(bus, implementor);
    endpoint.publish("/hello");
    endpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor());
    endpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor());
    return endpoint;
}
 
Example #16
Source File: MockWebServiceExtension.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static MockWebServiceContext create() {
    WebServiceMock webServiceMock = new WebServiceMockImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(WebServiceMock.class);
    svrFactory.setAddress(WEBSERVICE_MOCK_ADDRESS);
    svrFactory.setServiceBean(webServiceMock);
    svrFactory.getInInterceptors().add(new LoggingInInterceptor());
    svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    Server server = svrFactory.create();
    return new MockWebServiceContext(webServiceMock, server);
}
 
Example #17
Source File: AbstractWebServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
    super.initializeProcessEngine();

    webServiceMock = new WebServiceMockImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(WebServiceMock.class);
    svrFactory.setAddress("http://localhost:63081/webservicemock");
    svrFactory.setServiceBean(webServiceMock);
    svrFactory.getInInterceptors().add(new LoggingInInterceptor());
    svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    server = svrFactory.create();
    server.start();
}
 
Example #18
Source File: AbstractWebServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
    super.initializeProcessEngine();

    webServiceMock = new WebServiceMockImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(WebServiceMock.class);
    svrFactory.setAddress("http://localhost:63081/webservicemock");
    svrFactory.setServiceBean(webServiceMock);
    svrFactory.getInInterceptors().add(new LoggingInInterceptor());
    svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    server = svrFactory.create();
    server.start();
}
 
Example #19
Source File: OnvifDevice.java    From onvif with Apache License 2.0 5 votes vote down vote up
public JaxWsProxyFactoryBean getServiceProxy(BindingProvider servicePort, String serviceAddr) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.getHandlers();

    if (serviceAddr != null) proxyFactory.setAddress(serviceAddr);
    proxyFactory.setServiceClass(servicePort.getClass());

    SoapBindingConfiguration config = new SoapBindingConfiguration();

    config.setVersion(Soap12.getInstance());
    proxyFactory.setBindingConfig(config);
    Client deviceClient = ClientProxy.getClient(servicePort);

    if (verbose) {
      // these logging interceptors are depreciated, but should be fine for debugging/development
      // use.
      proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
      proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    }

    HTTPConduit http = (HTTPConduit) deviceClient.getConduit();
    if (securityHandler != null) proxyFactory.getHandlers().add(securityHandler);
    HTTPClientPolicy httpClientPolicy = http.getClient();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setReceiveTimeout(32000);
    httpClientPolicy.setAllowChunking(false);

    return proxyFactory;
  }
 
Example #20
Source File: InvokeCounter.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    factory.setServiceClass(Counter.class);
    factory.setAddress("http://localhost:12345/counter");
    Counter counter = (Counter) factory.create();
    counter.inc();
    counter.inc();
    counter.inc();
    counter.inc();
    counter.inc();

    System.out.println(counter.getCount());
}
 
Example #21
Source File: HelloWorldImplTest.java    From cxf-jaxws with MIT License 5 votes vote down vote up
private static HelloWorldPortType createClientProxy() {
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();

  // create the loggingInInterceptor and loggingOutInterceptor
  LoggingInInterceptor loggingInInterceptor =
      new LoggingInInterceptor();
  loggingInInterceptor.setPrettyLogging(true);
  LoggingOutInterceptor loggingOutInterceptor =
      new LoggingOutInterceptor();
  loggingOutInterceptor.setPrettyLogging(true);

  // add loggingInterceptor to print the received/sent messages
  jaxWsProxyFactoryBean.getInInterceptors()
      .add(loggingInInterceptor);
  jaxWsProxyFactoryBean.getInFaultInterceptors()
      .add(loggingInInterceptor);
  jaxWsProxyFactoryBean.getOutInterceptors()
      .add(loggingOutInterceptor);
  jaxWsProxyFactoryBean.getOutFaultInterceptors()
      .add(loggingOutInterceptor);

  jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class);
  jaxWsProxyFactoryBean.setAddress(ENDPOINT_ADDRESS);

  return (HelloWorldPortType) jaxWsProxyFactoryBean.create();
}
 
Example #22
Source File: AbstractWebServiceTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
	super.initializeProcessEngine();

       webServiceMock = new WebServiceMockImpl();
	JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
	svrFactory.setServiceClass(WebServiceMock.class);
       svrFactory.setAddress("http://localhost:63081/webservicemock");
       svrFactory.setServiceBean(webServiceMock);
	svrFactory.getInInterceptors().add(new LoggingInInterceptor());
	svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
	server = svrFactory.create();
	server.start();
}
 
Example #23
Source File: AbstractWebServiceTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
    super.initializeProcessEngine();

    webServiceMock = new WebServiceMockImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(WebServiceMock.class);
    svrFactory.setAddress(WEBSERVICE_MOCK_ADDRESS);
    svrFactory.setServiceBean(webServiceMock);
    svrFactory.getInInterceptors().add(new LoggingInInterceptor());
    svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    server = svrFactory.create();
    server.start();
}
 
Example #24
Source File: AbstractWebServiceTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
	super.initializeProcessEngine();

   webServiceMock = new WebServiceMockImpl();
	JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
	svrFactory.setServiceClass(WebServiceMock.class);
   svrFactory.setAddress("http://localhost:63081/webservicemock");
   svrFactory.setServiceBean(webServiceMock);
	svrFactory.getInInterceptors().add(new LoggingInInterceptor());
	svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
	server = svrFactory.create();
	server.start();
}
 
Example #25
Source File: WebServiceTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
    super.initializeProcessEngine();

    webServiceMock = new WebServiceMockImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(WebServiceMock.class);
    svrFactory.setAddress("http://localhost:63081/webservicemock");
    svrFactory.setServiceBean(webServiceMock);
    svrFactory.getInInterceptors().add(new LoggingInInterceptor());
    svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    server = svrFactory.create();
    server.start();
}
 
Example #26
Source File: WebServiceTaskTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 独立启动WebService服务
 */
public static void main(String[] args) {
	Counter counter = new CounterImpl();
	JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
	svrFactory.setServiceClass(Counter.class);
	svrFactory.setAddress("http://localhost:12345/counter");
	svrFactory.setServiceBean(counter);
	svrFactory.getInInterceptors().add(new LoggingInInterceptor());
	svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
	Server server = svrFactory.create();
	server.start();
}
 
Example #27
Source File: TrustedIdpOIDCProtocolHandler.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
private boolean validateSignature(TrustedIdp trustedIdp, JwsJwtCompactConsumer jwtConsumer)
    throws CertificateException, WSSecurityException, ProcessingException, IOException {

    // Validate the Signature
    String sigAlgo = getProperty(trustedIdp, SIGNATURE_ALGORITHM);
    if (sigAlgo == null || sigAlgo.isEmpty()) {
        sigAlgo = "RS256";
    }

    JwtToken jwt = jwtConsumer.getJwtToken();
    String jwksUri = getProperty(trustedIdp, JWKS_URI);
    JsonWebKey verifyingKey = null;

    if (jwksUri != null && jwt.getJwsHeaders() != null
        && jwt.getJwsHeaders().containsHeader(JoseConstants.HEADER_KEY_ID)) {
        String kid = (String)jwt.getJwsHeaders().getHeader(JoseConstants.HEADER_KEY_ID);
        LOG.debug("Attemping to retrieve key id {} from uri {}", kid, jwksUri);
        List<Object> jsonKeyProviders = new ArrayList<>();
        jsonKeyProviders.add(new JsonWebKeysProvider());

        WebClient client =
            WebClient.create(jwksUri, jsonKeyProviders, "cxf-tls.xml");
        client.accept("application/json");

        ClientConfiguration config = WebClient.getConfig(client);
        if (LOG.isDebugEnabled()) {
            config.getOutInterceptors().add(new LoggingOutInterceptor());
            config.getInInterceptors().add(new LoggingInInterceptor());
        }

        Response response = client.get();
        JsonWebKeys jsonWebKeys = response.readEntity(JsonWebKeys.class);
        if (jsonWebKeys != null) {
            verifyingKey = jsonWebKeys.getKey(kid);
        }
    }

    if (verifyingKey != null) {
        return jwtConsumer.verifySignatureWith(verifyingKey, SignatureAlgorithm.getAlgorithm(sigAlgo));
    }

    X509Certificate validatingCert = CertsUtils.parseX509Certificate(trustedIdp.getCertificate());
    if (validatingCert != null) {
        return jwtConsumer.verifySignatureWith(validatingCert, SignatureAlgorithm.getAlgorithm(sigAlgo));
    }

    LOG.warn("No key supplied to verify the signature of the IdToken");
    return false;
}
 
Example #28
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example #29
Source File: RESTServiceExporter.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
	 * This publishes the cxf service onto the cxf bus.
	 *
	 * @param serviceImpl
	 * @throws Exception
	 */
	@Override
	public void publishService(ServiceDefinition serviceDefinition, Object serviceImpl, String address) {
		RestServiceDefinition restServiceDef = (RestServiceDefinition)serviceDefinition;

		LOG.info("Creating JAXRSService " + restServiceDef.getServiceName());
		JAXRSServerFactoryBean svrFactory = new JAXRSServerFactoryBean();
        svrFactory.setBus(getCXFBus());

        List<Object> resources = restServiceDef.getResources();
        if (resources != null && !resources.isEmpty()) {
        	svrFactory.setServiceBeans(resources);
        } else {
        	try {
        		Class<?> resourceClass = this.getClass().getClassLoader().loadClass(restServiceDef.getResourceClass());
        		svrFactory.setResourceClasses(resourceClass);
        		svrFactory.setResourceProvider(resourceClass, new SingletonResourceProvider(serviceImpl));
        	} catch (ClassNotFoundException e) {
        		throw new RiceRuntimeException("Failed to publish the service because resource class could not be loaded: " + restServiceDef.getResourceClass(), e);
        	}
        }

        svrFactory.setServiceName(restServiceDef.getServiceName());
        svrFactory.setAddress(address);
        svrFactory.setExtensionMappings(restServiceDef.getExtensionMappings());
        svrFactory.setLanguageMappings(restServiceDef.getLanguageMappings());

        List<Object> providers = restServiceDef.getProviders();
        if (providers != null) {
        	svrFactory.setProviders(providers);
        }

        BindingFactoryManager bindingFactoryManager = getCXFBus().getExtension(BindingFactoryManager.class);
        JAXRSBindingFactory bindingFactory = new JAXRSBindingFactory();
        bindingFactory.setBus(getCXFBus());
        bindingFactoryManager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory);

		//Set logging interceptors
        if (LOG.isDebugEnabled()) {
        	svrFactory.getInInterceptors().add(new LoggingInInterceptor());
        }
//        svrFactory.getInInterceptors().add(new RESTConnector.VerifyingInInterceptor());
        if (LOG.isDebugEnabled()) {
        	svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
        }
//		svrFactory.getOutInterceptors().add(new RESTConnector.SigningOutInterceptor());

        svrFactory.setPublishedEndpointUrl(restServiceDef.getEndpointUrl().toExternalForm());
		svrFactory.create();
	}
 
Example #30
Source File: GlobalFeature.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
public GlobalFeature() {
    this.loggingInInterceptor = new LoggingInInterceptor();
    this.loggingInInterceptor.setPrettyLogging(true);
    this.loggingOutInterceptor = new LoggingOutInterceptor();
    this.loggingOutInterceptor.setPrettyLogging(true);
}