OpenSAMLAssertionExtractorImpl implements SAMLExtractorDOM { @Override public final AssertionType extractSAMLAssertion(final Element element) { LOG.debug("Executing Saml2AssertionExtractor.extractSamlAssertion()..."); if (null == element) { return null; } Assertion saml2Assertion = extractSaml2Assertion(element); AssertionType target = initializeAssertion(); if (saml2Assertion != null) { populateIssuer(saml2Assertion, target); populateSubject(saml2Assertion, target); populateAuthenticationStatement(saml2Assertion, target); populateAttributeStatement(saml2Assertion, target); populateAuthzDecisionStatement(saml2Assertion, target); } LOG.debug("end extractSamlAssertion()"); return target; }  @Override final AssertionType extractSAMLAssertion(final Element element);  }
@Test public void testNullAssertionElement() throws Exception { assertNull(openSAMLAssertionExtractorImpl.extractSAMLAssertion(null)); }
@Test public void testCompleteSamlAssertion() throws Exception { AssertionType assertionType = openSAMLAssertionExtractorImpl .extractSAMLAssertion(getElementForSamlFile(getTestFilePath("complete_saml.xml"))); assertNotNull(assertionType); verifyHomeCommunity(assertionType.getHomeCommunity(), "2.16.840.1.113883.3.424", null); verifyIssuer(assertionType.getSamlIssuer()); verifyDecisionStatement(assertionType.getSamlAuthzDecisionStatement()); verifyUser(assertionType.getUserInfo()); verifyAuthnStatement(assertionType.getSamlAuthnStatement()); verifyUniquePatientId(assertionType.getUniquePatientId()); verifyCeType(assertionType.getPurposeOfDisclosureCoded(), "OPERATIONS", "2.16.840.1.113883.3.18.7.1", "nhin-purpose", "Healthcare Operations"); verifySignature(assertionType.getSamlSignature()); verifySubject(assertionType.getSamlSubjectConfirmations()); }
@Test public void testDifferentOrderedAssertion() throws Exception { AssertionType assertionType = openSAMLAssertionExtractorImpl .extractSAMLAssertion(getElementForSamlFile(getTestFilePath("saml_header_diff_order.xml"))); assertNotNull(assertionType); assertEquals("CN=SAML User,OU=SU,O=SAML User,L=Los Angeles,ST=CA,C=US", assertionType.getSamlIssuer() .getIssuer()); assertEquals("urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName", assertionType.getSamlIssuer() .getIssuerFormat()); }
@Test public void evidenceWithoutAssertions() throws Exception { Element element = getElementWitoutEvidenceAssertions(); AssertionType assertionType = openSAMLAssertionExtractorImpl.extractSAMLAssertion(element); SamlAuthzDecisionStatementEvidenceType extractedEvidence = assertionType.getSamlAuthzDecisionStatement() .getEvidence(); assertNotNull(extractedEvidence); assertNull(extractedEvidence.getAssertion()); }
@Test public void testSamlAssertionValuesMissing() throws Exception { AssertionType assertionType = openSAMLAssertionExtractorImpl .extractSAMLAssertion(getElementForSamlFile(getTestFilePath("saml_missingValues.xml"))); assertNotNull(assertionType); verifyHomeCommunity(assertionType.getHomeCommunity(), EMPTY_STRING, null); verifyIssuer(assertionType.getSamlIssuer()); verifyDecisionStatement(assertionType.getSamlAuthzDecisionStatement()); assertEquals(assertionType.getUserInfo().getPersonName().getFamilyName(), EMPTY_STRING); assertEquals(assertionType.getUserInfo().getRoleCoded().getCode(), EMPTY_STRING); verifyAuthnStatement(assertionType.getSamlAuthnStatement()); assertEquals(assertionType.getPurposeOfDisclosureCoded().getCode(), EMPTY_STRING); verifySignature(assertionType.getSamlSignature()); }