Class ContextUtils

java.lang.Object
org.apache.cxf.ws.addressing.ContextUtils

public final class ContextUtils extends Object
Holder for utility methods relating to contexts.
  • Field Details

    • WSA_OBJECT_FACTORY

      public static final org.apache.cxf.ws.addressing.ObjectFactory WSA_OBJECT_FACTORY
    • ACTION

      public static final String ACTION
    • ALLOWED_DECOUPLED_DEST_SCHEMES_PROPERTY

      public static final String ALLOWED_DECOUPLED_DEST_SCHEMES_PROPERTY
      System property whose value overrides the comma-separated list of URI scheme prefixes permitted in wsa:ReplyTo / wsa:FaultTo decoupled-destination addresses. Example: -Dorg.apache.cxf.ws.addressing.decoupled.allowedSchemes=http://,https://,jms:
      See Also:
    • WS_ADDRESSING_DECOUPLED_ENABLED_PROPERTY

      public static final String WS_ADDRESSING_DECOUPLED_ENABLED_PROPERTY
      System property that enables WS-Addressing decoupled destinations (non-anonymous wsa:ReplyTo / wsa:FaultTo). Defaults to false — decoupled destinations are disabled by default to prevent SSRF. Set to true only when your deployment legitimately requires decoupled WS-Addressing callbacks.
      See Also:
    • DECOUPLED_DESTINATION_APPROVED_PROPERTY

      public static final String DECOUPLED_DESTINATION_APPROVED_PROPERTY
      Exchange property key that higher-level protocols (e.g. WS-RM) may set to Boolean.TRUE to pre-approve decoupled wsa:ReplyTo / wsa:FaultTo destinations for a specific exchange, bypassing the global "org.apache.cxf.ws.addressing.decoupled.enabled" opt-in flag.

      The URI-scheme allowlist ("org.apache.cxf.ws.addressing.decoupled.allowedSchemes" / DEFAULT_ALLOWED_DECOUPLED_DEST_SCHEMES) is still enforced even when this flag is set, to prevent reaching dangerous URI types (e.g. file://).

      Only trusted CXF modules should set this property.

      See Also:
    • DEFAULT_ALLOWED_DECOUPLED_DEST_SCHEMES

      public static final Set<String> DEFAULT_ALLOWED_DECOUPLED_DEST_SCHEMES
      Default set of URI scheme prefixes permitted in wsa:ReplyTo / wsa:FaultTo decoupled-destination addresses. Schemes that can open arbitrary filesystem or OS resources (file://, corba:, IOR:, etc.) are intentionally excluded.
  • Method Details

    • isOutbound

      public static boolean isOutbound(Message message)
      Determine if message is outbound.
      Parameters:
      message - the current Message
      Returns:
      true iff the message direction is outbound
    • isFault

      public static boolean isFault(Message message)
      Determine if message is fault.
      Parameters:
      message - the current Message
      Returns:
      true iff the message is a fault
    • isRequestor

      public static boolean isRequestor(Message message)
      Determine if current messaging role is that of requestor.
      Parameters:
      message - the current Message
      Returns:
      true if the current messaging role is that of requestor
    • getMAPProperty

      public static String getMAPProperty(boolean isRequestor, boolean isProviderContext, boolean isOutbound)
      Get appropriate property name for message addressing properties.
      Parameters:
      isRequestor - true if the current messaging role is that of requestor
      isProviderContext - true if the binding provider request context available to the client application as opposed to the message context visible to handlers
      isOutbound - true if the message is outbound
      Returns:
      the property name to use when caching the MAPs in the context
    • storeMAPs

      public static void storeMAPs(AddressingProperties maps, Message message, boolean isOutbound)
      Store MAPs in the message.
      Parameters:
      message - the current message
      isOutbound - true if the message is outbound
    • storeMAPs

      public static void storeMAPs(AddressingProperties maps, Message message, boolean isOutbound, boolean isRequestor)
      Store MAPs in the message.
      Parameters:
      maps - the MAPs to store
      message - the current message
      isOutbound - true if the message is outbound
      isRequestor - true if the current messaging role is that of requestor
    • storeMAPs

      public static void storeMAPs(AddressingProperties maps, Message message, boolean isOutbound, boolean isRequestor, boolean isProviderContext)
      Store MAPs in the message.
      Parameters:
      maps - the MAPs to store
      message - the current message
      isOutbound - true if the message is outbound
      isRequestor - true if the current messaging role is that of requestor
      isProviderContext - true if the binding provider request context
    • retrieveMAPs

      public static AddressingProperties retrieveMAPs(Message message, boolean isProviderContext, boolean isOutbound)
      Parameters:
      message - the current message
      isProviderContext - true if the binding provider request context available to the client application as opposed to the message context visible to handlers
      isOutbound - true if the message is outbound
      Returns:
      the current addressing properties
    • retrieveMAPs

      public static AddressingProperties retrieveMAPs(Message message, boolean isProviderContext, boolean isOutbound, boolean warnIfMissing)
      Parameters:
      message - the current message
      isProviderContext - true if the binding provider request context available to the client application as opposed to the message context visible to handlers
      isOutbound - true if the message is outbound
      warnIfMissing - log a warning message if properties cannot be retrieved
      Returns:
      the current addressing properties
    • getAttributedURI

      public static org.apache.cxf.ws.addressing.AttributedURIType getAttributedURI(String uri)
      Helper method to get an attributed URI.
      Parameters:
      uri - the URI
      Returns:
      an AttributedURIType encapsulating the URI
    • getRelatesTo

      public static org.apache.cxf.ws.addressing.RelatesToType getRelatesTo(String uri)
      Helper method to get a RealtesTo instance.
      Parameters:
      uri - the related URI
      Returns:
      a RelatesToType encapsulating the URI
    • isGenericAddress

      public static boolean isGenericAddress(org.apache.cxf.ws.addressing.EndpointReferenceType ref)
      Helper method to determine if an EPR address is generic (either null, none or anonymous).
      Parameters:
      ref - the EPR under test
      Returns:
      true if the address is generic
    • isAnonymousAddress

      public static boolean isAnonymousAddress(org.apache.cxf.ws.addressing.EndpointReferenceType ref)
      Helper method to determine if an EPR address is anon (either null, anonymous).
      Parameters:
      ref - the EPR under test
      Returns:
      true if the address is generic
    • isNoneAddress

      public static boolean isNoneAddress(org.apache.cxf.ws.addressing.EndpointReferenceType ref)
      Helper method to determine if an EPR address is none.
      Parameters:
      ref - the EPR under test
      Returns:
      true if the address is generic
    • hasEmptyAction

      public static boolean hasEmptyAction(AddressingProperties maps)
      Helper method to determine if an MAPs Action is empty (a null action is considered empty, whereas a zero length action suppresses the propagation of the Action property).
      Parameters:
      maps - the MAPs Action under test
      Returns:
      true if the Action is empty
    • propogateReceivedMAPs

      public static void propogateReceivedMAPs(AddressingProperties inMAPs, Exchange exchange)
      Propagate inbound MAPs onto full reponse & fault messages.
      Parameters:
      inMAPs - the inbound MAPs
      exchange - the current Exchange
    • propogateReceivedMAPs

      public static void propogateReceivedMAPs(AddressingProperties inMAPs, Message responseMessage)
      Propogate inbound MAPs onto reponse message if applicable (not applicable for oneways).
      Parameters:
      inMAPs - the inbound MAPs
      responseMessage -
    • storeMAPFaultName

      public static void storeMAPFaultName(String faultName, Message message)
      Store bad MAP fault name in the message.
      Parameters:
      faultName - the fault name to store
      message - the current message
    • retrieveMAPFaultName

      public static String retrieveMAPFaultName(Message message)
      Retrieve MAP fault name from the message.
      Parameters:
      message - the current message
      Returns:
      the retrieved fault name
    • storeMAPFaultReason

      public static void storeMAPFaultReason(String reason, Message message)
      Store MAP fault reason in the message.
      Parameters:
      reason - the fault reason to store
      message - the current message
    • retrieveMAPFaultReason

      public static String retrieveMAPFaultReason(Message message)
      Retrieve MAP fault reason from the message.
      Parameters:
      message - the current message
      Returns:
      the retrieved fault reason
    • storePartialResponseSent

      public static void storePartialResponseSent(Message message)
      Store an indication that a partial response has been sent. Relavant if *both* the replyTo & faultTo are decoupled, and a fault occurs, then we would already have sent the partial response (pre-dispatch) for the replyTo, so no need to send again.
      Parameters:
      message - the current message
    • retrievePartialResponseSent

      public static boolean retrievePartialResponseSent(Message message)
      Retrieve indication that a partial response has been sent.
      Parameters:
      message - the current message
      Returns:
      the retrieved indication that a partial response has been sent
    • storeDeferUncorrelatedMessageAbort

      public static void storeDeferUncorrelatedMessageAbort(Message message)
      Store indication that a deferred uncorrelated message abort is supported
      Parameters:
      message - the current message
    • retrieveDeferUncorrelatedMessageAbort

      public static boolean retrieveDeferUncorrelatedMessageAbort(Message message)
      Retrieve indication that a deferred uncorrelated message abort is supported
      Parameters:
      message - the current message
      Returns:
      the retrieved indication
    • storeDeferredUncorrelatedMessageAbort

      public static void storeDeferredUncorrelatedMessageAbort(Message message)
      Store indication that a deferred uncorrelated message abort should occur
      Parameters:
      message - the current message
    • retrieveDeferredUncorrelatedMessageAbort

      public static boolean retrieveDeferredUncorrelatedMessageAbort(Message message)
      Retrieve indication that a deferred uncorrelated message abort should occur.
      Parameters:
      message - the current message
      Returns:
      the retrieved indication
    • retrieveAsyncPostResponseDispatch

      public static boolean retrieveAsyncPostResponseDispatch(Message message)
      Retrieve indication that an async post-response service invocation is required.
      Parameters:
      message - the current message
      Returns:
      the retrieved indication that an async post-response service invocation is required.
    • generateUUID

      public static String generateUUID()
      Returns:
      a generated UUID
    • getConduit

      public static Conduit getConduit(Conduit conduit, Message message)
      Retreive Conduit from Exchange if not already available
      Parameters:
      conduit - the current value for the Conduit
      message - the current message
      Returns:
      the Conduit if available
    • getNoneEndpointReference

      public static org.apache.cxf.ws.addressing.EndpointReferenceType getNoneEndpointReference()
    • applyReferenceParam

      public static void applyReferenceParam(org.apache.cxf.ws.addressing.EndpointReferenceType toEpr, Object el)
    • createMessage

      public static Message createMessage(Exchange exchange)
      Create a Binding specific Message.
      Parameters:
      exchange - the current exchange
      Returns:
      the Method from the BindingOperationInfo
    • isDecoupledDestinationAllowed

      public static boolean isDecoupledDestinationAllowed(String uri)
      Returns true if uri is permitted as a wsa:ReplyTo / wsa:FaultTo decoupled-destination address for the WS-Addressing path.

      WS-Addressing decoupled destinations are disabled by default to prevent SSRF: any attacker who can craft a SOAP request can otherwise force the server to open an outbound connection to any URL. Enable with "org.apache.cxf.ws.addressing.decoupled.enabled"=true.

      When enabled, the URI must start with a prefix from "org.apache.cxf.ws.addressing.decoupled.allowedSchemes" or DEFAULT_ALLOWED_DECOUPLED_DEST_SCHEMES.

    • logDisallowedDecoupledDestinationScheme

      public static void logDisallowedDecoupledDestinationScheme(Logger logger, Level level, String destinationUri)
      Log a message after isDecoupledDestinationAllowed(String) returned false.
      Parameters:
      logger - the Logger to pass the message to
      level - log Level on which the message should be logged
      destinationUri - the URI banned due to the configuration
    • logRejectedDecoupledDestination

      public static void logRejectedDecoupledDestination(Logger logger, Level level, String destinationUri)
      Log a message after isDecoupledDestinationAllowed(String) returned false for messages having "org.apache.cxf.ws.addressing.decoupled.approved" set to true.
      Parameters:
      logger - the Logger to pass the message to
      level - log Level on which the message should be logged
      destinationUri - the URI banned due to the configuration
    • logDecoupledFaultToSchemeNotAllowed

      public static void logDecoupledFaultToSchemeNotAllowed(Logger logger, Level level, String destinationUri)
      Log a message after isDecoupledDestinationSchemeAllowed(String) returned false for messages having "org.apache.cxf.ws.addressing.decoupled.approved" set to true.
      Parameters:
      logger - the Logger to pass the message to
      level - log Level on which the message should be logged
      destinationUri - the URI banned due to the configuration
    • logDecoupledFaultToNotAllowed

      public static void logDecoupledFaultToNotAllowed(Logger logger, Level level, String destinationUri)
      Log a message after isDecoupledDestinationAllowed(String) returned false for FaultTo URI.
      Parameters:
      logger - the Logger to pass the message to
      level - log Level on which the message should be logged
      destinationUri - the URI banned due to the configuration
    • formatDecoupledReplyToNotPermittedMessage

      public static String formatDecoupledReplyToNotPermittedMessage(String destinationUri)
      Create a SOAP Fault reason after isDecoupledDestinationAllowed(String) returned false.
      Parameters:
      destinationUri - the URI banned due to the configuration
      Returns:
      a formatted message
    • formatDecoupledReplyToSchemeNotPermittedMessage

      public static String formatDecoupledReplyToSchemeNotPermittedMessage(String destinationUri)
      Create a SOAP Fault reason after isDecoupledDestinationSchemeAllowed(String) returned false.
      Parameters:
      destinationUri - the URI banned due to the configuration
      Returns:
      a formatted message
    • isDecoupledDestinationSchemeAllowed

      public static boolean isDecoupledDestinationSchemeAllowed(String uri)
    • createDecoupledDestination

      public static Destination createDecoupledDestination(Exchange exchange, org.apache.cxf.ws.addressing.EndpointReferenceType reference)