HOKSAMLAssertionBuilder extends SAMLAssertionBuilder { @Override public Element build(final CallbackProperties properties, String certificateAlias) { LOG.debug("SamlCallbackHandler.build() -- Start with certificate alias {}", certificateAlias); Element signedAssertion = null; try { final X509Certificate certificate = certificateManager.getCertificateBy(certificateAlias); final PublicKey publicKey = certificateManager.getPublicKeyBy(certificateAlias); final PrivateKey privateKey = certificateManager.getPrivateKeyBy(certificateAlias); Assertion assertion = componentBuilder.createAssertion(); final String aID = createAssertionId(); LOG.debug("Assertion ID: {}", aID); assertion.setID(aID); final DateTime issueInstant = new DateTime(); assertion.setIssueInstant(issueInstant); assertion.setIssuer(createIssuer(properties, certificate)); assertion.setSubject(createSubject(properties, certificate, publicKey)); assertion.setConditions(createConditions(properties)); assertion.getStatements().addAll( createAttributeStatements(properties, createEvidenceSubject(properties, certificate, publicKey))); signedAssertion = sign(properties, assertion, certificate, privateKey, publicKey); } catch (final SAMLComponentBuilderException | CertificateManagerException ex) { LOG.error("Unable to create HOK Assertion: {}", ex.getLocalizedMessage()); throw new SAMLAssertionBuilderException(ex.getLocalizedMessage(), ex); } LOG.debug("SamlCallbackHandler.build() -- End"); return signedAssertion; } HOKSAMLAssertionBuilder();   HOKSAMLAssertionBuilder(final CertificateManager certificateManager); @Override Element build(final CallbackProperties properties, String certificateAlias); List<Statement> createAttributeStatements(final CallbackProperties properties, final Subject subject); void addOptionalStatement(List<Statement> statements, Statement statement); void addOptionalAttributeStatements(List<Statement> statements, List<AttributeStatement> statementList); AuthnStatement createAuthenicationStatements(final CallbackProperties properties); AuthzDecisionStatement createAuthorizationDecisionStatement(final CallbackProperties properties,
        final Subject subject); Evidence createEvidence(final CallbackProperties properties, final Subject subject); Evidence buildEvidence(CallbackProperties properties, List<AttributeStatement> statements, Subject subject); AttributeStatement createSubjectIdAttributeStatement(final CallbackProperties properties); static String appendPrefixHomeCommunityID(final String homeCommunityId); static String checkPrefixBeforeAppend(final String checkValue, final String checkPrefix); static List<Object> checkHcidPrefixInList(final List<Object> valueList);  }
