Class BaseSAMLMessageParser
- java.lang.Object
-
- org.certificateservices.messages.saml2.BaseSAMLMessageParser
-
- Direct Known Subclasses:
DSS1CoreMessageParser,SAMLAssertionMessageParser,SAMLMetaDataMessageParser,SAMLProtocolMessageParser
public abstract class BaseSAMLMessageParser extends java.lang.ObjectBase SAML Message Parser that all SAML Message Parser that is not connected to the CSMessage workflow should inherit.It is possible to extend the parsing of XML using the settings 'jaxb.customclasspath' and 'jaxb.customschemas'
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBaseSAMLMessageParser.AssertionSignatureLocationFinderprotected classBaseSAMLMessageParser.BaseLSResourceResolverstatic interfaceBaseSAMLMessageParser.ConditionLookupClass used to verify certain conditions such as OneTimestatic classBaseSAMLMessageParser.EncryptedAttributeXMLConverterConverter that replaces all decrypted EncryptedAttributes with Attributesstatic classBaseSAMLMessageParser.SAMLPSignatureLocationFinderstatic classBaseSAMLMessageParser.SimpleConditionLookupSimple Condition lookup that doesn't support the OneTime or AudienceRestriction Conditions but throws MessageContentException if they exists.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringASSERTION_NAMESPACEstatic java.lang.StringASSERTION_XSD_SCHEMA_2_0_RESOURCE_LOCATIONprotected BaseSAMLMessageParser.AssertionSignatureLocationFinderassertionSignatureLocationFinderprotected java.security.cert.CertificateFactorycfprotected SAMLParserCustomisationscustomisationsprotected java.lang.StringcustomJAXBClasspathprotected java.lang.String[]customSchemaLocationsstatic java.lang.StringDEFAULT_SAML_VERSIONprotected ObjectFactorydsigOfprotected MessageSecurityProvidermessageSecurityProviderprotected ObjectFactoryofstatic java.lang.StringPROTOCOL_NAMESPACEstatic java.lang.StringSAMLP_XSD_SCHEMA_2_0_RESOURCE_LOCATIONprotected ObjectFactorysamlpOfprotected BaseSAMLMessageParser.SAMLPSignatureLocationFindersamlpSignatureLocationFinderprotected javax.xml.validation.ValidatorschemaValidatorstatic java.lang.StringSETTING_CUSTOM_JAXBCLASSPATHA ':' separated string containing package paths to JAXB libraries used with extensions to the parser.static java.lang.StringSETTING_CUSTOM_SCHEMALOCATIONSA ':' separated string containing the resource path to custom schemas used during validation.protected SystemTimesystemTimeprotected XMLEncrypterxmlEncrypterprotected XMLSignerxmlSigner
-
Constructor Summary
Constructors Constructor Description BaseSAMLMessageParser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description javax.xml.bind.JAXBElement<AssertionType>decryptAssertion(ContextMessageSecurityProvider.Context context, javax.xml.bind.JAXBElement<AssertionType> assertion)Method to decrypt an assertion containing encrypted attributes.javax.xml.validation.SchemagenerateSchema()byte[]genFailureMessage(ContextMessageSecurityProvider.Context context, java.lang.String inResponseTo, ResponseStatusCodes statusCode, java.lang.String failureMessage)Method to generate a general SAMLP failure message.byte[]genFailureMessage(ContextMessageSecurityProvider.Context context, java.lang.String inResponseTo, NameIDType issuer, java.lang.String destination, java.lang.String consent, ExtensionsType extensions, ResponseStatusCodes statusCode, java.lang.String failureMessage, boolean signSAMLPResponse)Method to generate a general SAMLP failure message.javax.xml.bind.JAXBElement<ResponseType>genSuccessfulSAMLPResponse(java.lang.String inResponseTo, javax.xml.bind.JAXBElement<AssertionType> assertion)Generates a simple basic SAMLP response containing one unencrypted assertion.javax.xml.bind.JAXBElement<AssertionType>getAssertionFromResponseType(ResponseType responseType)Help method to extract a Assertion to be included in a CSMessasge from a response typejava.security.cert.X509CertificategetCertificateFromAssertion(javax.xml.bind.JAXBElement<AssertionType> assertion)Help method to get the first signing certificate from a digital signature.protected abstract java.lang.String[]getDefaultSchemaLocations()protected javax.xml.parsers.DocumentBuildergetDocumentBuilder()protected javax.xml.bind.JAXBContextgetJAXBContext()Help method maintaining the JAXB Context.protected abstract java.lang.StringgetJAXBPackages()protected javax.xml.bind.MarshallergetMarshaller()abstract java.lang.StringgetNameSpace()Method that should return the main namespace of the packateprotected abstract XMLSigner.OrganisationLookupgetOrganisationLookup()protected abstract XMLSigner.SignatureLocationFindergetSignatureLocationFinder()protected javax.xml.bind.UnmarshallergetUnmarshaller()voidinit(MessageSecurityProvider secProv)Method to initialise the SAML parser using standard XSDs.voidinit(MessageSecurityProvider secProv, SAMLParserCustomisations customisations)Method to initialise the parser using standard XSDs and extra XSD used for extentions.protected abstract java.lang.StringlookupSchemaForElement(java.lang.String type, java.lang.String namespaceURI, java.lang.String publicId, java.lang.String systemId, java.lang.String baseURI)Method to find Schema for a specific element related to the custom schema locations.byte[]marshall(java.lang.Object message)Help method to marshall a message without signing it.byte[]marshallAndSign(ContextMessageSecurityProvider.Context context, java.lang.Object message)Help method to marshall and sign an JAXB data that is supported by the parser implementation.protected byte[]marshallAndSignSAMLPOrAssertion(ContextMessageSecurityProvider.Context context, javax.xml.bind.JAXBElement<?> message, boolean signAssertion, boolean signSAMLP)Help method to marshall and sign an Assertion, either standalone or inside a SAMLP Response Method that generates the signature and marshalls the message to byte array in UTF-8 format.byte[]marshallDoc(org.w3c.dom.Document doc)Help method to marshall a Doc into byte array, generates no signature just converts.java.lang.ObjectparseMessage(ContextMessageSecurityProvider.Context context, byte[] message, boolean requireSignature)Method to parses a generic SAML message and generates a JAXB structure.voidschemaValidate(java.lang.Object message)Method to validate a JAXB Object against Schema.protected java.lang.Objectunmarshall(byte[] message)org.w3c.dom.DocumentunmarshallDoc(byte[] message)Method to convert a message to a DocumentvoidverifyAssertionConditions(AssertionType assertionType, BaseSAMLMessageParser.ConditionLookup conditionLookup)Method that verifies the notBefore and notOnOrAfter conditions, all other conditions set in an assertion is ignored.voidverifyConditions(ConditionsType conditions, java.lang.String type, java.lang.String messageId, BaseSAMLMessageParser.ConditionLookup conditionLookup)
-
-
-
Field Detail
-
SETTING_CUSTOM_JAXBCLASSPATH
public static java.lang.String SETTING_CUSTOM_JAXBCLASSPATH
A ':' separated string containing package paths to JAXB libraries used with extensions to the parser.
-
SETTING_CUSTOM_SCHEMALOCATIONS
public static java.lang.String SETTING_CUSTOM_SCHEMALOCATIONS
A ':' separated string containing the resource path to custom schemas used during validation. Each path should be found using the getResourceAsStream method, so the schema might be placed inside a Jar on the classpath.
-
ASSERTION_NAMESPACE
public static java.lang.String ASSERTION_NAMESPACE
-
PROTOCOL_NAMESPACE
public static java.lang.String PROTOCOL_NAMESPACE
-
DEFAULT_SAML_VERSION
public static java.lang.String DEFAULT_SAML_VERSION
-
ASSERTION_XSD_SCHEMA_2_0_RESOURCE_LOCATION
public static final java.lang.String ASSERTION_XSD_SCHEMA_2_0_RESOURCE_LOCATION
- See Also:
- Constant Field Values
-
SAMLP_XSD_SCHEMA_2_0_RESOURCE_LOCATION
public static final java.lang.String SAMLP_XSD_SCHEMA_2_0_RESOURCE_LOCATION
- See Also:
- Constant Field Values
-
customJAXBClasspath
protected java.lang.String customJAXBClasspath
-
customSchemaLocations
protected java.lang.String[] customSchemaLocations
-
of
protected ObjectFactory of
-
samlpOf
protected ObjectFactory samlpOf
-
dsigOf
protected ObjectFactory dsigOf
-
systemTime
protected SystemTime systemTime
-
xmlEncrypter
protected XMLEncrypter xmlEncrypter
-
xmlSigner
protected XMLSigner xmlSigner
-
cf
protected java.security.cert.CertificateFactory cf
-
customisations
protected SAMLParserCustomisations customisations
-
messageSecurityProvider
protected MessageSecurityProvider messageSecurityProvider
-
schemaValidator
protected javax.xml.validation.Validator schemaValidator
-
assertionSignatureLocationFinder
protected BaseSAMLMessageParser.AssertionSignatureLocationFinder assertionSignatureLocationFinder
-
samlpSignatureLocationFinder
protected BaseSAMLMessageParser.SAMLPSignatureLocationFinder samlpSignatureLocationFinder
-
-
Method Detail
-
init
public void init(MessageSecurityProvider secProv) throws MessageProcessingException
Method to initialise the SAML parser using standard XSDs.- Parameters:
secProv- Message Security Provider to use.- Throws:
MessageProcessingException- if internal problems occurred setting up the SAMLMessageParser.
-
init
public void init(MessageSecurityProvider secProv, SAMLParserCustomisations customisations) throws MessageProcessingException
Method to initialise the parser using standard XSDs and extra XSD used for extentions.- Parameters:
secProv- Message Security Provider to use. If context is not default must a ContextMessageSecurityProvider be specified.customisations- implementation to specify non-SAML core JAXB extensions.- Throws:
MessageProcessingException- if internal problems occurred setting up the SAMLMessageParser.
-
getNameSpace
public abstract java.lang.String getNameSpace()
Method that should return the main namespace of the packate
-
getJAXBPackages
protected abstract java.lang.String getJAXBPackages()
- Returns:
- all related JAXBPackages.
-
getDefaultSchemaLocations
protected abstract java.lang.String[] getDefaultSchemaLocations() throws org.xml.sax.SAXException- Returns:
- an array of schema locations used by the parser. The string value should point to resources available using getResourceAsStream()
- Throws:
org.xml.sax.SAXException
-
getSignatureLocationFinder
protected abstract XMLSigner.SignatureLocationFinder getSignatureLocationFinder()
- Returns:
- returns the implementation locating the signature element of a specific message.
-
getOrganisationLookup
protected abstract XMLSigner.OrganisationLookup getOrganisationLookup()
- Returns:
- the implementation to lookup related organisation in a specific message.
-
lookupSchemaForElement
protected abstract java.lang.String lookupSchemaForElement(java.lang.String type, java.lang.String namespaceURI, java.lang.String publicId, java.lang.String systemId, java.lang.String baseURI)Method to find Schema for a specific element related to the custom schema locations. The implementation only need to find it's related XSD, the basic datatypes and XML itself are not needed.- Parameters:
type- The type of the resource being resolved. For XML [XML 1.0] resources (i.e. entities), applications must use the value "http://www.w3.org/TR/REC-xml". For XML Schema [XML Schema Part 1], applications must use the value "http://www.w3.org/2001/XMLSchema". Other types of resources are outside the scope of this specification and therefore should recommend an absolute URI in order to use this method.namespaceURI- The namespace of the resource being resolved, e.g. the target namespace of the XML Schema [XML Schema Part 1] when resolving XML Schema resources.publicId- The public identifier of the external entity being referenced, or null if no public identifier was supplied or if the resource is not an entity.systemId- The system identifier, a URI reference [IETF RFC 2396], of the external resource being referenced, or null if no system identifier was supplied.baseURI- The absolute base URI of the resource being parsed, or null if there is no base URI.- Returns:
- the resource as stream path to related schema XSD, or null if no matching found.
-
generateSchema
public javax.xml.validation.Schema generateSchema() throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
schemaValidate
public void schemaValidate(java.lang.Object message) throws MessageContentExceptionMethod to validate a JAXB Object against Schema.- Throws:
MessageContentException
-
parseMessage
public java.lang.Object parseMessage(ContextMessageSecurityProvider.Context context, byte[] message, boolean requireSignature) throws MessageContentException, MessageProcessingException
Method to parses a generic SAML message and generates a JAXB structure.- Parameters:
message- the message data.requireSignature- indicates if signature should exist and be valid.- Returns:
- a parsed SAML message..
- Throws:
MessageContentException- if response message data was invalid.MessageProcessingException- if internal problems occurred generated the message.
-
genFailureMessage
public byte[] genFailureMessage(ContextMessageSecurityProvider.Context context, java.lang.String inResponseTo, ResponseStatusCodes statusCode, java.lang.String failureMessage) throws MessageContentException, MessageProcessingException
Method to generate a general SAMLP failure message.- Parameters:
context- message security related context.inResponseTo- the ID of the attribute querystatusCode- the failure code to respond tofailureMessage- a descriptive failure message, may be null.- Returns:
- a SAMLP failure message.
- Throws:
MessageContentException- if parameters where invalid.MessageProcessingException- if internal problems occurred generated the message.
-
genFailureMessage
public byte[] genFailureMessage(ContextMessageSecurityProvider.Context context, java.lang.String inResponseTo, NameIDType issuer, java.lang.String destination, java.lang.String consent, ExtensionsType extensions, ResponseStatusCodes statusCode, java.lang.String failureMessage, boolean signSAMLPResponse) throws MessageContentException, MessageProcessingException
Method to generate a general SAMLP failure message.- Parameters:
context- message security related context.inResponseTo- the ID of the request, null if message was unreadableissuer- Identifies the entity that generated the response message. (Optional, null for no issuer)destination- A URI reference indicating the address to which this response has been sent. This is useful to prevent malicious forwarding of responses to unintended recipients, a protection that is required by some protocol bindings. If it is present, the actual recipient MUST check that the URI reference identifies the location at which the message was received. If it does not, the response MUST be discarded. Some protocol bindings may require the use of this attribute. (Optional, null for no destination)consent- Indicates whether or not (and under what conditions) consent has been obtained from a principal in the sending of this response. See Section 8.4 for some URI references that MAY be used as the value of the Consent attribute and their associated descriptions. If no Consent value is provided, the identifier urn:oasis:names:tc:SAML:2.0:consent:unspecified (see Section 8.4.1) is in effect.extensions- This extension point contains optional protocol message extension elements that are agreed on between the communicating parties. . No extension schema is required in order to make use of this extension point, and even if one is provided, the lax validation setting does not impose a requirement for the extension to be valid. SAML extension elements MUST be namespace-qualified in a non-SAML-defined namespace. (Optional, null for no extensions)statusCode- the failure code to respond to (Required)failureMessage- a descriptive failure message, may be null.signSAMLPResponse- if the response should be signed.- Returns:
- a SAMLP failure message.
- Throws:
MessageContentException- if parameters where invalid.MessageProcessingException- if internal problems occurred generated the message.
-
getCertificateFromAssertion
public java.security.cert.X509Certificate getCertificateFromAssertion(javax.xml.bind.JAXBElement<AssertionType> assertion) throws MessageContentException, MessageProcessingException
Help method to get the first signing certificate from a digital signature.- Parameters:
assertion- to extract certificate from.- Returns:
- the first found certificate in assertion.
- Throws:
MessageContentException- if response message data was invalid.MessageProcessingException- if internal problems occurred generated the message.
-
getAssertionFromResponseType
public javax.xml.bind.JAXBElement<AssertionType> getAssertionFromResponseType(ResponseType responseType)
Help method to extract a Assertion to be included in a CSMessasge from a response type- Parameters:
responseType- the response type to extract from, never null.- Returns:
- the first assertion type of null if no assertion was found.
-
decryptAssertion
public javax.xml.bind.JAXBElement<AssertionType> decryptAssertion(ContextMessageSecurityProvider.Context context, javax.xml.bind.JAXBElement<AssertionType> assertion) throws MessageContentException, MessageProcessingException, NoDecryptionKeyFoundException
Method to decrypt an assertion containing encrypted attributes.- Parameters:
context- message security related context.assertion- the assertion to decrypt and parse- Returns:
- an decrypted assertion
- Throws:
MessageContentException- if content of message was invalid.MessageProcessingException- if internal problems occurred parsing the assertions.NoDecryptionKeyFoundException- if no key could be found decrypting the assertion.
-
verifyAssertionConditions
public void verifyAssertionConditions(AssertionType assertionType, BaseSAMLMessageParser.ConditionLookup conditionLookup) throws MessageContentException
Method that verifies the notBefore and notOnOrAfter conditions, all other conditions set in an assertion is ignored.- Parameters:
assertionType- the assertion to verifyconditionLookup- implementation to check a specific set of conditions.- Throws:
MessageContentException- if conditions wasn't met.
-
verifyConditions
public void verifyConditions(ConditionsType conditions, java.lang.String type, java.lang.String messageId, BaseSAMLMessageParser.ConditionLookup conditionLookup) throws MessageContentException
- Throws:
MessageContentException
-
genSuccessfulSAMLPResponse
public javax.xml.bind.JAXBElement<ResponseType> genSuccessfulSAMLPResponse(java.lang.String inResponseTo, javax.xml.bind.JAXBElement<AssertionType> assertion) throws MessageProcessingException
Generates a simple basic SAMLP response containing one unencrypted assertion.- Parameters:
inResponseTo- the request id.assertion- the unencrypted assertion to add to teh response.- Returns:
- a successful SAMLPResponse.
- Throws:
MessageProcessingException- if internal problems occurred generating the message.
-
getJAXBContext
protected javax.xml.bind.JAXBContext getJAXBContext() throws javax.xml.bind.JAXBExceptionHelp method maintaining the JAXB Context.- Throws:
javax.xml.bind.JAXBException
-
marshall
public byte[] marshall(java.lang.Object message) throws MessageProcessingExceptionHelp method to marshall a message without signing it.- Parameters:
message- the message to marshall into a XML byte array.- Returns:
- the marshalled byte array
- Throws:
MessageProcessingException- if problem occurred marshalling the message.
-
unmarshall
protected java.lang.Object unmarshall(byte[] message) throws MessageProcessingException, MessageContentException
-
marshallAndSign
public byte[] marshallAndSign(ContextMessageSecurityProvider.Context context, java.lang.Object message) throws MessageProcessingException, MessageContentException
Help method to marshall and sign an JAXB data that is supported by the parser implementation. Method that generates the signature and marshalls the message to byte array in UTF-8 format.- Parameters:
message- to sign and marshall.- Returns:
- a marshalled and signed message.
- Throws:
MessageProcessingException- if problems occurred when processing the message.MessageContentException- if unsupported version is detected in message.
-
marshallDoc
public byte[] marshallDoc(org.w3c.dom.Document doc) throws MessageProcessingException, MessageContentExceptionHelp method to marshall a Doc into byte array, generates no signature just converts.- Parameters:
doc- Document to marshall into byte array- Returns:
- a byte array representation of the doc
- Throws:
MessageProcessingException- if internal problems occurred when processing the message.MessageContentException- if message was malformed.
-
unmarshallDoc
public org.w3c.dom.Document unmarshallDoc(byte[] message) throws MessageContentException, MessageProcessingExceptionMethod to convert a message to a Document- Parameters:
message- the bytearray xml message to convert to Document.- Returns:
- the Document object.
- Throws:
MessageContentException- if message was malformed.MessageProcessingException
-
marshallAndSignSAMLPOrAssertion
protected byte[] marshallAndSignSAMLPOrAssertion(ContextMessageSecurityProvider.Context context, javax.xml.bind.JAXBElement<?> message, boolean signAssertion, boolean signSAMLP) throws MessageProcessingException, MessageContentException
Help method to marshall and sign an Assertion, either standalone or inside a SAMLP Response Method that generates the signature and marshalls the message to byte array in UTF-8 format.- Parameters:
context- the message security context to use.message- a Assertion or Response (SAMLP) structure.- Returns:
- a marshalled and signed message.
- Throws:
MessageProcessingException- if problems occurred when processing the message.MessageContentException- if unsupported version is detected in message.
-
getDocumentBuilder
protected javax.xml.parsers.DocumentBuilder getDocumentBuilder() throws MessageProcessingException- Throws:
MessageProcessingException
-
getMarshaller
protected javax.xml.bind.Marshaller getMarshaller() throws javax.xml.bind.JAXBException- Throws:
javax.xml.bind.JAXBException
-
getUnmarshaller
protected javax.xml.bind.Unmarshaller getUnmarshaller() throws javax.xml.bind.JAXBException, org.xml.sax.SAXException- Throws:
javax.xml.bind.JAXBExceptionorg.xml.sax.SAXException
-
-