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 LogoutMessageImpl method extract.
private <T extends SAMLObject> T extract(@NotNull String samlObject, @NotNull Class<T> clazz) throws WSSecurityException, XMLStreamException {
Document responseDoc = StaxUtils.read(new ByteArrayInputStream(samlObject.getBytes(StandardCharsets.UTF_8)));
XMLObject responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
if (clazz.isAssignableFrom(responseXmlObject.getClass())) {
return clazz.cast(responseXmlObject);
}
return null;
}
use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class SecurityAssertionImpl method getPrincipals.
@Override
public Set<Principal> getPrincipals() {
Set<Principal> principals = new HashSet<>();
Principal primary = getPrincipal();
principals.add(primary);
principals.add(new RolePrincipal(primary.getName()));
for (AttributeStatement attributeStatement : getAttributeStatements()) {
for (Attribute attr : attributeStatement.getAttributes()) {
if (StringUtils.containsIgnoreCase(attr.getName(), "role")) {
for (final XMLObject obj : attr.getAttributeValues()) {
principals.add(new RolePrincipal(((XSString) obj).getValue()));
}
}
}
}
return principals;
}
use of org.opensaml.core.xml.XMLObject in project ddf by codice.
the class MetadataConfigurationParser method readEntityDescriptor.
private EntityDescriptor readEntityDescriptor(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.");
}
return (EntityDescriptor) entityXmlObj;
}
Aggregations