Search in sources :

Example 56 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class FileAuthenticationHandlerTests method verifyFailsUserNotInFileWithCommaSeparator.

@Test
public void verifyFailsUserNotInFileWithCommaSeparator() {
    val c = new UsernamePasswordCredential();
    this.authenticationHandler = new FileAuthenticationHandler(StringUtils.EMPTY, null, null, new ClassPathResource("authentication2.txt"), ",");
    c.setUsername("fds");
    c.setPassword("rutgers");
    assertThrows(AccountNotFoundException.class, () -> this.authenticationHandler.authenticate(c));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 57 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class FileAuthenticationHandlerTests method verifyFailsNullUserName.

@Test
public void verifyFailsNullUserName() {
    val c = new UsernamePasswordCredential();
    c.setUsername(null);
    c.setPassword("user");
    assertThrows(AccountNotFoundException.class, () -> this.authenticationHandler.authenticate(c));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 58 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class RejectUsersAuthenticationHandlerTests method verifyPassesNullUserName.

@Test
public void verifyPassesNullUserName() {
    val c = new UsernamePasswordCredential();
    c.setUsername(null);
    c.setPassword("user");
    assertThrows(AccountNotFoundException.class, () -> this.authenticationHandler.authenticate(c));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 59 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class RejectUsersAuthenticationHandlerTests method verifyFailsUserInMap.

@Test
public void verifyFailsUserInMap() {
    val c = new UsernamePasswordCredential();
    c.setUsername("scott");
    c.setPassword("rutgers");
    assertThrows(FailedLoginException.class, () -> this.authenticationHandler.authenticate(c));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 60 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential 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;
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) RememberMeAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Aggregations

lombok.val (lombok.val)111 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)111 Test (org.junit.jupiter.api.Test)74 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)12 HashMap (java.util.HashMap)8 Map (java.util.Map)8 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)8 LinkedHashMap (java.util.LinkedHashMap)7 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 Executable (org.junit.jupiter.api.function.Executable)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)6 MockRequestContext (org.springframework.webflow.test.MockRequestContext)6 ArrayList (java.util.ArrayList)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 MockServletContext (org.springframework.mock.web.MockServletContext)5 FailedLoginException (javax.security.auth.login.FailedLoginException)4 SurrogateUsernamePasswordCredential (org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)4