Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/extend ig test infrastructure #590

Merged
merged 4 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
package gov.nist.toolkit.registrymsg.common;

import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;

import java.util.HashMap;
import java.util.List;

public class RequestHeader {
// String home;
// String queryId;
// OMElement adhocQueryElement;
// OMElement adhocQueryRequestElement;
// OMAttribute homeAtt;
// String patientId = null;
// List<String> documentEntryObjectTypeList = null;
OMElement omElement;
HashMap<String, OMElement> attributeStatement = new HashMap<>();
String samlAssertionID = null;
String samlAssertionIssueInstant = null;
String samlAssertionVersion = null;
String samlAssertionIssuer = null;
String samlCanonicalizationMethodAlgorithm = null;
String samlSignatureMethodAlgorithm = null;
String samlDigestMethodAlgorithm = null;
String samlDigestValue = null;
String samlSignatureValue = null;
String samlX509Certificate = null;
String samlRSAKyValueModulus = null;
String samlRSAKeyValueExponent = null;
String samlNHINHomeCommunityID = null;
String samlIHEHomeCommunityID = null;
String samlPurposeOfUseCode = null;
String samlPurposeOfUseCodeSystem = null;
String samlPurposeOfUseCSP = null;
String samlPurposeOfUseValidatedAttributes = null;


/*
public String getHome() {
return home;
}
public String getQueryId() {
return queryId;
}
public OMElement getAdhocQueryElement() {
return adhocQueryElement;
}
public OMElement getRequestHeaderElement() {
return adhocQueryRequestElement;
}
public OMAttribute getHomeAtt() {
return homeAtt;
}
public String getPatientId() { return patientId; }

public OMElement getAttributeStatementAttribute(String name) {
OMElement e = attributeStatement.get(name);
return e;
}

public void setAttributeStatement(HashMap<String, OMElement> attributeStatement) {
this.attributeStatement = attributeStatement;
}

public List<String> getDocumentEntryObjectTypeList() {
return documentEntryObjectTypeList;
}

*/
public OMElement getAttributeStatementAttribute(String name) {
OMElement e = attributeStatement.get(name);
return e;
}

public OMElement getOmElement() {
return omElement;
}

public void setOmElement(OMElement omElement) {
this.omElement = omElement;
}

public HashMap<String, OMElement> getAttributeStatement() {
return attributeStatement;
}

public String getSamlAssertionID() {
return samlAssertionID;
}

public void setSamlAssertionID(String samlAssertionID) {
this.samlAssertionID = samlAssertionID;
}

public String getSamlAssertionIssueInstant() {
return samlAssertionIssueInstant;
}

public void setSamlAssertionIssueInstant(String samlAssertionIssueInstant) {
this.samlAssertionIssueInstant = samlAssertionIssueInstant;
}

public String getSamlAssertionVersion() {
return samlAssertionVersion;
}

public void setSamlAssertionVersion(String samlAssertionVersion) {
this.samlAssertionVersion = samlAssertionVersion;
}

public String getSamlAssertionIssuer() {
return samlAssertionIssuer;
}

public void setSamlAssertionIssuer(String samlAssertionIssuer) {
this.samlAssertionIssuer = samlAssertionIssuer;
}

public String getSamlCanonicalizationMethodAlgorithm() {
return samlCanonicalizationMethodAlgorithm;
}

public void setSamlCanonicalizationMethodAlgorithm(String samlCanonicalizationMethodAlgorithm) {
this.samlCanonicalizationMethodAlgorithm = samlCanonicalizationMethodAlgorithm;
}

public String getSamlSignatureMethodAlgorithm() {
return samlSignatureMethodAlgorithm;
}

public void setSamlSignatureMethodAlgorithm(String samlSignatureMethodAlgorithm) {
this.samlSignatureMethodAlgorithm = samlSignatureMethodAlgorithm;
}

public String getSamlDigestMethodAlgorithm() {
return samlDigestMethodAlgorithm;
}

public void setSamlDigestMethodAlgorithm(String samlDigestMethodAlgorithm) {
this.samlDigestMethodAlgorithm = samlDigestMethodAlgorithm;
}

public String getSamlDigestValue() {
return samlDigestValue;
}

public void setSamlDigestValue(String samlDigestValue) {
this.samlDigestValue = samlDigestValue;
}

public String getSamlSignatureValue() {
return samlSignatureValue;
}

public void setSamlSignatureValue(String samlSignatureValue) {
this.samlSignatureValue = samlSignatureValue;
}

public String getSamlX509Certificate() {
return samlX509Certificate;
}

public void setSamlX509Certificate(String samlX509Certificate) {
this.samlX509Certificate = samlX509Certificate;
}

public String getSamlRSAKyValueModulus() {
return samlRSAKyValueModulus;
}

public void setSamlRSAKyValueModulus(String samlRSAKyValueModulus) {
this.samlRSAKyValueModulus = samlRSAKyValueModulus;
}

public String getSamlRSAKeyValueExponent() {
return samlRSAKeyValueExponent;
}

public void setSamlRSAKeyValueExponent(String samlRSAKeyValueExponent) {
this.samlRSAKeyValueExponent = samlRSAKeyValueExponent;
}

public String getSamlNHINHomeCommunityID() {
return samlNHINHomeCommunityID;
}

public void setSamlNHINHomeCommunityID(String samlNHINHomeCommunityID) {
this.samlNHINHomeCommunityID = samlNHINHomeCommunityID;
}

public String getSamlIHEHomeCommunityID() {
return samlIHEHomeCommunityID;
}

public void setSamlIHEHomeCommunityID(String samlIHEHomeCommunityID) {
this.samlIHEHomeCommunityID = samlIHEHomeCommunityID;
}

public String getSamlPurposeOfUseCode() {
return samlPurposeOfUseCode;
}

public void setSamlPurposeOfUseCode(String samlPurposeOfUseCode) {
this.samlPurposeOfUseCode = samlPurposeOfUseCode;
}

public String getSamlPurposeOfUseCodeSystem() {
return samlPurposeOfUseCodeSystem;
}

public void setSamlPurposeOfUseCodeSystem(String samlPurposeOfUseCodeSystem) {
this.samlPurposeOfUseCodeSystem = samlPurposeOfUseCodeSystem;
}

public String getSamlPurposeOfUseCSP() {
return samlPurposeOfUseCSP;
}

public void setSamlPurposeOfUseCSP(String samlPurposeOfUseCSP) {
this.samlPurposeOfUseCSP = samlPurposeOfUseCSP;
}

public String getSamlPurposeOfUseValidatedAttributes() {
return samlPurposeOfUseValidatedAttributes;
}

public void setSamlPurposeOfUseValidatedAttributes(String samlPurposeOfUseValidatedAttributes) {
this.samlPurposeOfUseValidatedAttributes = samlPurposeOfUseValidatedAttributes;
}

public String getAttributeValue(String name) {
String rtn = null;
OMElement e = attributeStatement.get(name);
if (e != null) {
OMElement child = e.getFirstElement();
if (child != null) {
rtn = child.getText();
}
}
return rtn;
}

public String toString() {
return "RequestHeader: ";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package gov.nist.toolkit.registrymsg.common;

import gov.nist.toolkit.commondatatypes.MetadataSupport;
import gov.nist.toolkit.utilities.xml.XmlUtil;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.xpath.AXIOMXPath;

import javax.xml.namespace.QName;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class RequestHeaderParser {
OMElement ele;
RequestHeader header = new RequestHeader();


public RequestHeaderParser(OMElement ele) {
this.ele = ele;
}

public RequestHeader getRequestHeader() throws Exception {
parse();
return header;
}

public void parse() throws Exception {
String zz = ele.getLocalName();
if (!ele.getLocalName().equals("Header")) {
// Something is wrong
return;
}

AXIOMXPath xpathExpression = new AXIOMXPath ("//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='AttributeStatement']");
Object o = xpathExpression.selectSingleNode(ele);
if (o == null) return;
OMElement omEle = (OMElement) o;
Iterator<OMElement> iterator = omEle.getChildElements();
HashMap<String, OMElement> attributeListMap = new HashMap<>();
while (iterator.hasNext()) {
OMElement x = iterator.next();
String name = x.getAttributeValue(new QName("Name"));
attributeListMap.put(name, x.cloneOMElement());
}

header.omElement = omEle;
header.attributeStatement = attributeListMap;

header.samlAssertionID = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']", "ID");
header.samlAssertionIssueInstant = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']", "IssueInstant");
header.samlAssertionVersion = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']", "Version");
header.samlAssertionIssuer = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Issuer']");
header.samlCanonicalizationMethodAlgorithm = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='SignedInfo']/*[local-name()='CanonicalizationMethod']", "Algorithm");
header.samlSignatureMethodAlgorithm = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='SignedInfo']/*[local-name()='SignatureMethod']", "Algorithm");
header.samlDigestMethodAlgorithm = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='SignedInfo']/*[local-name()='Reference']/*[local-name()='DigestMethod']", "Algorithm");
header.samlDigestValue = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='SignedInfo']/*[local-name()='Reference']/*[local-name()='DigestValue']");
header.samlSignatureValue = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='SignatureValue']");
header.samlX509Certificate = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='KeyInfo']/*[local-name()='X509Data']/*[local-name()='X509Certificate']");
header.samlRSAKyValueModulus = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='KeyInfo']/*[local-name()='KeyValue']/*[local-name()='RSAKeyValue']/*[local-name()='Modulus']");
header.samlRSAKeyValueExponent = evaluateXPath(ele, "//*[local-name()='Security']/*[local-name()='Assertion']/*[local-name()='Signature']/*[local-name()='KeyInfo']/*[local-name()='KeyValue']/*[local-name()='RSAKeyValue']/*[local-name()='Exponent']");

header.samlNHINHomeCommunityID = header.getAttributeValue("urn:nhin:names:saml:homeCommunityId");
header.samlIHEHomeCommunityID = header.getAttributeValue("urn:ihe:iti:xca:2010:homeCommunityId");
header.samlPurposeOfUseCSP = header.getAttributeValue("csp");
header.samlPurposeOfUseValidatedAttributes = header.getAttributeValue("validated_attributes");




System.out.println("SAML Assertion ID: " + header.samlAssertionID);
}

String evaluateXPath(OMElement ele, String expression) throws Exception {
AXIOMXPath xpathExpression = new AXIOMXPath (expression);
Object o = xpathExpression.selectSingleNode(ele);
if (o == null) return null;

OMElement omEle = (OMElement) o;
String rtn = omEle.getText();
return rtn;
}

String evaluateXPath(OMElement ele, String expression, String attribute) throws Exception {
try {
AXIOMXPath xpathExpression = new AXIOMXPath(expression);
Object o = xpathExpression.selectSingleNode(ele);
if (o == null) return null;

OMElement omEle = (OMElement) o;
String rtn = null;
rtn = omEle.getAttributeValue(new QName(attribute));

return rtn;
} catch (Exception e) {
String z = e.toString();
throw e;
}
}

List<String> parseValueList(OMElement e, String xpath) throws Exception {
ArrayList<String> rtn = new ArrayList<>();

AXIOMXPath xpathExpression = new AXIOMXPath (xpath);
List<Object> objectList = xpathExpression.selectNodes(ele);
if (objectList != null) {
for (Object o: objectList) {
OMElement omEle = (OMElement) o;
String text = omEle.getText();
rtn.add(text);
}
}
return rtn;
}
}
Loading