Search in sources :

Example 11 with Status

use of org.opensaml.saml.saml2.core.Status in project ddf by codice.

the class AuthnResponseValidator method validate.

public void validate(XMLObject xmlObject) throws ValidationException {
    if (!(xmlObject instanceof Response)) {
        throw new ValidationException("Invalid AuthN response XML.");
    }
    Response authnResponse = (Response) xmlObject;
    String status = authnResponse.getStatus().getStatusCode().getValue();
    if (!StatusCode.SUCCESS.equals(status)) {
        throw new ValidationException("AuthN request was unsuccessful.  Received status: " + status);
    }
    if (authnResponse.getAssertions().size() < 1) {
        throw new ValidationException("Assertion missing in AuthN response.");
    }
    if (authnResponse.getAssertions().size() > 1) {
        LOGGER.info("Received multiple assertions in AuthN response.  Only using the first assertion.");
    }
    if (authnResponse.getSignature() != null) {
        try {
            simpleSign.validateSignature(authnResponse.getSignature(), authnResponse.getDOM().getOwnerDocument());
        } catch (SimpleSign.SignatureException e) {
            throw new ValidationException("Invalid or untrusted signature.");
        }
    }
}
Also used : Response(org.opensaml.saml.saml2.core.Response) SimpleSign(ddf.security.samlp.SimpleSign) ValidationException(ddf.security.samlp.ValidationException)

Aggregations

Response (org.opensaml.saml.saml2.core.Response)4 Status (org.opensaml.saml.saml2.core.Status)4 DateTime (org.joda.time.DateTime)3 StatusCode (org.opensaml.saml.saml2.core.StatusCode)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 LogoutResponse (org.opensaml.saml.saml2.core.LogoutResponse)2 StatusMessage (org.opensaml.saml.saml2.core.StatusMessage)2 SamlProtocol (ddf.security.samlp.SamlProtocol)1 SimpleSign (ddf.security.samlp.SimpleSign)1 ValidationException (ddf.security.samlp.ValidationException)1 EntityInformation (ddf.security.samlp.impl.EntityInformation)1 IOException (java.io.IOException)1 SecureRandom (java.security.SecureRandom)1 ServletResponse (javax.servlet.ServletResponse)1 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)1 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)1 SAMLObject (org.opensaml.saml.common.SAMLObject)1 SignableSAMLObject (org.opensaml.saml.common.SignableSAMLObject)1 Status (org.opensaml.saml.saml1.core.Status)1 StatusCode (org.opensaml.saml.saml1.core.StatusCode)1