@Test public void testBuild() throws SAMLAssertionBuilderException, CertificateManagerException { SAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); final Element assertion = builder.build(makeCallbackProperties(null), null); assertNotNull(assertion); }
@Test public void testBuild_NoSubjectID() throws CertificateManagerException { HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> properties = getDefaultProperties(); properties.put(SamlConstants.USER_FIRST_PROP, null); properties.put(SamlConstants.USER_MIDDLE_PROP, null); properties.put(SamlConstants.USER_LAST_PROP, null); try { builder.build(makeCallbackProperties(properties), null); fail("Builder does not fail when there is a missing user name / subject ID"); } catch (SAMLAssertionBuilderException e) { assertEquals("No information provided to fill in Subject ID attribute.", e.getMessage()); } }
@Test public void testBuild_NoSubjectOrg() throws CertificateManagerException { SAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> properties = getDefaultProperties(); properties.put(SamlConstants.USER_ORG_PROP, null); try { builder.build(makeCallbackProperties(properties), null); fail("Builder does not fail when there is a missing subject organization"); } catch (SAMLAssertionBuilderException e) { assertEquals("No Organization Attribute statement provided.", e.getMessage()); } }
@Test public void testBuild_NoSubjectRole() throws CertificateManagerException { SAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> properties = getDefaultProperties(); properties.put(SamlConstants.USER_CODE_PROP, null); properties.put(SamlConstants.USER_SYST_PROP, null); properties.put(SamlConstants.USER_SYST_NAME_PROP, null); properties.put(SamlConstants.USER_DISPLAY_PROP, null); try { builder.build(makeCallbackProperties(properties), null); fail("Builder does not fail when there is a missing subject role"); } catch (SAMLAssertionBuilderException e) { assertEquals("No information provided to fill in subject role attribute.", e.getMessage()); } }
@Test public void testBuild_NoPurposeOfUse() throws CertificateManagerException { SAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> properties = getDefaultProperties(); properties.put(SamlConstants.PURPOSE_CODE_PROP, null); properties.put(SamlConstants.PURPOSE_SYST_PROP, null); properties.put(SamlConstants.PURPOSE_SYST_NAME_PROP, null); properties.put(SamlConstants.PURPOSE_DISPLAY_PROP, null); try { builder.build(makeCallbackProperties(properties), null); fail("Builder does not fail when there is a missing purpose of use"); } catch (SAMLAssertionBuilderException e) { assertEquals("No information provided to fill in Purpose For Use attribute.", e.getMessage()); } }
@Test public void testBuild_NoHCID() throws CertificateManagerException { SAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> properties = getDefaultProperties(); properties.put(SamlConstants.HOME_COM_PROP, null); try { builder.build(makeCallbackProperties(properties), null); fail("Builder does not fail when there is a missing HCID"); } catch (SAMLAssertionBuilderException e) { assertEquals("No Home Community ID Attribute statement provided.", e.getMessage()); } }
@Test public void testBuild_NoOrgID() throws CertificateManagerException { SAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> properties = getDefaultProperties(); properties.put(SamlConstants.USER_ORG_ID_PROP, null); try { builder.build(makeCallbackProperties(properties), null); fail("Builder does not fail when there is a missing organization ID"); } catch (SAMLAssertionBuilderException e) { assertEquals("No Organization ID Attribute statement provided.", e.getMessage()); } }
@Test public void testBuildIssuer_DefaultNulled() throws CertificateManagerException { final HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> props = getDefaultProperties(); props.put(SamlConstants.ASSERTION_ISSUER_FORMAT_PROP, ""); props.put(SamlConstants.ASSERTION_ISSUER_PROP, ""); final CallbackProperties callbackProps = makeCallbackProperties(props); Element element = builder.build(callbackProps, null); Node issuer = getIssuerNode(element.getChildNodes()); String format = issuer.getAttributes().getNamedItem("Format").getNodeValue(); String issuerName = issuer.getFirstChild().getNodeValue(); assertEquals(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509, format); assertEquals(SamlConstants.SAML_DEFAULT_ISSUER_NAME, issuerName); }
@Test public void testBuildIssuer_X509Cert() throws CertificateManagerException { final HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); String issuer = "CN=SAMLTest User,OU=SU,O=SAML Test User,L=Los Angeles,ST=CA,C=US"; HashMap<String, Object> props = getDefaultProperties(); props.put(SamlConstants.ASSERTION_ISSUER_FORMAT_PROP, SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); props.put(SamlConstants.ASSERTION_ISSUER_PROP, issuer); final CallbackProperties callbackProps = makeCallbackProperties(props); Element element = builder.build(callbackProps, null); Node issuerNode = getIssuerNode(element.getChildNodes()); String format = issuerNode.getAttributes().getNamedItem("Format").getNodeValue(); String issuerName = issuerNode.getFirstChild().getNodeValue(); assertEquals(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509, format); assertEquals(issuer, issuerName); }
@Test public void testBuildIssuer_DomainName() throws CertificateManagerException { final HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> props = getDefaultProperties(); props.put(SamlConstants.ASSERTION_ISSUER_FORMAT_PROP, SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_WINDOWS_NAME); props.put(SamlConstants.ASSERTION_ISSUER_PROP, "CONNECT\\plobre"); final CallbackProperties callbackProps = makeCallbackProperties(props); Element element = builder.build(callbackProps, null); Node issuer = getIssuerNode(element.getChildNodes()); String format = issuer.getAttributes().getNamedItem("Format").getNodeValue(); String issuerName = issuer.getFirstChild().getNodeValue(); assertEquals(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_WINDOWS_NAME, format); assertEquals("CONNECT\\plobre", issuerName); }
@Test public void testBuildIssuer_Email() throws CertificateManagerException { final HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(setupCertManager()); HashMap<String, Object> props = getDefaultProperties(); props.put(SamlConstants.ASSERTION_ISSUER_FORMAT_PROP, SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS); props.put(SamlConstants.ASSERTION_ISSUER_PROP, "connect@connect.net"); final CallbackProperties callbackProps = makeCallbackProperties(props); Element element = builder.build(callbackProps, null); Node issuer = getIssuerNode(element.getChildNodes()); String format = issuer.getAttributes().getNamedItem("Format").getNodeValue(); String issuerName = issuer.getFirstChild().getNodeValue(); assertEquals(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS, format); assertEquals("connect@connect.net", issuerName); }