Class AbstractWsSecurityInterceptor
- All Implemented Interfaces:
org.springframework.core.Ordered, org.springframework.ws.client.support.interceptor.ClientInterceptor, org.springframework.ws.server.EndpointInterceptor, org.springframework.ws.soap.server.SoapEndpointInterceptor
- Direct Known Subclasses:
Wss4jSecurityInterceptor
endpoint mapping; or on the client side, on the
web service template.
Subclasses of this base class can be configured to secure incoming and secure outgoing messages. By default, both are on.
- Since:
- 1.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault order for WS-Security interceptors, ensuring they run early.protected final org.apache.commons.logging.LogLogger available to subclasses.static final StringFault string of the fault returned to the sender when validation of a request fails.protected static final QNameFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterCompletion(org.springframework.ws.context.MessageContext messageContext, @Nullable Exception ex) voidafterCompletion(org.springframework.ws.context.MessageContext messageContext, Object endpoint, @Nullable Exception ex) protected abstract voidcleanUp()intgetOrder()booleanhandleFault(org.springframework.ws.context.MessageContext messageContext) Returnstrue, i.e.booleanhandleFault(org.springframework.ws.context.MessageContext messageContext, Object endpoint) Returnstrue, i.e.protected booleanhandleFaultException(WsSecurityFaultException ex, org.springframework.ws.context.MessageContext messageContext) Handles a fault exception.Default implementation logs the given exception, and creates a SOAP Fault with the properties of the given exception, and returnsfalse.final booleanhandleRequest(org.springframework.ws.context.MessageContext messageContext) Secures a client-side outgoing request.final booleanhandleRequest(org.springframework.ws.context.MessageContext messageContext, Object endpoint) Validates a server-side incoming request.final booleanhandleResponse(org.springframework.ws.context.MessageContext messageContext) Validates a client-side incoming response.final booleanhandleResponse(org.springframework.ws.context.MessageContext messageContext, Object endpoint) Secures a server-side outgoing response.protected booleanhandleSecurementException(WsSecuritySecurementException ex, org.springframework.ws.context.MessageContext messageContext) Handles an securement exception.protected booleanhandleValidationException(WsSecurityValidationException ex, org.springframework.ws.context.MessageContext messageContext) Handles an invalid SOAP message.protected abstract voidsecureMessage(org.springframework.ws.soap.SoapMessage soapMessage, org.springframework.ws.context.MessageContext messageContext) Abstract template method.voidsetExceptionResolver(org.springframework.ws.server.EndpointExceptionResolver exceptionResolver) Provide anEndpointExceptionResolverfor resolving validation exceptions.voidsetSecureRequest(boolean secureRequest) Indicates whether client-side outgoing requests are to be secured.voidsetSecureResponse(boolean secureResponse) Indicates whether server-side outgoing responses are to be secured.voidsetSkipValidationIfNoHeaderPresent(boolean skipValidationIfNoHeaderPresent) Indicates whether validation is skipped for messages that carry nowsse:Securityheader.voidsetValidateRequest(boolean validateRequest) Indicates whether server-side incoming request are to be validated.voidsetValidateResponse(boolean validateResponse) Indicates whether client-side incoming responses are to be validated.booleanunderstands(org.springframework.ws.soap.SoapHeaderElement headerElement) protected abstract voidvalidateMessage(org.springframework.ws.soap.SoapMessage soapMessage, org.springframework.ws.context.MessageContext messageContext) Abstract template method.
-
Field Details
-
DEFAULT_ORDER
public static final int DEFAULT_ORDERDefault order for WS-Security interceptors, ensuring they run early. Any interceptor with a higher precedence than -200 will therefore run before security is applied.- Since:
- 3.1.9
- See Also:
-
VALIDATION_FAULT_STRING
Fault string of the fault returned to the sender when validation of a request fails.The same fault string is used whatever went wrong, so that the fault does not tell a sender which check failed. The details are logged instead, see
handleValidationException(WsSecurityValidationException, MessageContext).- Since:
- 3.1.10
- See Also:
-
logger
protected final org.apache.commons.logging.Log loggerLogger available to subclasses. -
WS_SECURITY_NAME
-
-
Constructor Details
-
AbstractWsSecurityInterceptor
public AbstractWsSecurityInterceptor()
-
-
Method Details
-
setValidateRequest
public void setValidateRequest(boolean validateRequest) Indicates whether server-side incoming request are to be validated. Defaults totrue. -
setSecureResponse
public void setSecureResponse(boolean secureResponse) Indicates whether server-side outgoing responses are to be secured. Defaults totrue. -
setSecureRequest
public void setSecureRequest(boolean secureRequest) Indicates whether client-side outgoing requests are to be secured. Defaults totrue. -
setValidateResponse
public void setValidateResponse(boolean validateResponse) Indicates whether client-side incoming responses are to be validated. Defaults totrue. -
setExceptionResolver
public void setExceptionResolver(org.springframework.ws.server.EndpointExceptionResolver exceptionResolver) Provide anEndpointExceptionResolverfor resolving validation exceptions. -
setSkipValidationIfNoHeaderPresent
public void setSkipValidationIfNoHeaderPresent(boolean skipValidationIfNoHeaderPresent) Indicates whether validation is skipped for messages that carry nowsse:Securityheader. Defaults tofalse.On the server side, this applies to incoming requests, and the sender of a request decides whether to include the header. Enabling this therefore makes every
validation actionconfigured on this interceptor optional from the caller's point of view: a request that simply omits the header reaches the endpoint with no signature, encryption, timestamp or username token check applied. Do not enable this for endpoints that rely on WS-Security to authenticate or authorize their callers.On the client side, this applies to the
validation of responsesreceived from a server that the client chose to call, where accepting an unsecured reply is usually a deliberate interoperability decision rather than a trust boundary. -
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
handleRequest
public final boolean handleRequest(org.springframework.ws.context.MessageContext messageContext, Object endpoint) throws Exception Validates a server-side incoming request. Delegates tovalidateMessage(org.springframework.ws.soap.SoapMessage,org.springframework.ws.context.MessageContext)if thevalidateRequestproperty istrue.- Specified by:
handleRequestin interfaceorg.springframework.ws.server.EndpointInterceptor- Parameters:
messageContext- the message context, containing the request to be validatedendpoint- chosen endpoint to invoke- Returns:
trueif the request was valid;falseotherwise.- Throws:
Exception- in case of errors- See Also:
-
handleResponse
public final boolean handleResponse(org.springframework.ws.context.MessageContext messageContext, Object endpoint) throws Exception Secures a server-side outgoing response. Delegates tosecureMessage(org.springframework.ws.soap.SoapMessage,org.springframework.ws.context.MessageContext)if thesecureResponseproperty istrue.- Specified by:
handleResponsein interfaceorg.springframework.ws.server.EndpointInterceptor- Parameters:
messageContext- the message context, containing the response to be securedendpoint- chosen endpoint to invoke- Returns:
trueif the response was secured;falseotherwise.- Throws:
Exception- in case of errors- See Also:
-
handleFault
-
afterCompletion
-
understands
public boolean understands(org.springframework.ws.soap.SoapHeaderElement headerElement) - Specified by:
understandsin interfaceorg.springframework.ws.soap.server.SoapEndpointInterceptor
-
handleRequest
public final boolean handleRequest(org.springframework.ws.context.MessageContext messageContext) throws org.springframework.ws.client.WebServiceClientException Secures a client-side outgoing request. Delegates tosecureMessage(org.springframework.ws.soap.SoapMessage,org.springframework.ws.context.MessageContext)if thesecureRequestproperty istrue.- Specified by:
handleRequestin interfaceorg.springframework.ws.client.support.interceptor.ClientInterceptor- Parameters:
messageContext- the message context, containing the request to be secured- Returns:
trueif the response was secured;falseotherwise.- Throws:
org.springframework.ws.client.WebServiceClientException- See Also:
-
handleResponse
public final boolean handleResponse(org.springframework.ws.context.MessageContext messageContext) throws org.springframework.ws.client.WebServiceClientException Validates a client-side incoming response. Delegates tovalidateMessage(org.springframework.ws.soap.SoapMessage,org.springframework.ws.context.MessageContext)if thevalidateResponseproperty istrue.- Specified by:
handleResponsein interfaceorg.springframework.ws.client.support.interceptor.ClientInterceptor- Parameters:
messageContext- the message context, containing the response to be validated- Returns:
trueif the request was valid;falseotherwise.- Throws:
org.springframework.ws.client.WebServiceClientException- See Also:
-
handleFault
public boolean handleFault(org.springframework.ws.context.MessageContext messageContext) throws org.springframework.ws.client.WebServiceClientException Returnstrue, i.e. fault responses are not validated.- Specified by:
handleFaultin interfaceorg.springframework.ws.client.support.interceptor.ClientInterceptor- Throws:
org.springframework.ws.client.WebServiceClientException
-
afterCompletion
public void afterCompletion(org.springframework.ws.context.MessageContext messageContext, @Nullable Exception ex) throws org.springframework.ws.client.WebServiceClientException - Specified by:
afterCompletionin interfaceorg.springframework.ws.client.support.interceptor.ClientInterceptor- Throws:
org.springframework.ws.client.WebServiceClientException
-
handleSecurementException
protected boolean handleSecurementException(WsSecuritySecurementException ex, org.springframework.ws.context.MessageContext messageContext) Handles an securement exception. Default implementation logs the given exception, and returnsfalse.- Parameters:
ex- the validation exceptionmessageContext- the message context- Returns:
trueto continue processing the message,false(the default) otherwise
-
handleValidationException
protected boolean handleValidationException(WsSecurityValidationException ex, org.springframework.ws.context.MessageContext messageContext) Handles an invalid SOAP message. Default implementation logs the given exception, delegates to the setexceptionResolverif any, or creates a SOAP 1.1 Client or SOAP 1.2 Sender Fault withVALIDATION_FAULT_STRINGas fault string, and returnsfalse.- Parameters:
ex- the validation exceptionmessageContext- the message context- Returns:
trueto continue processing the message,false(the default) otherwise
-
handleFaultException
protected boolean handleFaultException(WsSecurityFaultException ex, org.springframework.ws.context.MessageContext messageContext) Handles a fault exception.Default implementation logs the given exception, and creates a SOAP Fault with the properties of the given exception, and returnsfalse.- Parameters:
ex- the validation exceptionmessageContext- the message context- Returns:
trueto continue processing the message,false(the default) otherwise
-
validateMessage
protected abstract void validateMessage(org.springframework.ws.soap.SoapMessage soapMessage, org.springframework.ws.context.MessageContext messageContext) throws WsSecurityValidationException Abstract template method. Subclasses are required to validate the request contained in the givenSoapMessage, and replace the original request with the validated version.- Parameters:
soapMessage- the soap message to validate- Throws:
WsSecurityValidationException- in case of validation errors
-
secureMessage
protected abstract void secureMessage(org.springframework.ws.soap.SoapMessage soapMessage, org.springframework.ws.context.MessageContext messageContext) throws WsSecuritySecurementException Abstract template method. Subclasses are required to secure the response contained in the givenSoapMessage, and replace the original response with the secured version.- Parameters:
soapMessage- the soap message to secure- Throws:
WsSecuritySecurementException- in case of securement errors
-
cleanUp
protected abstract void cleanUp()
-