Search in sources :

Example 6 with DefaultAuthenticationBuilder

use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.

the class AtLeastOneCredentialValidatedAuthenticationPolicyTests method verifyHandlerCountMismatch.

@Test
public void verifyHandlerCountMismatch() throws Exception {
    val input = new AtLeastOneCredentialValidatedAuthenticationPolicy(true);
    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 7 with DefaultAuthenticationBuilder

use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.

private AuthenticationBuilder newBuilder(final Credential credential) {
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    final AuthenticationBuilder builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
    if (this.p.supports(credential)) {
        this.p.populateAttributes(builder, AuthenticationTransaction.of(credential));
    }
    return builder;
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) 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) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.RememberMeUsernamePasswordCredential) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 8 with DefaultAuthenticationBuilder

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, Object> attributes) {
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess("testHandler", new DefaultAuthenticationHandlerExecutionResult(handler, meta)).setAttributes(attributes).build();
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 9 with DefaultAuthenticationBuilder

use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.

the class NotPreventedAuthenticationPolicyTests method verifyOperationNotPrevented.

@Test
public void verifyOperationNotPrevented() throws Exception {
    val input = new NotPreventedAuthenticationPolicy();
    val authn = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).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) Test(org.junit.jupiter.api.Test)

Example 10 with DefaultAuthenticationBuilder

use of org.apereo.cas.authentication.DefaultAuthenticationBuilder in project cas by apereo.

the class NotPreventedAuthenticationPolicyTests method verifyOperationPrevented.

@Test
public void verifyOperationPrevented() throws Exception {
    val input = new NotPreventedAuthenticationPolicy();
    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)

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