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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations