use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class KryoTranscoderTests method verifyEncodeDecodeTGTImpl.
@Test
public void verifyEncodeDecodeTGTImpl() throws Exception {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final AuthenticationBuilder bldr = new DefaultAuthenticationBuilder(new DefaultPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
bldr.setAttributes(new HashMap<>(this.principalAttributes));
bldr.setAuthenticationDate(ZonedDateTime.now());
bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
bldr.addFailure("error", AccountNotFoundException.class);
bldr.addSuccess("authn", new DefaultHandlerResult(new AcceptUsersAuthenticationHandler(""), new BasicCredentialMetaData(userPassCredential)));
final TicketGrantingTicket expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, bldr.build(), new NeverExpiresExpirationPolicy());
final ServiceTicket ticket = expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
CachedData result = transcoder.encode(expectedTGT);
final TicketGrantingTicket resultTicket = (TicketGrantingTicket) transcoder.decode(result);
assertEquals(expectedTGT, resultTicket);
result = transcoder.encode(ticket);
final ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
}
use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class SamlAuthenticationMetaDataPopulatorTests method newAuthenticationBuilder.
private static AuthenticationBuilder newAuthenticationBuilder(final Principal principal) {
final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess("test", new DefaultHandlerResult(handler, meta));
}
use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class SuccessfulHandlerMetaDataPopulatorTests method verifyOperation.
@Test
public void verifyOperation() {
val input = new SuccessfulHandlerMetaDataPopulator();
val transaction = new DefaultAuthenticationTransaction(CoreAuthenticationTestUtils.getWebApplicationService(), List.of(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("cas")));
val builder = new DefaultAuthenticationBuilder();
input.populateAttributes(builder, transaction);
assertFalse(builder.hasAttribute(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS));
assertTrue(builder.getAttributes().get(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS).isEmpty());
}
use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class AllAuthenticationHandlersSucceededAuthenticationPolicyTests method verifyOperationPrevented.
@Test
public void verifyOperationPrevented() {
val input = new AllAuthenticationHandlersSucceededAuthenticationPolicy();
val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
val authn = builder.addFailure("Prevented", new PreventedException("error")).build();
assertFalse(input.isSatisfiedBy(authn, Set.of(), mock(ConfigurableApplicationContext.class), Optional.empty()).isSuccess());
}
use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class AllAuthenticationHandlersSucceededAuthenticationPolicyTests method verifyMismatch.
@Test
public void verifyMismatch() {
val input = new AllAuthenticationHandlersSucceededAuthenticationPolicy();
val authn = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).build();
assertFalse(input.isSatisfiedBy(authn, Set.of(new SimpleTestUsernamePasswordAuthenticationHandler()), mock(ConfigurableApplicationContext.class), Optional.empty()).isSuccess());
}
Aggregations