Saml2AllowNoSubjectAssertionSpecValidator extends Saml2ExchangeAuthFrameworkValidator { protected void validateSubject(final Assertion assertion) throws WSSecurityException { if (CollectionUtils.isEmpty(assertion.getStatements())) { assertAttAuthzStatements(assertion); } if (CollectionUtils.isNotEmpty(assertion.getAuthnStatements()) && assertion.getSubject() == null) { throw new WSSecurityException(ErrorCode.FAILURE, "Assertions containing AuthnStatements require a Subject"); } if (CollectionUtils.isNotEmpty(assertion.getAuthzDecisionStatements()) && assertion.getSubject() == null) { throw new WSSecurityException(ErrorCode.FAILURE, "Assertions containing AuthzDecisionStatements require a Subject"); } validateSubject(assertion.getSubject()); } Saml2AllowNoSubjectAssertionSpecValidator();   }
@Test public void testValidateSubject() throws WSSecurityException { 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); 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); final Subject subject = mock(Subject.class); final Issuer issuer = mock(Issuer.class); final NameID name = mock(NameID.class); when(assertion.getStatements()).thenReturn(statementList); when(assertion.getAuthnStatements()).thenReturn(authnStatementList); when(assertion.getAttributeStatements()).thenReturn(attrStatementList); when(assertion.getAuthzDecisionStatements()).thenReturn(authzDecisionStatementList); 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)); assertTrue(true); }