SamlTokenCreator { public Map<String, Object> createRequestContext(AssertionType assertion, String url, String action) { LOG.trace("Entering SamlTokenCreator.CreateRequestContext..."); Map<String, Object> requestContext = new HashMap<>(); if (assertion != null) { String NPI = assertion.getNationalProviderId(); if (NullChecker.isNotNullish(NPI)) { requestContext.put(SamlConstants.ATTRIBUTE_NAME_NPI, NPI); } extractAccessConsentAttributes(requestContext, assertion); extractSubjectConfirmation(requestContext, assertion); extractUserInfo(requestContext, assertion); extractPurposeOfDisclosureCoded(assertion, requestContext); extractHomeCommunity(requestContext, assertion); if (CollectionUtils.isNotEmpty(assertion.getUniquePatientId())) { for (String patId : assertion.getUniquePatientId()) { if (NullChecker.isNotNullish(patId)) { requestContext.put(SamlConstants.PATIENT_ID_PROP, patId); break; } } } extractSamlIssuer(requestContext, assertion); extractSamlConditions(requestContext, assertion); extractSamlAuthnStatement(assertion, requestContext); extractSamlAuthzDecisionStatement(assertion, requestContext); extractSamlIssuerAttributes(assertion, requestContext); extractSamlAlgorithmTypes(assertion, requestContext); } else { LOG.error("Error: samlSendOperation input assertion is null"); } requestContext.put(SamlConstants.RESOURCE_PROP, url); if (NullChecker.isNotNullish(action)) { requestContext.put(SamlConstants.ACTION_PROP, action); } else { LOG.warn("samlSendOperation input action is null"); } if (LOG.isTraceEnabled()) { LOG.trace("Request Context:"); Set<Entry<String, Object>> allKeys = requestContext.entrySet(); for (Entry<String, Object> keyValue : allKeys) { LOG.trace(keyValue.getKey() + " = " + keyValue.getValue()); } } LOG.trace("Exiting SamlTokenCreator.CreateRequestContext..."); return requestContext; }  Map<String, Object> createRequestContext(AssertionType assertion, String url, String action);  }
@Test public void CreateRequestContext() { SamlTokenCreator token = new SamlTokenCreator(); String action = null; Map<String, Object> expectedrequestContext; expectedrequestContext = token.createRequestContext(createAssertionInfo(), RESOURCE_URL, action); System.out.println(expectedrequestContext); testUserName(expectedrequestContext); testUserHomeCommunityId(expectedrequestContext); testUserOrganizationName(expectedrequestContext); testUserInfoCode(expectedrequestContext); testUserInfoCodeSystem(expectedrequestContext); testUserInfoCodeSystemName(expectedrequestContext); testUserInfoCodedisplayName(expectedrequestContext); testPersonNameTypeFirstName(expectedrequestContext); testPersonNameTypeMiddleName(expectedrequestContext); testPersonNameTypeLastName(expectedrequestContext); testPurposeOfUseRoleCode(expectedrequestContext); testPurposeOfUseCodeSystem(expectedrequestContext); testPurposeOfUseCodeSystemName(expectedrequestContext); testPurposeOfUseDisplayName(expectedrequestContext); testHomeCommunity(expectedrequestContext); testAuthnInstant(expectedrequestContext); testAuthnSessionIndex(expectedrequestContext); testAuthnContextClass(expectedrequestContext); testSubjectLocalityAddress(expectedrequestContext); testSubjectLocalityDNS(expectedrequestContext); testauthzAction(expectedrequestContext); testauthzResource(expectedrequestContext); testauthzDecision(expectedrequestContext); testEvidenceAssertionId(expectedrequestContext); testEvidenceAssertionInstant(expectedrequestContext); testEvidenceAssertionVersion(expectedrequestContext); testEvidenceAssertionIssuer(expectedrequestContext); testEvidenceAssertionIssuerFormat(expectedrequestContext); testEvidenceSubject(expectedrequestContext); testEvidenceConditionNotBefore(expectedrequestContext); testEvidenceConditionNotAfter(expectedrequestContext); testAssertionIssuer(expectedrequestContext); testAssertionIssuerFormat(expectedrequestContext); }
@Test public void createRequestContextAssertionNull() { AssertionType assertion = null; String url = null; String action = null; SamlTokenCreator token = new SamlTokenCreator(); Map<String, Object> requestContext = token.createRequestContext(assertion, url, action); assertEquals("requestContext created with null params should have exactly one entry", requestContext.size(), 1); }
@Test public void createRequestContextUserNameNull() { AssertionType assertion = new AssertionType(); UserType userInfo = new UserType(); PersonNameType person = null; userInfo.setPersonName(person); assertion.setUserInfo(userInfo); String url = null; String action = null; SamlTokenCreator token = new SamlTokenCreator(); Map<String, Object> expectedrequestContext = token.createRequestContext(assertion, url, action); assertFalse(expectedrequestContext.containsKey("userName")); }
@Test public void createRequestContextUserInfoOrgNull() { AssertionType assertion = new AssertionType(); UserType userInfo = new UserType(); HomeCommunityType home = new HomeCommunityType(); userInfo.setOrg(home); assertion.setUserInfo(userInfo); String url = null; String action = null; SamlTokenCreator token = new SamlTokenCreator(); Map<String, Object> expectedrequestContext = token.createRequestContext(assertion, url, action); assertFalse(expectedrequestContext.containsKey("userOrganization")); }
@Test public void createRequestContextUserInfoRoleCodedNull() { AssertionType assertion = new AssertionType(); UserType userInfo = new UserType(); HomeCommunityType home = new HomeCommunityType(); home.setHomeCommunityId("1.1"); home.setName("CONNECT"); userInfo.setOrg(home); CeType ce = new CeType(); userInfo.setRoleCoded(ce); assertion.setUserInfo(userInfo); String url = null; String action = null; SamlTokenCreator token = new SamlTokenCreator(); Map<String, Object> expectedrequestContext = token.createRequestContext(assertion, url, action); assertFalse(expectedrequestContext.containsKey("userRoleCode")); }