CONNECTSamlAssertionValidator extends SamlAssertionValidator { protected void checkSignedAssertion(final SamlAssertionWrapper assertion, final RequestData data) throws WSSecurityException { final SAMLKeyInfo samlKeyInfo = assertion.getSignatureKeyInfo(); final X509Certificate[] certs = samlKeyInfo.getCerts(); final PublicKey publicKey = samlKeyInfo.getPublicKey(); try { super.verifySignedAssertion(assertion, data); } catch (final WSSecurityException e) { if (certs == null && publicKey != null) { LOG.warn("Could not establish trust of the signature's public key because no matching public key " + "exists in the truststore."); } else { throw e; } } } CONNECTSamlAssertionValidator();  CONNECTSamlAssertionValidator(final PropertyAccessor propertyAccessor); @Override Credential validate(final Credential credential, final RequestData data); void checkAttributes(SamlAssertionWrapper assertion);  }
@Test public void testCheckSignedAssertion_HappyPath() throws WSSecurityException { final SamlAssertionWrapper assertion = mock(SamlAssertionWrapper.class); final RequestData data = mock(RequestData.class); final SAMLKeyInfo keyInfo = mock(SAMLKeyInfo.class); final PublicKey publicKey = mock(PublicKey.class); final Crypto crypto = mock(Crypto.class); when(assertion.getSignatureKeyInfo()).thenReturn(keyInfo); when(keyInfo.getPublicKey()).thenReturn(publicKey); when(data.getDecCrypto()).thenReturn(crypto); final CONNECTSamlAssertionValidator validator = new CONNECTSamlAssertionValidator() { @Override protected boolean validateAttributes() { return false; } }; validator.checkSignedAssertion(assertion, data); assertNotNull(assertion.getSignatureKeyInfo().getPublicKey()); assertNull(assertion.getSignatureKeyInfo().getCerts()); }
@Test public void testCheckSignedAssertion_ChainCertError() throws WSSecurityException { final SamlAssertionWrapper assertion = mock(SamlAssertionWrapper.class); final RequestData data = mock(RequestData.class); final SAMLKeyInfo keyInfo = mock(SAMLKeyInfo.class); final PublicKey publicKey = mock(PublicKey.class); final Crypto crypto = mock(Crypto.class); when(assertion.getSignatureKeyInfo()).thenReturn(keyInfo); when(keyInfo.getPublicKey()).thenReturn(publicKey); when(data.getSigVerCrypto()).thenReturn(crypto); final CONNECTSamlAssertionValidator validator = new CONNECTSamlAssertionValidator() { @Override protected boolean validateAttributes() { return false; } }; validator.checkSignedAssertion(assertion, data); assertNotNull(assertion.getSignatureKeyInfo().getPublicKey()); assertNull(assertion.getSignatureKeyInfo().getCerts()); }
@Test(expected = WSSecurityException.class) public void testCheckSignedAssertion_Exception() throws WSSecurityException { final SamlAssertionWrapper assertion = mock(SamlAssertionWrapper.class); final RequestData data = mock(RequestData.class); final SAMLKeyInfo keyInfo = mock(SAMLKeyInfo.class); when(assertion.getSignatureKeyInfo()).thenReturn(keyInfo); final CONNECTSamlAssertionValidator validator = new CONNECTSamlAssertionValidator() { @Override protected boolean validateAttributes() { return false; } }; validator.checkSignedAssertion(assertion, data); }