/** * Gets the SAMLVersion for a given version string, such as "2.0". * * @param version SAML version string * * @return SAMLVersion for the given string */ public static final SAMLVersion valueOf(@Nonnull final String version) { String[] components = version.split("\\."); return valueOf(Integer.valueOf(components[0]), Integer.valueOf(components[1])); }
/** * Gets the SAMLVersion given the major and minor version number. * * @param majorVersion major version number * @param minorVersion minor version number * * @return the SAMLVersion */ public static final SAMLVersion valueOf(final int majorVersion, final int minorVersion) { if (majorVersion == 1) { if (minorVersion == 0) { return SAMLVersion.VERSION_10; } else if (minorVersion == 1) { return SAMLVersion.VERSION_11; } } else if (majorVersion == 2) { if (minorVersion == 0) { return SAMLVersion.VERSION_20; } } return new SAMLVersion(majorVersion, minorVersion); }
/** {@inheritDoc} */ public int getMajorVersion(){ return version.getMajorVersion(); }
if (WSSConstants.NS_SAML11_TOKEN_PROFILE_TYPE.equals(content) && samlVersion != SAMLVersion.VERSION_11) { return "Policy enforces SAML V1.1 token but got " + samlVersion.toString(); } else if (WSSConstants.NS_SAML20_TOKEN_PROFILE_TYPE.equals(content) && samlVersion != SAMLVersion.VERSION_20) { return "Policy enforces SAML V2.0 token but got " + samlVersion.toString();
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException { RequestAbstractType request = (RequestAbstractType) samlElement; if (request.getID() != null) { domElement.setAttributeNS(null, RequestAbstractType.ID_ATTRIB_NAME, request.getID()); if (request.getVersion() != SAMLVersion.VERSION_10) { domElement.setIdAttributeNS(null, RequestAbstractType.ID_ATTRIB_NAME, true); } } if (request.getIssueInstant() != null) { String date = SAMLConfigurationSupport.getSAMLDateFormatter().print(request.getIssueInstant()); domElement.setAttributeNS(null, RequestAbstractType.ISSUEINSTANT_ATTRIB_NAME, date); } domElement.setAttributeNS(null, RequestAbstractType.MAJORVERSION_ATTRIB_NAME, Integer.toString(request.getVersion().getMajorVersion())); domElement.setAttributeNS(null, RequestAbstractType.MINORVERSION_ATTRIB_NAME, Integer.toString(request.getVersion().getMinorVersion())); } }
/** {@inheritDoc} */ public int getMinorVersion() { return version.getMinorVersion(); }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { Assertion assertion = (Assertion) samlObject; if (assertion.getVersion() != null) { domElement.setAttributeNS(null, Assertion.VERSION_ATTRIB_NAME, assertion.getVersion().toString()); } if (assertion.getIssueInstant() != null) { String issueInstantStr = SAMLConfigurationSupport.getSAMLDateFormatter().print(assertion.getIssueInstant()); domElement.setAttributeNS(null, Assertion.ISSUE_INSTANT_ATTRIB_NAME, issueInstantStr); } if (assertion.getID() != null) { domElement.setAttributeNS(null, Assertion.ID_ATTRIB_NAME, assertion.getID()); domElement.setIdAttributeNS(null, Assertion.ID_ATTRIB_NAME, true); } } }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException { ResponseAbstractType response = (ResponseAbstractType) samlElement; if (response.getID() != null) { domElement.setAttributeNS(null, ResponseAbstractType.ID_ATTRIB_NAME, response.getID()); if (response.getVersion() != SAMLVersion.VERSION_10) { domElement.setIdAttributeNS(null, ResponseAbstractType.ID_ATTRIB_NAME, true); } } if (response.getInResponseTo() != null) { domElement.setAttributeNS(null, ResponseAbstractType.INRESPONSETO_ATTRIB_NAME, response.getInResponseTo()); } if (response.getIssueInstant() != null) { String date = SAMLConfigurationSupport.getSAMLDateFormatter().print(response.getIssueInstant()); domElement.setAttributeNS(null, ResponseAbstractType.ISSUEINSTANT_ATTRIB_NAME, date); } domElement.setAttributeNS(null, RequestAbstractType.MAJORVERSION_ATTRIB_NAME, Integer.toString(response.getVersion().getMajorVersion())); domElement.setAttributeNS(null, RequestAbstractType.MINORVERSION_ATTRIB_NAME, Integer.toString(response.getVersion().getMinorVersion())); if (response.getRecipient() != null) { domElement.setAttributeNS(null, ResponseAbstractType.RECIPIENT_ATTRIB_NAME, response.getRecipient()); } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { Assertion assertion = (Assertion) samlObject; if (attribute.getLocalName().equals(Assertion.VERSION_ATTRIB_NAME)) { assertion.setVersion(SAMLVersion.valueOf(attribute.getValue())); } else if (attribute.getLocalName().equals(Assertion.ISSUE_INSTANT_ATTRIB_NAME) && !Strings.isNullOrEmpty(attribute.getValue())) { assertion.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC())); } else if (attribute.getLocalName().equals(Assertion.ID_ATTRIB_NAME)) { assertion.setID(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else { super.processAttribute(samlObject, attribute); } } }
if (version.getMajorVersion() != 1) { throw new MessageHandlerException("Request major version was invalid"); if (version.getMajorVersion() != 1) { throw new MessageHandlerException("Request major version was invalid"); if (version.getMajorVersion() != 2) { throw new MessageHandlerException("Response major version was invalid"); if (version.getMajorVersion() != 2) { throw new MessageHandlerException("Response major version was invalid");
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { RequestAbstractType req = (RequestAbstractType) samlObject; if (attribute.getLocalName().equals(RequestAbstractType.VERSION_ATTRIB_NAME)) { req.setVersion(SAMLVersion.valueOf(attribute.getValue())); } else if (attribute.getLocalName().equals(RequestAbstractType.ID_ATTRIB_NAME)) { req.setID(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else if (attribute.getLocalName().equals(RequestAbstractType.ISSUE_INSTANT_ATTRIB_NAME) && !Strings.isNullOrEmpty(attribute.getValue())) { req.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC())); } else if (attribute.getLocalName().equals(RequestAbstractType.DESTINATION_ATTRIB_NAME)) { req.setDestination(attribute.getValue()); } else if (attribute.getLocalName().equals(RequestAbstractType.CONSENT_ATTRIB_NAME)) { req.setConsent(attribute.getValue()); } else { super.processAttribute(samlObject, attribute); } }
.setIssueInstant(parsed.getIssueInstant()) .setIssuer(getIssuer(parsed.getIssuer())) .setVersion(parsed.getVersion().toString()) .setStatus(getStatus(parsed.getStatus())) .setAssertions(
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { StatusResponseType sr = (StatusResponseType) samlObject; if (attribute.getLocalName().equals(StatusResponseType.VERSION_ATTRIB_NAME)) { sr.setVersion(SAMLVersion.valueOf(attribute.getValue())); } else if (attribute.getLocalName().equals(StatusResponseType.ID_ATTRIB_NAME)) { sr.setID(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else if (attribute.getLocalName().equals(StatusResponseType.IN_RESPONSE_TO_ATTRIB_NAME)) { sr.setInResponseTo(attribute.getValue()); } else if (attribute.getLocalName().equals(StatusResponseType.ISSUE_INSTANT_ATTRIB_NAME) && !Strings.isNullOrEmpty(attribute.getValue())) { sr.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC())); } else if (attribute.getLocalName().equals(StatusResponseType.DESTINATION_ATTRIB_NAME)) { sr.setDestination(attribute.getValue()); } else if (attribute.getLocalName().equals(StatusResponseType.CONSENT_ATTRIB_NAME)) { sr.setConsent(attribute.getValue()); } else { super.processAttribute(samlObject, attribute); } }
protected LogoutResponse resolveLogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse response, List<SimpleKey> verificationKeys, List<SimpleKey> localKeys) { LogoutResponse result = new LogoutResponse() .setId(response.getID()) .setInResponseTo(response.getInResponseTo()) .setConsent(response.getConsent()) .setVersion(response.getVersion().toString()) .setIssueInstant(response.getIssueInstant()) .setIssuer(getIssuer(response.getIssuer())) .setDestination(response.getDestination()) .setStatus(getStatus(response.getStatus())); return result; }
.setId(request.getID()) .setIssueInstant(request.getIssueInstant()) .setVersion(request.getVersion().toString()) .setRequestedAuthenticationContext(getRequestedAuthenticationContext(request)) .setAuthenticationContextClassReference(getAuthenticationContextClassReference(request))
protected LogoutRequest resolveLogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest request, List<SimpleKey> verificationKeys, List<SimpleKey> localKeys) { LogoutRequest result = new LogoutRequest() .setId(request.getID()) .setConsent(request.getConsent()) .setVersion(request.getVersion().toString()) .setNotOnOrAfter(request.getNotOnOrAfter()) .setIssueInstant(request.getIssueInstant()) .setReason(LogoutReason.fromUrn(request.getReason())) .setIssuer(getIssuer(request.getIssuer())) .setDestination(new Endpoint().setLocation(request.getDestination())); NameID nameID = getNameID(request.getNameID(), request.getEncryptedID(), localKeys); result.setNameId(getNameIdPrincipal(nameID)); return result; }
protected Assertion resolveAssertion( org.opensaml.saml.saml2.core.Assertion parsed, List<SimpleKey> verificationKeys, List<SimpleKey> localKeys ) { Signature signature = validateSignature(parsed, verificationKeys); return new Assertion() .setSignature(signature) .setId(parsed.getID()) .setIssueInstant(parsed.getIssueInstant()) .setVersion(parsed.getVersion().toString()) .setIssuer(getIssuer(parsed.getIssuer())) .setSubject(getSubject(parsed.getSubject(), localKeys)) .setConditions(getConditions(parsed.getConditions())) .setAuthenticationStatements(getAuthenticationStatements(parsed.getAuthnStatements())) .setAttributes(getAttributes(parsed.getAttributeStatements(), localKeys)) ; }