/** * 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); }
/** * Verifies that authentication requests without subjects are not accepted. * * @throws Exception if an error occurs. */ @Test public void shouldNotAuthenticateWithoutSubject() throws Exception { logger.debug("Verifying that an authentication request without a subject is rejected..."); AssertionBuilder assertionBuilder = new AssertionBuilder(); Saml2AuthenticationToken authentication = new Saml2AuthenticationToken(assertionBuilder.getAssertion()); assertNull(authnProvider.authenticate(authentication)); assertFalse(authentication.isAuthenticated()); }
/** * Verifies that valid authentication requests are accepted. * * @throws Exception if an error occurs. */ @Test public void shouldAuthenticate() throws Exception { logger.debug("Verifying that a valid authentication request is accepted..."); AssertionBuilder assertionBuilder = new AssertionBuilder(); assertionBuilder.setSubject("*****@*****.**"); Saml2AuthenticationToken authentication = new Saml2AuthenticationToken(assertionBuilder.getAssertion()); assertNotNull(authnProvider.authenticate(authentication)); assertTrue(authentication.isAuthenticated()); }
/** * Verifies that the authentication provider doesn't support other authentication request types. */ @Test public void shouldNotSupportOtherAuthenticationRequests() { logger.debug( "Verifying that the authentication provider does not support other authentication requests..."); assertFalse(authnProvider.supports(LdapAuthenticator.class)); }
/** Verifies that the authentication provider supports instances of Saml2AuthenticationToken. */ @Test public void shouldSupportSaml2AuthenticationTokens() { logger.debug( "Verifying that the authentication provider supports instances of Saml2AuthenticationToken..."); assertTrue(authnProvider.supports(Saml2AuthenticationToken.class)); }