Search in sources :

Example 46 with Response

use of org.opensaml.saml2.core.Response in project cloudstack by apache.

the class SAMLUtils method decodeSAMLResponse.

public static Response decodeSAMLResponse(String responseMessage) throws ConfigurationException, ParserConfigurationException, SAXException, IOException, UnmarshallingException {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
    byte[] base64DecodedResponse = Base64.decode(responseMessage);
    Document document = docBuilder.parse(new ByteArrayInputStream(base64DecodedResponse));
    Element element = document.getDocumentElement();
    UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
    Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
    return (Response) unmarshaller.unmarshall(element);
}
Also used : LoginCmdResponse(org.apache.cloudstack.api.response.LoginCmdResponse) Response(org.opensaml.saml2.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) UnmarshallerFactory(org.opensaml.xml.io.UnmarshallerFactory) Document(org.w3c.dom.Document) Unmarshaller(org.opensaml.xml.io.Unmarshaller)

Example 47 with Response

use of org.opensaml.saml2.core.Response in project cas by apereo.

the class SamlResponseAuditPrincipalIdProvider method getPrincipalIdFrom.

@Override
public String getPrincipalIdFrom(final JoinPoint auditTarget, final Authentication authentication, final Object returnValue, final Exception exception) {
    val response = (Response) returnValue;
    if (!response.getAssertions().isEmpty()) {
        val assertion = response.getAssertions().get(0);
        val subject = assertion.getSubject();
        if (subject != null && subject.getNameID() != null) {
            return subject.getNameID().getValue();
        }
    }
    return super.getPrincipalIdFrom(auditTarget, authentication, returnValue, exception);
}
Also used : lombok.val(lombok.val) Response(org.opensaml.saml.saml2.core.Response)

Example 48 with Response

use of org.opensaml.saml2.core.Response in project cas by apereo.

the class SamlResponseAuditResourceResolver method getPrincipalIdFromSamlEcpResponse.

private String[] getPrincipalIdFromSamlEcpResponse(final Envelope envelope) {
    val objects = envelope.getBody().getUnknownXMLObjects();
    if (objects.isEmpty()) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }
    val object = objects.get(0);
    if (object instanceof Response) {
        return getPrincipalIdFromSamlResponse((Response) object);
    }
    if (object instanceof Fault) {
        return getPrincipalIdFromSamlEcpFault((Fault) object);
    }
    return ArrayUtils.EMPTY_STRING_ARRAY;
}
Also used : lombok.val(lombok.val) Response(org.opensaml.saml.saml2.core.Response) Fault(org.opensaml.soap.soap11.Fault)

Example 49 with Response

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

the class SamlProtocol method createResponse.

public static Response createResponse(Issuer issuer, Status status, String requestId, Element samlAssertion) throws WSSecurityException {
    Response response = responseSAMLObjectBuilder.buildObject();
    response.setIssuer(issuer);
    response.setStatus(status);
    response.setID("_" + UUID.randomUUID().toString());
    response.setIssueInstant(new DateTime());
    response.setInResponseTo(requestId);
    response.setVersion(SAMLVersion.VERSION_20);
    if (samlAssertion != null) {
        SamlAssertionWrapper samlAssertionWrapper = new SamlAssertionWrapper(samlAssertion);
        response.getAssertions().add(samlAssertionWrapper.getSaml2());
    }
    return response;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) DateTime(org.joda.time.DateTime)

Example 50 with Response

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

the class SamlAssertionValidatorImpl method createSamlResponse.

/**
 * Creates the SAML response that we use for validation against the CXF code.
 *
 * @param inResponseTo
 * @param issuer
 * @param status
 * @return Response
 */
private static Response createSamlResponse(String inResponseTo, String issuer, Status status) {
    if (responseBuilder == null) {
        responseBuilder = (SAMLObjectBuilder<Response>) builderFactory.getBuilder(Response.DEFAULT_ELEMENT_NAME);
    }
    Response response = responseBuilder.buildObject();
    response.setID(UUID.randomUUID().toString());
    response.setIssueInstant(new DateTime());
    response.setInResponseTo(inResponseTo);
    response.setIssuer(createIssuer(issuer));
    response.setStatus(status);
    response.setVersion(SAMLVersion.VERSION_20);
    return response;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) DateTime(org.joda.time.DateTime)

Aggregations

Response (org.opensaml.saml.saml2.core.Response)245 Test (org.junit.jupiter.api.Test)148 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)84 Assertion (org.opensaml.saml.saml2.core.Assertion)62 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)51 Element (org.w3c.dom.Element)44 Status (org.opensaml.saml.saml2.core.Status)37 DateTime (org.joda.time.DateTime)36 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)31 Document (org.w3c.dom.Document)31 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)26 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)19 SubjectConfirmationDataBean (org.apache.wss4j.common.saml.bean.SubjectConfirmationDataBean)19 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)19 IdpIdaStatus (uk.gov.ida.saml.hub.domain.IdpIdaStatus)18 Authentication (org.springframework.security.core.Authentication)16 ResponseValidatorTestHelper.createStatus (uk.gov.ida.saml.hub.validators.response.helpers.ResponseValidatorTestHelper.createStatus)16 Crypto (org.apache.wss4j.common.crypto.Crypto)15 NameID (org.opensaml.saml.saml2.core.NameID)14 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)13