/**
  * Verifies that the authentication provider throws an exception when authentication fails if we
  * request it to.
  *
  * @throws Exception if an error occurs.
  */
 @Test(expected = BadCredentialsException.class)
 public void shouldThrowExceptionOnAuthenticaitonFailureIfAsked() throws Exception {
   logger.debug(
       "Verifying that the authentication provider can throw an exception when authentication fails...");
   AssertionBuilder assertionBuilder = new AssertionBuilder();
   Saml2AuthenticationToken authentication =
       new Saml2AuthenticationToken(assertionBuilder.getAssertion());
   authnProvider.setThrowExceptionWhenTokenRejected(true);
   authnProvider.authenticate(authentication);
 }