HOKSAMLAssertionBuilder extends SAMLAssertionBuilder { public AuthzDecisionStatement createAuthorizationDecisionStatement(final CallbackProperties properties, final Subject subject) { AuthzDecisionStatement authDecisionStatement = null; final Boolean hasAuthzStmt = properties.getAuthorizationStatementExists(); if (hasAuthzStmt) { final String resource = properties.getAuthorizationResource(); final Evidence evidence = createEvidence(properties, subject); authDecisionStatement = componentBuilder.createAuthzDecisionStatement(resource, AUTHZ_DECISION_PERMIT, AUTHZ_DECISION_ACTION_EXECUTE, evidence); } return authDecisionStatement; } 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 testCreateAuthenticationDecisionStatements() throws SAMLAssertionBuilderException { final CallbackProperties callbackProps = mock(CallbackProperties.class); final Subject subject = mock(Subject.class); final DateTime beforeCreation = new DateTime(); final DateTime conditionNotBefore = new DateTime(); final DateTime conditionNotAfter = conditionNotBefore.plusMinutes(5); final List<Object> evidenceAccessConstent = new ArrayList<>(); final List<Object> evidenceInstantAccessConsent = new ArrayList<>(); evidenceAccessConstent.add("urn:oid:1.2.3.4"); evidenceInstantAccessConsent.add("urn:oid:1.2.3.4.123456789"); when(callbackProps.getEvidenceConditionNotBefore()).thenReturn(conditionNotBefore); when(callbackProps.getEvidenceConditionNotAfter()).thenReturn(conditionNotAfter); when(callbackProps.getAuthorizationStatementExists()).thenReturn(true); when(callbackProps.getEvidenceAccessConstent()).thenReturn(evidenceAccessConstent); when(callbackProps.getEvidenceInstantAccessConsent()).thenReturn(evidenceInstantAccessConsent); final AuthzDecisionStatement statement = getNonDefaultConditionBuilder() .createAuthorizationDecisionStatement(callbackProps, subject); assertNotNull(statement); assertEquals(DecisionTypeEnumeration.PERMIT, statement.getDecision()); final Action action = statement.getActions().get(0); assertEquals(SAMLAssertionBuilder.AUTHZ_DECISION_ACTION_EXECUTE, action.getAction()); final Evidence evidence = statement.getEvidence(); final Assertion assertion = evidence.getAssertions().get(0); assertTrue(assertion.getID().startsWith("_")); assertTrue(beforeCreation.isBefore(assertion.getIssueInstant()) || beforeCreation.isEqual(assertion.getIssueInstant())); final Issuer issuer = assertion.getIssuer(); assertEquals(SAMLAssertionBuilder.X509_NAME_ID, issuer.getFormat()); final Conditions conditions = assertion.getConditions(); assertEquals(conditions.getNotBefore(), conditionNotBefore.withZone(DateTimeZone.UTC)); assertEquals(conditions.getNotOnOrAfter(), conditionNotAfter.withZone(DateTimeZone.UTC)); final List<AttributeStatement> attributeStatement = assertion.getAttributeStatements(); assertEquals(2, attributeStatement.get(0).getAttributes().size()); final Attribute firstAttribute = attributeStatement.get(0).getAttributes().get(0); final Attribute secondAttribute = attributeStatement.get(0).getAttributes().get(1); assertEquals("AccessConsentPolicy", firstAttribute.getName()); assertEquals("InstanceAccessConsentPolicy", secondAttribute.getName()); }
@Test public void testEvidenceConditionsNotBeforeAndNotAfterPresent() throws PropertyAccessException, SAMLAssertionBuilderException { final CallbackProperties callbackProps = mock(CallbackProperties.class); final Subject subject = mock(Subject.class); final DateTime conditionNotBefore = new DateTime(); final DateTime conditionNotAfter = new DateTime(); final PropertyAccessor propertyAccessor = mock(PropertyAccessor.class); when(propertyAccessor.getProperty(Mockito.anyString(), Mockito.anyString())) .thenReturn(Boolean.TRUE.toString()); when(callbackProps.getAuthorizationStatementExists()).thenReturn(true); when(callbackProps.getEvidenceConditionNotBefore()).thenReturn(conditionNotBefore); when(callbackProps.getEvidenceConditionNotAfter()).thenReturn(conditionNotAfter); final AuthzDecisionStatement statement = getNonDefaultConditionBuilder() .createAuthorizationDecisionStatement(callbackProps, subject); assertNotNull(statement); final Evidence evidence = statement.getEvidence(); final Assertion assertion = evidence.getAssertions().get(0); final Conditions conditions = assertion.getConditions(); assertEquals(conditions.getNotBefore(), conditionNotBefore.withZone(DateTimeZone.UTC)); assertEquals(conditions.getNotOnOrAfter(), conditionNotAfter.withZone(DateTimeZone.UTC)); }
@Test public void testEvidanceConditionsNotBeforeIsNull() throws PropertyAccessException, SAMLAssertionBuilderException { final CallbackProperties callbackProps = mock(CallbackProperties.class); final Subject subject = mock(Subject.class); final DateTime conditionNotAfter = new DateTime(); final PropertyAccessor propertyAccessor = mock(PropertyAccessor.class); when(propertyAccessor.getProperty(Mockito.anyString(), Mockito.anyString())) .thenReturn(Boolean.FALSE.toString()); when(callbackProps.getAuthorizationStatementExists()).thenReturn(true); when(callbackProps.getEvidenceConditionNotAfter()).thenReturn(conditionNotAfter); when(callbackProps.getEvidenceConditionNotBefore()).thenReturn(null); final AuthzDecisionStatement statement = getNonDefaultConditionBuilder() .createAuthorizationDecisionStatement(callbackProps, subject); assertNotNull(statement); final Evidence evidence = statement.getEvidence(); final Assertion assertion = evidence.getAssertions().get(0); final Conditions conditions = assertion.getConditions(); assertNull(conditions); }
@Test public void testEvidanceConditionsNotAfterIsNull() throws PropertyAccessException, SAMLAssertionBuilderException { final CallbackProperties callbackProps = mock(CallbackProperties.class); final Subject subject = mock(Subject.class); final DateTime conditionNotBefore = new DateTime(); final PropertyAccessor propertyAccessor = mock(PropertyAccessor.class); when(propertyAccessor.getProperty(Mockito.anyString(), Mockito.anyString())) .thenReturn(Boolean.FALSE.toString()); when(callbackProps.getAuthorizationStatementExists()).thenReturn(true); when(callbackProps.getEvidenceConditionNotBefore()).thenReturn(conditionNotBefore); when(callbackProps.getEvidenceConditionNotAfter()).thenReturn(null); final AuthzDecisionStatement statement = getNonDefaultConditionBuilder() .createAuthorizationDecisionStatement(callbackProps, subject); assertNotNull(statement); final Evidence evidence = statement.getEvidence(); final Assertion assertion = evidence.getAssertions().get(0); final Conditions conditions = assertion.getConditions(); assertNull(conditions); }
@Test public void testCreateAuthenticationDecisionStatementsWithoutACPorIACP() throws SAMLAssertionBuilderException { final CallbackProperties callbackProps = mock(CallbackProperties.class); final Subject subject = mock(Subject.class); final DateTime beforeCreation = new DateTime(); final DateTime conditionNotBefore = new DateTime(); final DateTime conditionNotAfter = conditionNotBefore.plusMinutes(5); when(callbackProps.getEvidenceConditionNotBefore()).thenReturn(conditionNotBefore); when(callbackProps.getEvidenceConditionNotAfter()).thenReturn(conditionNotAfter); when(callbackProps.getAuthorizationStatementExists()).thenReturn(true); final AuthzDecisionStatement statement = getNonDefaultConditionBuilder() .createAuthorizationDecisionStatement(callbackProps, subject); assertNotNull(statement); assertEquals(DecisionTypeEnumeration.PERMIT, statement.getDecision()); final Action action = statement.getActions().get(0); assertEquals(SAMLAssertionBuilder.AUTHZ_DECISION_ACTION_EXECUTE, action.getAction()); final Evidence evidence = statement.getEvidence(); final Assertion assertion = evidence.getAssertions().get(0); assertTrue(assertion.getID().startsWith("_")); assertTrue(beforeCreation.isBefore(assertion.getIssueInstant()) || beforeCreation.isEqual(assertion.getIssueInstant())); final Issuer issuer = assertion.getIssuer(); assertEquals(SAMLAssertionBuilder.X509_NAME_ID, issuer.getFormat()); final Conditions conditions = assertion.getConditions(); assertEquals(conditions.getNotBefore(), conditionNotBefore.withZone(DateTimeZone.UTC)); assertEquals(conditions.getNotOnOrAfter(), conditionNotAfter.withZone(DateTimeZone.UTC)); final List<AuthzDecisionStatement> authzDecisionStatements = assertion.getAuthzDecisionStatements(); assertTrue(CollectionUtils.isEmpty(authzDecisionStatements)); final List<AttributeStatement> attributeStatement = assertion.getAttributeStatements(); assertTrue(CollectionUtils.isEmpty(attributeStatement)); }