Class AbstractWsSecurityInterceptor
java.lang.Object
org.springframework.ws.soap.security.AbstractWsSecurityInterceptor
- All Implemented Interfaces:
ClientInterceptor
,EndpointInterceptor
,SoapEndpointInterceptor
- Direct Known Subclasses:
Wss4jSecurityInterceptor
public abstract class AbstractWsSecurityInterceptor
extends Object
implements SoapEndpointInterceptor, ClientInterceptor
Interceptor base class for interceptors that handle WS-Security. Can be used on the server side, registered in a
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
- Author:
- Arjen Poutsma
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.apache.commons.logging.Log
Logger available to subclasses.protected static final QName
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterCompletion
(MessageContext messageContext, Exception ex) Callback after completion of request and response (fault) processing.void
afterCompletion
(MessageContext messageContext, Object endpoint, Exception ex) Callback after completion of request and response (fault) processing.protected abstract void
cleanUp()
boolean
handleFault
(MessageContext messageContext) Returnstrue
, i.e.boolean
handleFault
(MessageContext messageContext, Object endpoint) Returnstrue
, i.e.protected boolean
handleFaultException
(WsSecurityFaultException ex, 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 boolean
handleRequest
(MessageContext messageContext) Secures a client-side outgoing request.final boolean
handleRequest
(MessageContext messageContext, Object endpoint) Validates a server-side incoming request.final boolean
handleResponse
(MessageContext messageContext) Validates a client-side incoming response.final boolean
handleResponse
(MessageContext messageContext, Object endpoint) Secures a server-side outgoing response.protected boolean
handleSecurementException
(WsSecuritySecurementException ex, MessageContext messageContext) Handles an securement exception.protected boolean
handleValidationException
(WsSecurityValidationException ex, MessageContext messageContext) Handles an invalid SOAP message.protected abstract void
secureMessage
(SoapMessage soapMessage, MessageContext messageContext) Abstract template method.void
setExceptionResolver
(EndpointExceptionResolver exceptionResolver) Provide anEndpointExceptionResolver
for resolving validation exceptions.void
setSecureRequest
(boolean secureRequest) Indicates whether client-side outgoing requests are to be secured.void
setSecureResponse
(boolean secureResponse) Indicates whether server-side outgoing responses are to be secured.void
setSkipValidationIfNoHeaderPresent
(boolean skipValidationIfNoHeaderPresent) Allows skipping validation if no security header is present.void
setValidateRequest
(boolean validateRequest) Indicates whether server-side incoming request are to be validated.void
setValidateResponse
(boolean validateResponse) Indicates whether client-side incoming responses are to be validated.boolean
understands
(SoapHeaderElement headerElement) Given aSoapHeaderElement
, return whether or not thisSoapEndpointInterceptor
understands it.protected abstract void
validateMessage
(SoapMessage soapMessage, MessageContext messageContext) Abstract template method.
-
Field Details
-
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
Provide anEndpointExceptionResolver
for resolving validation exceptions. -
setSkipValidationIfNoHeaderPresent
public void setSkipValidationIfNoHeaderPresent(boolean skipValidationIfNoHeaderPresent) Allows skipping validation if no security header is present. -
handleRequest
Validates a server-side incoming request. Delegates tovalidateMessage(org.springframework.ws.soap.SoapMessage,org.springframework.ws.context.MessageContext)
if thevalidateRequest
property istrue
.- Specified by:
handleRequest
in interfaceEndpointInterceptor
- Parameters:
messageContext
- the message context, containing the request to be validatedendpoint
- chosen endpoint to invoke- Returns:
true
if the request was valid;false
otherwise.- Throws:
Exception
- in case of errors- See Also:
-
handleResponse
public final boolean handleResponse(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 thesecureResponse
property istrue
.- Specified by:
handleResponse
in interfaceEndpointInterceptor
- Parameters:
messageContext
- the message context, containing the response to be securedendpoint
- chosen endpoint to invoke- Returns:
true
if the response was secured;false
otherwise.- Throws:
Exception
- in case of errors- See Also:
-
handleFault
Returnstrue
, i.e. fault responses are not secured.- Specified by:
handleFault
in interfaceEndpointInterceptor
- Parameters:
messageContext
- contains both request and response messages, the response should contains a Faultendpoint
- chosen endpoint to invoke- Returns:
true
to continue processing of the response interceptor chain;false
to indicate blocking of the response handler chain.- Throws:
Exception
-
afterCompletion
Description copied from interface:EndpointInterceptor
Callback after completion of request and response (fault) processing. Will be called on any outcome of endpoint invocation, thus allows for proper resource cleanup.Note: Will only be called if this interceptor's
EndpointInterceptor.handleRequest(org.springframework.ws.context.MessageContext, java.lang.Object)
method has successfully completed.As with the
EndpointInterceptor.handleResponse(org.springframework.ws.context.MessageContext, java.lang.Object)
method, the method will be invoked on each interceptor in the chain in reverse order, so the first interceptor will be the last to be invoked.- Specified by:
afterCompletion
in interfaceEndpointInterceptor
- Parameters:
messageContext
- contains both request and response messages, the response should contains a Faultendpoint
- chosen endpoint to invokeex
- exception thrown on handler execution, if any
-
understands
Description copied from interface:SoapEndpointInterceptor
Given aSoapHeaderElement
, return whether or not thisSoapEndpointInterceptor
understands it.- Specified by:
understands
in interfaceSoapEndpointInterceptor
- Parameters:
headerElement
- the header- Returns:
true
if understood,false
otherwise
-
handleRequest
Secures a client-side outgoing request. Delegates tosecureMessage(org.springframework.ws.soap.SoapMessage,org.springframework.ws.context.MessageContext)
if thesecureRequest
property istrue
.- Specified by:
handleRequest
in interfaceClientInterceptor
- Parameters:
messageContext
- the message context, containing the request to be secured- Returns:
true
if the response was secured;false
otherwise.- Throws:
Exception
- in case of errorsWebServiceClientException
- in case of errors- See Also:
-
handleResponse
Validates a client-side incoming response. Delegates tovalidateMessage(org.springframework.ws.soap.SoapMessage,org.springframework.ws.context.MessageContext)
if thevalidateResponse
property istrue
.- Specified by:
handleResponse
in interfaceClientInterceptor
- Parameters:
messageContext
- the message context, containing the response to be validated- Returns:
true
if the request was valid;false
otherwise.- Throws:
Exception
- in case of errorsWebServiceClientException
- in case of errors- See Also:
-
handleFault
Returnstrue
, i.e. fault responses are not validated.- Specified by:
handleFault
in interfaceClientInterceptor
- Parameters:
messageContext
- contains the outgoing request message- Returns:
true
to continue processing of the request interceptors;false
to indicate blocking of the request endpoint chain- Throws:
WebServiceClientException
- in case of errors- See Also:
-
afterCompletion
public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException Description copied from interface:ClientInterceptor
Callback after completion of request and response (fault) processing. Will be called on any outcome, thus allows for proper resource cleanup.Note: Will only be called if this interceptor's
ClientInterceptor.handleRequest(org.springframework.ws.context.MessageContext)
method has successfully completed.- Specified by:
afterCompletion
in interfaceClientInterceptor
- Parameters:
messageContext
- contains both request and response messages, the response should contains a Faultex
- exception thrown on handler execution, if any- Throws:
WebServiceClientException
- in case of errors
-
handleSecurementException
protected boolean handleSecurementException(WsSecuritySecurementException ex, MessageContext messageContext) Handles an securement exception. Default implementation logs the given exception, and returnsfalse
.- Parameters:
ex
- the validation exceptionmessageContext
- the message context- Returns:
true
to continue processing the message,false
(the default) otherwise
-
handleValidationException
protected boolean handleValidationException(WsSecurityValidationException ex, MessageContext messageContext) Handles an invalid SOAP message. Default implementation logs the given exception, delegates to the setexceptionResolver
if any, or creates a SOAP 1.1 Client or SOAP 1.2 Sender Fault with the exception message as fault string, and returnsfalse
.- Parameters:
ex
- the validation exceptionmessageContext
- the message context- Returns:
true
to continue processing the message,false
(the default) otherwise
-
handleFaultException
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:
true
to continue processing the message,false
(the default) otherwise
-
validateMessage
protected abstract void validateMessage(SoapMessage soapMessage, 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(SoapMessage soapMessage, 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()
-