SpecificUserAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext) { final Bundle bundle = policyBuilderContext.getBundle(); final IdGenerator idGenerator = policyBuilderContext.getIdGenerator(); final Element idProviderNameElement = getSingleChildElement(assertionElement, ID_PROV_NAME, true); if (idProviderNameElement != null) { final String idProviderName = idProviderNameElement.getAttributes().getNamedItem(STRING_VALUE).getTextContent(); String id; if (idProviderName.equals(INTERNAL_IDP_NAME)) { id = INTERNAL_IDP_ID; } else { final IdentityProvider identityProvider = bundle.getIdentityProviders().get(idProviderName); if (identityProvider != null) { if (identityProvider.getAnnotatedEntity() != null && identityProvider.getAnnotatedEntity().getId() != null) { id = identityProvider.getAnnotatedEntity().getId(); } else { id = identityProvider.getId(); } } else { id = idGenerator.generate(); } } Element idProviderGoidElement = createElementWithAttribute( policyBuilderContext.getPolicyDocument(), ID_PROV_OID, GOID_VALUE, id ); assertionElement.insertBefore(idProviderGoidElement, idProviderNameElement); assertionElement.removeChild(idProviderNameElement); } }  @Override void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext); @Override String getAssertionTagName();  }
@Test public void testBuildAssertionElement() { String providerName = "testLdap"; Element authenticationAssertion = createSpecificUserAssertion(document, providerName); policyBuilderContext = new PolicyBuilderContext("path.xml", document, bundle, new IdGenerator()); policyBuilderContext.withPolicy(policy); authenticationAssertionBuilder.buildAssertionElement(authenticationAssertion, policyBuilderContext); Element idProvideOidElement = getSingleChildElement(authenticationAssertion, ID_PROV_OID, true); assertNotNull(idProvideOidElement); }
@Test public void testBuildAssertionElementForInternalIDProvider() { String providerName = INTERNAL_IDP_NAME; Element authenticationAssertion = createSpecificUserAssertion(document, providerName); policyBuilderContext = new PolicyBuilderContext("path.xml", document, bundle, new IdGenerator()); policyBuilderContext.withPolicy(policy); authenticationAssertionBuilder.buildAssertionElement(authenticationAssertion, policyBuilderContext); Element idProvideOidElement = getSingleChildElement(authenticationAssertion, ID_PROV_OID, true); assertNotNull(idProvideOidElement); }