Search in sources :

Example 1 with DefaultAuthenticationBuilder

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);
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) CachedData(net.spy.memcached.CachedData) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Test(org.junit.Test)

Example 2 with DefaultAuthenticationBuilder

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));
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 3 with DefaultAuthenticationBuilder

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());
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) DefaultAuthenticationTransaction(org.apereo.cas.authentication.DefaultAuthenticationTransaction) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultAuthenticationBuilder

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());
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) PreventedException(org.apereo.cas.authentication.PreventedException) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultAuthenticationBuilder

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());
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)15 lombok.val (lombok.val)11 Test (org.junit.jupiter.api.Test)9 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)7 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)6 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)5 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)4 PreventedException (org.apereo.cas.authentication.PreventedException)4 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)4 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)3 CredentialMetaData (org.apereo.cas.authentication.CredentialMetaData)3 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)3 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AcceptUsersAuthenticationHandler (org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)2 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)2 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)2 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)2 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1