Saml2AllowNoSubjectAssertionSpecValidator extends Saml2ExchangeAuthFrameworkValidator { @Override protected void validateAssertion(final SamlAssertionWrapper samlAssertion) throws WSSecurityException { validateSubject(samlAssertion.getSaml2()); } Saml2AllowNoSubjectAssertionSpecValidator();   }
@Test(expected = WSSecurityException.class) public void testValidateSubject_FailOnGetStatemtents() throws WSSecurityException { final String expectedMessage = "Subject is required when Statements are absent"; final Assertion assertion = mock(Assertion.class); final Saml2AllowNoSubjectAssertionSpecValidator validator = new Saml2AllowNoSubjectAssertionSpecValidator(); final List<Statement> statementList = new ArrayList<>(); when(assertion.getStatements()).thenReturn(statementList); try { validator.validateAssertion(new SamlAssertionWrapper(assertion)); } catch (final WSSecurityException e) { assertEquals(e.getMsgID(), expectedMessage); throw e; } }
@Test(expected = WSSecurityException.class) public void testValidateSubject_FailOnGetAuthnStatements() throws WSSecurityException { final String expectedMessage = "Assertions containing AuthnStatements require a Subject"; final Assertion assertion = mock(Assertion.class); final Saml2AllowNoSubjectAssertionSpecValidator validator = new Saml2AllowNoSubjectAssertionSpecValidator(); final Statement statement = mock(Statement.class); final List<Statement> statementList = new ArrayList<>(); statementList.add(statement); final AuthnStatement authnStatement = mock(AuthnStatement.class); final List<AuthnStatement> authnStatementList = new ArrayList<>(); authnStatementList.add(authnStatement); when(assertion.getStatements()).thenReturn(statementList); when(assertion.getAuthnStatements()).thenReturn(authnStatementList); try { validator.validateAssertion(new SamlAssertionWrapper(assertion)); } catch (final WSSecurityException e) { assertEquals(e.getMsgID(), expectedMessage); throw e; } }
@Test(expected = WSSecurityException.class) public void testValidateSubject_FailOnGetAuthzDecisionStatements() throws WSSecurityException { final String expectedMessage = "Assertions containing AuthzDecisionStatements require a Subject"; final Assertion assertion = mock(Assertion.class); final Saml2AllowNoSubjectAssertionSpecValidator validator = new Saml2AllowNoSubjectAssertionSpecValidator(); final Statement statement = mock(Statement.class); final List<Statement> statementList = new ArrayList<>(); statementList.add(statement); final List<AuthnStatement> authnStatementList = new ArrayList<>(); final AttributeStatement attrStatement = mock(AttributeStatement.class); final List<AttributeStatement> attrStatementList = new ArrayList<>(); attrStatementList.add(attrStatement); final AuthzDecisionStatement authzDecisionStatement = mock(AuthzDecisionStatement.class); final List<AuthzDecisionStatement> authzDecisionStatementList = new ArrayList<>(); authzDecisionStatementList.add(authzDecisionStatement); when(assertion.getStatements()).thenReturn(statementList); when(assertion.getAuthnStatements()).thenReturn(authnStatementList); when(assertion.getAttributeStatements()).thenReturn(attrStatementList); when(assertion.getAuthzDecisionStatements()).thenReturn(authzDecisionStatementList); try { validator.validateAssertion(new SamlAssertionWrapper(assertion)); } catch (final WSSecurityException e) { assertEquals(e.getMsgID(), expectedMessage); throw e; } }