use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class LogoutMessageImpl method extractRequest.
private LogoutWrapper<LogoutRequest> extractRequest(String samlObject) throws LogoutSecurityException, XMLStreamException {
try {
Document requestDoc = StaxUtils.read(new ByteArrayInputStream(samlObject.getBytes(StandardCharsets.UTF_8)));
XMLObject requestXmlObject = OpenSAMLUtil.fromDom(requestDoc.getDocumentElement());
if (LogoutRequest.class.isAssignableFrom(requestXmlObject.getClass())) {
return new LogoutWrapperImpl<>((LogoutRequest) requestXmlObject);
}
return null;
} catch (WSSecurityException e) {
throw new LogoutSecurityException(e);
}
}
use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class LogoutMessageImpl method signSamlGet.
private URI signSamlGet(LogoutWrapper samlObject, URI target, String relayState, String requestType) throws LogoutSecurityException, SignatureException, IOException {
try {
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
SamlSecurity samlSecurity = new SamlSecurity();
String encodedResponse = URLEncoder.encode(samlSecurity.deflateAndBase64Encode(DOM2Writer.nodeToString(OpenSAMLUtil.toDom((XMLObject) samlObject.getMessage(), doc, false))), "UTF-8");
String requestToSign = String.format("%s=%s&%s=%s", requestType, encodedResponse, SSOConstants.RELAY_STATE, relayState);
UriBuilder uriBuilder = UriBuilder.fromUri(target);
uriBuilder.queryParam(requestType, encodedResponse);
uriBuilder.queryParam(SSOConstants.RELAY_STATE, relayState);
new SimpleSign(systemCrypto).signUriString(requestToSign, uriBuilder);
return uriBuilder.build();
} catch (WSSecurityException e) {
throw new LogoutSecurityException(e);
}
}
use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class MetadataConfigurationParser method readEntityDescriptors.
private List<EntityDescriptor> readEntityDescriptors(Reader reader) {
Document entityDoc;
try {
entityDoc = StaxUtils.read(reader);
} catch (Exception ex) {
throw new IllegalArgumentException("Unable to read SAMLRequest as XML.");
}
XMLObject entityXmlObj;
try {
entityXmlObj = OpenSAMLUtil.fromDom(entityDoc.getDocumentElement());
} catch (WSSecurityException ex) {
throw new IllegalArgumentException("Unable to convert EntityDescriptor document to XMLObject.");
}
if (entityXmlObj instanceof EntitiesDescriptor) {
return ((EntitiesDescriptor) entityXmlObj).getEntityDescriptors();
} else {
return Collections.singletonList((EntityDescriptor) entityXmlObj);
}
}
use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class PaosInInterceptor method checkSamlpResponse.
private void checkSamlpResponse(SOAPPart soapRequest) throws IOException {
XMLObject responseXmlObj = null;
try {
Node node = soapRequest.getEnvelope().getBody().getFirstChild();
responseXmlObj = SamlProtocol.getXmlObjectFromNode(node);
} catch (WSSecurityException | SOAPException | XMLStreamException ex) {
throw new IOException("Unable to convert Response document to XMLObject.");
}
if (responseXmlObj == null) {
throw new IOException("Response object is not Found.");
}
if (!(responseXmlObj instanceof org.opensaml.saml.saml2.core.Response)) {
throw new IOException("SAMLRequest object is not org.opensaml.saml.saml2.core.Response.");
}
}
use of org.opensaml.core.xml.XMLObject in project cas by apereo.
the class WsFederationHelper method createCredentialFromToken.
/**
* createCredentialFromToken converts a SAML 1.1 assertion to a WSFederationCredential.
*
* @param assertion the provided assertion
* @return an equivalent credential.
*/
public WsFederationCredential createCredentialFromToken(final Assertion assertion) {
val retrievedOn = ZonedDateTime.now(clock);
LOGGER.trace("Retrieved on [{}]", retrievedOn);
val credential = new WsFederationCredential();
credential.setRetrievedOn(retrievedOn);
credential.setId(assertion.getID());
credential.setIssuer(assertion.getIssuer());
credential.setIssuedOn(DateTimeUtils.zonedDateTimeOf(assertion.getIssueInstant()));
val conditions = assertion.getConditions();
if (conditions != null) {
credential.setNotBefore(DateTimeUtils.zonedDateTimeOf(conditions.getNotBefore()));
credential.setNotOnOrAfter(DateTimeUtils.zonedDateTimeOf(conditions.getNotOnOrAfter()));
if (!conditions.getAudienceRestrictionConditions().isEmpty()) {
credential.setAudience(conditions.getAudienceRestrictionConditions().get(0).getAudiences().get(0).getURI());
}
}
if (!assertion.getAuthenticationStatements().isEmpty()) {
credential.setAuthenticationMethod(assertion.getAuthenticationStatements().get(0).getAuthenticationMethod());
}
val attributes = new HashMap<String, List<Object>>();
assertion.getAttributeStatements().stream().flatMap(attributeStatement -> attributeStatement.getAttributes().stream()).forEach(item -> {
LOGGER.trace("Processed attribute: [{}]", item.getAttributeName());
final List<Object> itemList = item.getAttributeValues().stream().map(xmlObject -> ((XSAny) xmlObject).getTextContent()).collect(Collectors.toList());
if (!itemList.isEmpty()) {
attributes.put(item.getAttributeName(), itemList);
}
});
credential.setAttributes(attributes);
LOGGER.debug("WsFederation Credential retrieved as: [{}]", credential);
return credential;
}
Aggregations