Saml2ExchangeAuthFrameworkValidator extends SamlAssertionValidator { @Override protected void validateAssertion(final SamlAssertionWrapper samlAssertion) throws WSSecurityException { try { super.validateAssertion(samlAssertion); validateSubject(samlAssertion.getSaml2().getSubject()); validateIssuer(samlAssertion.getSaml2().getIssuer()); } catch (WSSecurityException e) { LOG.error("Validation Fail {}", e.getLocalizedMessage(), e); throw new WSSecurityException(ErrorCode.FAILURE, e); } }    }
@Test public void testValidate() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = mock(Issuer.class); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); when(name.getValue()).thenReturn(SamlConstants.SAML_DEFAULT_ISSUER_NAME); when(assertion.getIssuer()).thenReturn(issuer); when(issuer.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); when(issuer.getValue()).thenReturn(SamlConstants.SAML_DEFAULT_ISSUER_NAME); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test public void testValidate2() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = mock(Issuer.class); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS); when(name.getValue()).thenReturn("example@example.org"); when(assertion.getIssuer()).thenReturn(issuer); when(issuer.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS); when(issuer.getValue()).thenReturn("example@example.org"); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateNoNameSubject() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); when(assertion.getSubject()).thenReturn(subject); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateSubjectWrongFormat() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn("wrong value"); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateIssuerNoFormat() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = mock(Issuer.class); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS); when(assertion.getIssuer()).thenReturn(issuer); when(issuer.getFormat()).thenReturn(null); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateIssuerNotEmailAddress() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = generateIssuer(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS, "this is obviously not an email address....okkk?"); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS); when(assertion.getIssuer()).thenReturn(issuer); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateIssuerNotX509SubjectName() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = generateIssuer(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509, "this is obviously not an x509 subject name....okkk?"); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); when(assertion.getIssuer()).thenReturn(issuer); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateIssuerNotWindowsDomainName() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = generateIssuer(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_WINDOWS_NAME, "this is obviously not an windows domain name....okkk?"); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); when(assertion.getIssuer()).thenReturn(issuer); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateSubjectX509InvalidValue() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = mock(Issuer.class); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); when(name.getValue()).thenReturn("not a valid X509 name."); when(assertion.getIssuer()).thenReturn(issuer); when(issuer.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); when(issuer.getValue()).thenReturn(SamlConstants.SAML_DEFAULT_ISSUER_NAME); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }
@Test(expected = WSSecurityException.class) public void testValidateSubjectEmailInvalidValue() throws WSSecurityException { Saml2ExchangeAuthFrameworkValidator validator = new Saml2ExchangeAuthFrameworkValidator(); Assertion assertion = mock(Assertion.class); Subject subject = mock(Subject.class); NameID name = mock(NameID.class); Issuer issuer = mock(Issuer.class); when(assertion.getSubject()).thenReturn(subject); when(subject.getNameID()).thenReturn(name); when(name.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_EMAIL_ADDRESS); when(name.getValue()).thenReturn("not a valid email address."); when(assertion.getIssuer()).thenReturn(issuer); when(issuer.getFormat()).thenReturn(SamlConstants.AUTH_FRWK_NAME_ID_FORMAT_X509); when(issuer.getValue()).thenReturn(SamlConstants.SAML_DEFAULT_ISSUER_NAME); validator.validateAssertion(new SamlAssertionWrapper(assertion)); }