CONNECTSamlAssertionValidator extends SamlAssertionValidator { protected boolean validateAttributes() { boolean validate = false; try { validate = PropertyAccessor.getInstance().getPropertyBoolean(NhincConstants.SAML_PROPERTY_FILE, SamlConstants.VALIDATE_ATTRIBUTES_PROP); } catch (PropertyAccessException ex) { LOG.warn("Unable to access property for validating SAML attributes due to: {}", ex.getLocalizedMessage(), ex); } return validate; } CONNECTSamlAssertionValidator();  CONNECTSamlAssertionValidator(final PropertyAccessor propertyAccessor); @Override Credential validate(final Credential credential, final RequestData data); void checkAttributes(SamlAssertionWrapper assertion);  }
@Test public void testValidateAttributes() throws WSSecurityException { final org.opensaml.saml.saml2.core.Assertion saml2Assertion = mock(org.opensaml.saml.saml2.core.Assertion.class); final SamlAssertionWrapper assertionWrapper = new SamlAssertionWrapper(saml2Assertion); final XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory(); final SAMLObjectBuilder<AttributeStatement> attributeStatementBuilder = (SAMLObjectBuilder<AttributeStatement>) builderFactory .getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME); List<Object> values = new ArrayList<>(); values.add("value"); List<Attribute> attributes = new ArrayList<>(); for (String name : VALIDATED_ATTRIBUTES) { Attribute attr = SAML2ComponentBuilder.createAttribute("", name, "nameFormat", values); attributes.add(attr); } final AttributeStatement attributeStatement = attributeStatementBuilder.buildObject(); attributeStatement.getAttributes().addAll(attributes); List<AttributeStatement> statements = new ArrayList<>(); statements.add(attributeStatement); when(saml2Assertion.getAttributeStatements()).thenReturn(statements); CONNECTSamlAssertionValidator validator = new CONNECTSamlAssertionValidator(); validator.checkAttributes(assertionWrapper); }