@Test
public void statefulAuthenticationIsSuccessful() throws Exception {
CasAuthentication token = new CasAuthentication(CasAuthentication.STATEFUL_ID, "ST-123", null);
token.setDetails("details");
Authentication result = cap.authenticate(token);
// Confirm ST-123 was NOT added to the cache
assertTrue(cache.get("ST-456") == null);
if (!(result instanceof CasAuthentication)) {
fail("Should have returned a CasAuthentication");
}
CasAuthentication casResult = (CasAuthentication) result;
assertEquals(makeUserDetailsFromAuthoritiesPopulator(), casResult.getPrincipal());
assertEquals("ST-123", casResult.getCredentials());
assertTrue(casResult.getAuthorities().contains(new GrantedAuthorityBean("ROLE_A")));
assertTrue(casResult.getAuthorities().contains(new GrantedAuthorityBean("ROLE_B")));
assertEquals(cap.getKey().hashCode(), casResult.getKeyHash());
assertEquals("details", casResult.getDetails());
// Now confirm the CasAuthentication is automatically re-accepted.
// To ensure TicketValidator not called again, set it to deliver an
// exception...
cap.setTicketValidator(new MockTicketValidator(false));
Authentication laterResult = cap.authenticate(result);
assertEquals(result, laterResult);
}