use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.
private static AuthenticationBuilder newBuilder(final Credential credential, final RememberMeAuthenticationProperties properties) {
val populator = new RememberMeAuthenticationMetaDataPopulator(properties);
val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
if (populator.supports(credential)) {
populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credential));
}
return builder;
}
use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class RegisteredServiceTestUtils method getAuthentication.
public static Authentication getAuthentication(final Principal principal, final Map<String, List<Object>> attributes) {
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess("testHandler", new DefaultAuthenticationHandlerExecutionResult(handler, meta)).setAttributes(attributes).build();
}
use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.
the class AtLeastOneCredentialValidatedAuthenticationPolicyTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val input = new AtLeastOneCredentialValidatedAuthenticationPolicy();
val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
val authn = builder.addSuccess("Handler1", mock(AuthenticationHandlerExecutionResult.class)).build();
assertTrue(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 AtLeastOneCredentialValidatedAuthenticationPolicyTests method verifyOperationPrevented.
@Test
public void verifyOperationPrevented() throws Exception {
val input = new AtLeastOneCredentialValidatedAuthenticationPolicy();
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 CasKryoTranscoderTests method verifyEncodeDecodeTGTImpl.
@Test
public void verifyEncodeDecodeTGTImpl() {
val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
val bldr = new DefaultAuthenticationBuilder(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
bldr.setAttributes(new HashMap<>(this.principalAttributes));
bldr.setAuthenticationDate(ZonedDateTime.now(ZoneId.systemDefault()));
bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
bldr.addFailure("error", new AccountNotFoundException());
bldr.addSuccess("authn", new DefaultAuthenticationHandlerExecutionResult(new AcceptUsersAuthenticationHandler(StringUtils.EMPTY), new BasicCredentialMetaData(userPassCredential)));
val authentication = bldr.build();
val expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, authentication, NeverExpiresExpirationPolicy.INSTANCE);
val serviceTicket = (ProxyGrantingTicketIssuerTicket) expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), NeverExpiresExpirationPolicy.INSTANCE, false, true);
var encoded = transcoder.encode(expectedTGT);
var decoded = transcoder.decode(encoded);
assertEquals(expectedTGT, decoded);
encoded = transcoder.encode(serviceTicket);
decoded = transcoder.decode(encoded);
assertEquals(serviceTicket, decoded);
decoded = transcoder.decode(encoded);
assertEquals(serviceTicket, decoded);
val pgt = serviceTicket.grantProxyGrantingTicket(PGT_ID, authentication, new HardTimeoutExpirationPolicy(100));
encoded = transcoder.encode(pgt);
decoded = transcoder.decode(encoded);
assertEquals(pgt, decoded);
val pt = pgt.grantProxyTicket(PT_ID, RegisteredServiceTestUtils.getService(), new HardTimeoutExpirationPolicy(100), true);
encoded = transcoder.encode(pt);
decoded = transcoder.decode(encoded);
assertEquals(pt, decoded);
}
Aggregations