HOKSAMLAssertionBuilder extends SAMLAssertionBuilder { public AuthnStatement createAuthenicationStatements(final CallbackProperties properties) { AuthnStatement authnStatements = null; if (properties.getAuthenticationStatementExists()) { String cntxCls = properties.getAuthenticationContextClass(); if (cntxCls == null || !isValidAuthnCntxCls(cntxCls)) { LOG.error("Assertion Authentication Statement <AuthnContext> element is null or not valid format."); throw new SAMLAssertionBuilderException( "Assertion Authentication Statement <AuthnContext> element is null or not valid format."); } final String sessionIndex = properties.getAuthenticationSessionIndex(); LOG.debug("Setting Authentication session index to: {}", sessionIndex); DateTime authInstant = properties.getAuthenticationInstant(); if (authInstant == null) { LOG.error("Assertion Authentication Statement <AuthnInstant> element is null."); throw new SAMLAssertionBuilderException( "Assertion Authentication Statement <AuthnInstant> element is null."); } try { ISODateTimeFormat.dateTimeParser().parseDateTime(authInstant.toString()); } catch (UnsupportedOperationException | IllegalArgumentException e) { LOG.error("Date Format is incorrect."); throw new SAMLAssertionBuilderException(e.getLocalizedMessage(), e); } final String inetAddr = properties.getSubjectLocality(); final String dnsName = properties.getSubjectDNS(); final AuthnStatement authnStatement = componentBuilder .createAuthenticationStatements(cntxCls, sessionIndex, authInstant, inetAddr, dnsName); authnStatements = authnStatement; } return authnStatements; } 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 testCreateAuthenticationStatement_NullProperty() { final CallbackProperties callbackProps = mock(CallbackProperties.class); final HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(); when(callbackProps.getAuthenticationStatementExists()).thenReturn(true); try { builder.createAuthenicationStatements(callbackProps); fail("Builder does not fail when there is missing authentication"); } catch (SAMLAssertionBuilderException e) { assertEquals("Assertion Authentication Statement <AuthnContext> element is null or not valid format.", e.getMessage()); } }
@Test public void testCreateAuthenticationStatementWithContext() throws SAMLAssertionBuilderException { final CallbackProperties callbackProps = mock(CallbackProperties.class); final HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(); DateTime AuthIns = new DateTime(); when(callbackProps.getAuthenticationContextClass()).thenReturn("urn:oasis:names:tc:SAML:2.0:ac:classes:X509"); when(callbackProps.getAuthenticationInstant()).thenReturn(AuthIns); when(callbackProps.getAuthenticationStatementExists()).thenReturn(true); final AuthnStatement authnStatement = builder.createAuthenicationStatements(callbackProps); assertNotNull(authnStatement); assertNotNull(authnStatement); }
@Test public void testCreateAuthenticationStatementWithDateNull() { final CallbackProperties callbackProps = mock(CallbackProperties.class); final HOKSAMLAssertionBuilder builder = new HOKSAMLAssertionBuilder(); when(callbackProps.getAuthenticationContextClass()).thenReturn("urn:oasis:names:tc:SAML:2.0:ac:classes:X509"); when(callbackProps.getAuthenticationStatementExists()).thenReturn(true); try { builder.createAuthenicationStatements(callbackProps); fail("Auth statement did not throw when date provided is not provided"); } catch (SAMLAssertionBuilderException e) { assertEquals("Assertion Authentication Statement <AuthnInstant> element is null.", e.getMessage()); } }