Search in sources :

Example 16 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class CoreAuthenticationTestUtils method getAuthenticationBuilder.

public static AuthenticationBuilder getAuthenticationBuilder(final Principal principal) {
    val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess(handler.getName(), new DefaultAuthenticationHandlerExecutionResult(handler, meta));
}
Also used : lombok.val(lombok.val) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Example 17 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class DefaultAuthenticationBuilderTests method verifyUpdateOperation.

@Test
public void verifyUpdateOperation() {
    val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
    builder.addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
    builder.setCredentials(List.of(meta));
    val authn = builder.build();
    val builder2 = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
    builder2.setAuthenticationDate(ZonedDateTime.now(Clock.systemUTC()).plusDays(10));
    builder2.addAttribute("authn2", "value2");
    builder2.addWarning(new DefaultMessageDescriptor("code"));
    val authn2 = builder2.build();
    authn.updateAll(authn2);
    assertTrue(authn.getAttributes().containsKey("authn2"));
}
Also used : lombok.val(lombok.val) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) DefaultMessageDescriptor(org.apereo.cas.DefaultMessageDescriptor) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) Test(org.junit.jupiter.api.Test)

Example 18 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class DefaultAuthenticationBuilderTests method verifyOperation.

@Test
public void verifyOperation() {
    val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
    builder.addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
    builder.setCredentials(List.of(meta));
    val result = new DefaultAuthenticationHandlerExecutionResult(new SimpleTestUsernamePasswordAuthenticationHandler(), meta);
    builder.addSuccess("Success", result);
    builder.setFailures(Map.of("Failure1", new FailedLoginException()));
    builder.addFailure("Success", new FailedLoginException());
    assertFalse(builder.hasAttribute("invalid"));
    assertNotNull(builder.build());
}
Also used : lombok.val(lombok.val) FailedLoginException(javax.security.auth.login.FailedLoginException) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) Test(org.junit.jupiter.api.Test)

Example 19 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class SimpleTestUsernamePasswordAuthenticationHandler method authenticateUsernamePasswordInternal.

@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential, final String originalPassword) throws GeneralSecurityException, PreventedException {
    val username = credential.getUsername();
    val password = credential.getPassword();
    val exception = this.usernameErrorMap.get(username);
    if (exception instanceof GeneralSecurityException) {
        throw (GeneralSecurityException) exception;
    }
    if (exception instanceof PreventedException) {
        throw (PreventedException) exception;
    }
    if (exception instanceof RuntimeException) {
        throw (RuntimeException) exception;
    }
    if (exception != null) {
        LOGGER.debug("Cannot throw checked exception [{}] since it is not declared by method signature.", exception.getClass().getName(), exception);
    }
    if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password) && (username.equals(password) || password.equals(StringUtils.reverse(username)))) {
        LOGGER.debug("User [{}] was successfully authenticated.", username);
        return new DefaultAuthenticationHandlerExecutionResult(this, new BasicCredentialMetaData(credential), this.principalFactory.createPrincipal(username), this.warnings);
    }
    LOGGER.debug("User [{}] failed authentication", username);
    throw new FailedLoginException();
}
Also used : lombok.val(lombok.val) FailedLoginException(javax.security.auth.login.FailedLoginException) GeneralSecurityException(java.security.GeneralSecurityException) PreventedException(org.apereo.cas.authentication.PreventedException) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Example 20 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class DefaultAuthenticationHandlerExecutionResultTests method verifyOperation.

@Test
public void verifyOperation() {
    val otp = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    val res = new DefaultAuthenticationHandlerExecutionResult(new SimpleTestUsernamePasswordAuthenticationHandler(), new BasicCredentialMetaData(otp), CollectionUtils.wrapList(new DefaultMessageDescriptor("code1")));
    assertFalse(res.getWarnings().isEmpty());
    res.clearWarnings();
    assertTrue(res.getWarnings().isEmpty());
}
Also used : lombok.val(lombok.val) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) DefaultMessageDescriptor(org.apereo.cas.DefaultMessageDescriptor) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)21 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)21 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)12 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)8 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)7 FailedLoginException (javax.security.auth.login.FailedLoginException)6 Test (org.junit.jupiter.api.Test)6 GeneralSecurityException (java.security.GeneralSecurityException)3 HashMap (java.util.HashMap)3 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)3 BasicIdentifiableCredential (org.apereo.cas.authentication.credential.BasicIdentifiableCredential)3 DefaultMessageDescriptor (org.apereo.cas.DefaultMessageDescriptor)2 SpnegoCredential (org.apereo.cas.support.spnego.authentication.principal.SpnegoCredential)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 Type1Message (jcifs.ntlmssp.Type1Message)1 Type2Message (jcifs.ntlmssp.Type2Message)1 Type3Message (jcifs.ntlmssp.Type3Message)1 NtlmPasswordAuthentication (jcifs.smb.NtlmPasswordAuthentication)1