use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class AssertionConsumerService method extractSamlResponse.
private org.opensaml.saml.saml2.core.Response extractSamlResponse(String samlResponse) {
org.opensaml.saml.saml2.core.Response response = null;
try {
Document responseDoc = StaxUtils.read(new ByteArrayInputStream(samlResponse.getBytes(StandardCharsets.UTF_8)));
XMLObject responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
if (responseXmlObject instanceof org.opensaml.saml.saml2.core.Response) {
response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
}
} catch (XMLStreamException | WSSecurityException e) {
LOGGER.debug("Failed to convert AuthN response string to object.", e);
}
return response;
}
use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class SimpleSignTest method testSignSamlObjectThenModify.
@Test(expected = SimpleSign.SignatureException.class)
public void testSignSamlObjectThenModify() throws Exception {
Document responseDoc = StaxUtils.read(new ByteArrayInputStream(cannedResponse.getBytes()));
XMLObject responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
org.opensaml.saml.saml2.core.Response response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
simpleSign.signSamlObject(response);
Document doc = DOMUtils.createDocument();
Element requestElement = OpenSAMLUtil.toDom(response, doc);
requestElement.setAttribute("oops", "changedit");
String responseMessage = DOM2Writer.nodeToString(requestElement);
responseDoc = StaxUtils.read(new ByteArrayInputStream(responseMessage.getBytes()));
responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
simpleSign.validateSignature(response.getSignature(), response.getDOM().getOwnerDocument());
}
use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class SimpleSignTest method testSignSamlObject.
@Test
public void testSignSamlObject() throws Exception {
Document responseDoc = StaxUtils.read(new ByteArrayInputStream(cannedResponse.getBytes()));
XMLObject responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
org.opensaml.saml.saml2.core.Response response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
simpleSign.signSamlObject(response);
Document doc = DOMUtils.createDocument();
Element requestElement = OpenSAMLUtil.toDom(response, doc);
String responseMessage = DOM2Writer.nodeToString(requestElement);
responseDoc = StaxUtils.read(new ByteArrayInputStream(responseMessage.getBytes()));
responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
simpleSign.validateSignature(response.getSignature(), response.getDOM().getOwnerDocument());
}
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 ddf by codice.
the class AbstractAuthorizingRealm method expandAttributes.
/**
* Takes an {@link org.opensaml.saml.saml2.core.Attribute} and utilizes the
* {@link ddf.security.expansion.Expansion} service to potentially expand it to a
* different/enhanced set of attributes. This expansion is controlled by the configuration of
* the expansion service but relies on the name of this attribute as a key. The returned set of
* Strings represent the possibly expanded set of attributes to be added to the current
* permissions.
*
* @param attribute current attribute whose values are to be potentially expanded
* @return a set of potentially expanded values
*/
private Set<String> expandAttributes(Attribute attribute, Collection<Expansion> expansions) {
Set<String> attributeSet = new HashSet<>();
String attributeName = attribute.getName();
for (XMLObject curValue : attribute.getAttributeValues()) {
if (curValue instanceof XSString) {
attributeSet.add(((XSString) curValue).getValue());
} else {
LOGGER.debug("Unexpected attribute type (non-string) for attribute named {} - ignored", attributeName);
}
}
for (Expansion expansionService : expansions) {
LOGGER.debug("Expanding attributes for {} - original values: {}", attributeName, attributeSet);
attributeSet = expansionService.expand(attributeName, attributeSet);
}
LOGGER.debug("Expanded attributes for {} - values: {}", attributeName, attributeSet);
return attributeSet;
}
Aggregations