Apache CXF Documentation

repository·main·Indexed 21 days ago

https://github.com/apache/cxf

An open-source services framework for building and deploying SOAP (via JAX-WS) and REST (via JAX-RS) web services in Java. It supports contract-first and code-first workflows, Spring Boot integration, and various security standards including OAuth 2.0, OpenID Connect, and SAML. The framework provides comprehensive tools for message logging, observability via Micrometer, and a flexible Client interface for synchronous and asynchronous service invocation.

Tokens
7.4K
Snippets
18
Records
32
Agent score
75%

What's inside Apache CXF

  1. Overview of XKMS implementation components

    main

    The Apache CXF XKMS (XML Key Management Service) implementation is organized into several modules:

    • xkms-client: Contains the XKMS client and invoker implementations.
    • xkms-common: Contains common functionality, XML schemas, and generated code.
    • xkms-service: The core XKMS service implementation.
    • xkms-x509-handlers: Implementation of pluggable commands for X509 keys.
    • xkms-features: Karaf features for both the XKMS client and service.
    • xkms-itests: Integration tests.
    • xkms-osgi: OSGi blueprint configuration for OSGi deployment.
    • xkms-war: Web Spring configuration for Web deployment.
  2. Overview of Apache CXF capabilities

    main

    Apache CXF is an open-source services framework for building and deploying web services and REST APIs in Java. It supports multiple programming models and protocols:

    Core Programming Models (Frontends)

    • JAX-WS: For building SOAP-based web services.
    • JAX-RS: For building RESTful services.
    • Simple Frontend: For creating clients and endpoints without using annotations.

    Key Features

    • Development Approaches: Supports both contract-first (generating Java from WSDL or OpenAPI specs) and code-first (generating WSDL or OpenAPI specs from annotated Java classes) workflows.
    • Security: Provides support for WS-Security, WS-SecurityPolicy, OAuth 2.0, OpenID Connect (OIDC), JWT, TLS configuration, client certificate authentication, and SAML token handling.
    • Spring Boot Integration: Offers dedicated Spring Boot starters for JAX-WS and JAX-RS to enable auto-configured, embedded service deployment.
    • Observability: Includes built-in Micrometer integration for collecting metrics (latency, error rates, throughput) compatible with Prometheus and Grafana.
    • Protocol & Transport Support: Supports SOAP, XML/HTTP, RESTful HTTP, and CORBA over transports such as HTTP, JMS, and JBI.
  3. Security properties provided by Apache CXF

    main

    Apache CXF provides several security mechanisms, but their effectiveness is strictly conditional on the integrator enabling and correctly configuring them. The core security properties include:

    1. Message-level authentication & integrity via WS-Security: When WS-SecurityPolicy or relevant interceptors are configured, CXF verifies signatures and tokens and enforces replay windows.
    2. Authorization enforcement: Using interceptors like AbstractAuthorizingInInterceptor, CXF can deny operations if the established identity lacks the required roles.
    3. Safe-by-default XML processing: CXF uses secure StAX processing and implements input limits (depth, entity, element, and size) to mitigate XML External Entity (XXE) attacks and XML-bomb Denial of Service (DoS).
    4. Transport security support: Support for TLS conduits and listeners with hostname and certificate validation.
    5. Robust message parsing: Designed to yield clean SOAP/REST faults for malformed input rather than causing memory corruption or system crashes.
  4. Identify Trust Boundaries and Data Flow in CXF

    main

    In a CXF application, the primary trust boundary is the endpoint's inbound interceptor chain. Data transitions from untrusted to trusted through the following stages:

    1. Wire → StAX/XML Parse: Raw SOAP/XML is parsed. This is a critical surface for XML attacks like XXE (XML External Entity) and DoS (e.g., Billion Laughs). CXF provides input-limit and secure-parsing defaults to mitigate this.
    2. Parsed Message → WS-Security: If configured, interceptors verify signatures, encryption, and tokens (SAML, X.509, etc.). Without this, the message is only trusted at the transport layer.
    3. Message → Authorization: Authorizing interceptors (e.g., AbstractAuthorizingInInterceptor) map the validated identity to specific roles or permitted operations.
    4. REST Body → Provider: JAX-RS providers unmarshal bodies (JSON/XML/multipart) into objects. This is a surface for deserialization attacks and parser-based DoS.
    5. Client Conduit → Remote Fetch: When acting as a client, CXF may perform outbound requests to resolve WSDLs, schemas, or MTOM references. If these URLs are attacker-influenced, it creates an SSRF (Server-Side Request Forgery) surface.
  5. Security 'False Friends' in CXF

    main

    Be aware of features that may appear to provide security but require additional configuration to be effective:

    • UsernameToken in SOAP headers: This is only as strong as the configured validation and the underlying transport. A plaintext UsernameToken over non-TLS is interceptable.
    • XML Signatures: A signature covering 'an' element is not the same as covering 'the' element. Naive 'is it signed?' checks are vulnerable to signature-wrapping (XSW); the binding must verify exactly what is signed.
    • WS-ReliableMessaging / WS-Addressing: These protocols provide reliability and routing, not security.
  6. Understand the Apache CXF Security Model and Scope

    main

    Apache CXF is a services framework for building and consuming SOAP (JAX-WS) and REST (JAX-RS) services. It is important to distinguish between the framework's responsibilities and the integrator's responsibilities:

    Framework Responsibilities (In-Scope)

    CXF provides the mechanisms for security, including:

    • Message Pipeline: Interceptor-based processing for SOAP/XML and REST/JSON/Multipart.
    • WS-Security: Support for signatures, encryption, and token validation (UsernameToken, SAML, X.509, Kerberos) via WSS4J.
    • AuthN/AuthZ: Interceptors for mapping identity to roles (e.g., AbstractAuthorizingInInterceptor).
    • Transport: Support for TLS conduits and HTTP transports.
    • Input Protection: Mechanisms for XML/JSON parsing and input limits.

    Integrator Responsibilities (Out-of-Scope)

    CXF is a framework, not a deployed application. The Service Integrator (the developer/operator) is responsible for:

    • Configuration: Selecting which transports, interceptors, and WS-SecurityPolicy settings are active.
    • Security Posture: Enabling TLS enforcement, configuring WS-Security interceptors, and setting input limits.
    • Misconfigurations: Any insecurity resulting from a developer choosing to disable security controls (e.g., trusting all TLS certs or exposing unauthenticated endpoints) is considered an integrator error, not a framework vulnerability.

    Component Scope Table

    FamilyEntry pointIn Model?
    SOAP / JAX-WSendpoint + interceptor chain, StAX/XML parseYes
    WS-Securitysig/enc/UsernameToken/SAML/Timestamp interceptorsYes
    REST / JAX-RSresource matching, providers (JSON/XML/multipart)Yes
    HTTP transportHTTP(S) conduit, WSDL/schema/MTOM URL fetchYes
    AuthN/AuthZinterceptor.security.*, common.security.*Yes
    XJC codegenapache/cxf-xjc-utils (build-time)No
  7. Install XKMS for Apache Karaf 2.x

    main

    To install the XKMS client and service in Apache Karaf 2.x, add the features URL from the Maven repository and then install the specific service and client features.

    features:addurl mvn:org.apache.cxf.services.xkms/cxf-services-xkms-features/3.4.0-SNAPSHOT/xml
    features:install cxf-xkms-service cxf-xkms-client
  8. How to get started with Apache CXF

    main

    Depending on your needs, follow these paths to begin using Apache CXF:

    Using a Binary Distribution

    If you are using a pre-compiled binary distribution, refer to release_notes.txt for installation instructions and a list of supported/unsupported features.

    Building from Source

    If you wish to build Apache CXF from the source distribution, refer to BUILDING.txt for detailed instructions.

    Online Documentation

    For comprehensive guides and additional information, visit the official website: https://cxf.apache.org/

  9. Deploy the STS sample WAR to Tomcat

    main

    The sts-war module provides a sample WAR deployment for the Security Token Service (STS). You can deploy it to a Tomcat server using the Maven Tomcat plugin.

    Note: If you intend to run system tests against this deployment, you must configure TLS in Tomcat by enabling a port (typically 8443) in the conf/server.xml file.

    mvn tomcat:deploy
  10. Configure CXF Security via Runtime Knobs

    main

    The security envelope of a CXF application is defined by runtime configuration. Developers should focus on the following high-leverage configuration areas to harden their services:

    Configuration AreaSecurity Impact
    XML ParsingConfigure StAX secure-processing, DocumentDepth, entity-expansion, and element-count limits to prevent XXE and XML-DoS.
    WS-SecurityConfigure WS-SecurityPolicy and WS-Security interceptors to ensure messages are signed, encrypted, and authenticated.
    StreamingChoose between allowStreaming and DOM-based WS-Security; streaming modes change the XSW (XML Signature Wrapping) and validation surface.
    TransportEnforce TLS on the conduit/listener to ensure transport confidentiality and integrity.
    JAX-RS ProvidersHarden JSON/XML libraries and use deserialization allow-lists to prevent RCE and XXE via providers.
    Remote ResolutionControl property/URL resolution for WSDL, schema, and MTOM imports to prevent SSRF.

    Note: Unconfigured security (e.g., no WS-Security interceptors) defaults to transport-only trust.

  11. Use the Jakarta REST TCK to test specification compliance

    main

    The Jakarta REST TCK (Technology Compatibility Kit) is a standalone kit used to test whether a Jakarta REST implementation complies with the Jakarta REST specification.

    Important Note: This specific TCK contains only tests added since Jakarta REST 3.0. For full certification compliance, you must also perform tests from the Jakarta Platform TCK to cover historical requirements.