CONNECTSamlAssertionValidator extends SamlAssertionValidator { @Override protected void validateAssertion(final SamlAssertionWrapper assertion) throws WSSecurityException { if (assertion.getSaml1() != null) { assertion.validateSignatureAgainstProfile(); } else if (assertion.getSaml2() != null) { final Issuer issuer = assertion.getSaml2().getIssuer(); validateIssuer(issuer); try { for (final Saml2ExchangeAuthFrameworkValidator validator : getSaml2SpecValidators()) { validator.validateAssertion(assertion); } } catch (final WSSecurityException e) { LOG.error("Saml Validation error: {}", e.getLocalizedMessage(), e); throw new WSSecurityException(ErrorCode.FAILED_CHECK, "invalidSAMLsecurity"); } } } CONNECTSamlAssertionValidator();  CONNECTSamlAssertionValidator(final PropertyAccessor propertyAccessor); @Override Credential validate(final Credential credential, final RequestData data); void checkAttributes(SamlAssertionWrapper assertion);  }
@Test public void testValidateAssertionSaml1() throws WSSecurityException { final org.opensaml.saml.saml1.core.Assertion saml1Assertion = mock(org.opensaml.saml.saml1.core.Assertion.class); final SamlAssertionWrapper assertionWrapper = new SamlAssertionWrapper(saml1Assertion); final SamlAssertionWrapper assertion = spy(assertionWrapper); final QName assertionQName = new QName("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion", "saml1"); when(saml1Assertion.getElementQName()).thenReturn(assertionQName); when(saml1Assertion.getMajorVersion()).thenReturn(1); when(saml1Assertion.getMinorVersion()).thenReturn(0); when(saml1Assertion.getID()).thenReturn("Assertion_ID"); when(saml1Assertion.getIssuer()).thenReturn("Issuer"); final DateTime dateTime = new DateTime(); when(saml1Assertion.getIssueInstant()).thenReturn(dateTime); final Statement statement = mock(Statement.class); final List<Statement> statementList = new ArrayList<>(); statementList.add(statement); when(saml1Assertion.getStatements()).thenReturn(statementList); final Signature signature = mock(Signature.class, RETURNS_DEEP_STUBS); final List<ContentReference> content = mock(List.class); final SAMLObjectContentReference b = mock(SAMLObjectContentReference.class); b.setDigestAlgorithm(SignatureConstants.ALGO_ID_DIGEST_SHA1); when(signature.getContentReferences()).thenReturn(content); when((SAMLObjectContentReference) content.get(0)).thenReturn(b); assertion.setSignature(signature); final CONNECTSamlAssertionValidator validator = new CONNECTSamlAssertionValidator() { @Override protected boolean validateAttributes() { return false; } }; validator.validateAssertion(assertion); verify(assertion).validateSignatureAgainstProfile(); }
@Test(expected = WSSecurityException.class) public void testValidateAssertionSaml1_ValidationFails() throws WSSecurityException { final org.opensaml.saml.saml1.core.Assertion saml1Assertion = mock(org.opensaml.saml.saml1.core.Assertion.class); final SamlAssertionWrapper assertion = new SamlAssertionWrapper(saml1Assertion); final QName assertionQName = new QName("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion", "saml1"); when(saml1Assertion.getElementQName()).thenReturn(assertionQName); when(saml1Assertion.getMajorVersion()).thenReturn(1); when(saml1Assertion.getMinorVersion()).thenReturn(0); when(saml1Assertion.getID()).thenReturn(null); final Signature signature = new SignatureBuilder().buildObject(); when(assertion.getSignature()).thenReturn(signature); final CONNECTSamlAssertionValidator validator = new CONNECTSamlAssertionValidator() { @Override protected boolean validateAttributes() { return false; } }; validator.validateAssertion(assertion); }