Search in sources :

Example 1 with UsernamePasswordCredential

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

the class PasswordExpiringWarningMessageDescriptorTests method verifySerialization.

@Test
public void verifySerialization() throws Exception {
    val d = new PasswordExpiringWarningMessageDescriptor("DefaultMessage", 30);
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    handler.addMessageDescriptor(d);
    val credential = new UsernamePasswordCredential("casuser", "resusac");
    val result = handler.authenticate(credential);
    assertNotNull(result);
    assertNotNull(result.getPrincipal());
    assertNotNull(result.getWarnings());
    MAPPER.writeValue(JSON_FILE, result);
    val read = MAPPER.readValue(JSON_FILE, AuthenticationHandlerExecutionResult.class);
    assertEquals(result, read);
}
Also used : lombok.val(lombok.val) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 2 with UsernamePasswordCredential

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

the class AuthenticationCredentialTypeMetaDataPopulatorTests method verifyPopulator.

@Test
public void verifyPopulator() {
    val credentials = new UsernamePasswordCredential();
    val builder = CoreAuthenticationTestUtils.getAuthenticationBuilder();
    this.populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credentials));
    val auth = builder.build();
    assertEquals(credentials.getClass().getSimpleName(), auth.getAttributes().get(Credential.CREDENTIAL_TYPE_ATTRIBUTE).get(0));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 3 with UsernamePasswordCredential

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

the class CoreAuthenticationTestUtils method getAuthentication.

public static Authentication getAuthentication(final Principal principal, final Map<String, List<Object>> attributes, final ZonedDateTime authnDate) {
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    return new DefaultAuthenticationBuilder(principal).addCredential(meta).setAuthenticationDate(authnDate).addSuccess(handler.getName(), new DefaultAuthenticationHandlerExecutionResult(handler, meta)).setAttributes(attributes).build();
}
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 4 with UsernamePasswordCredential

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

the class UsernamePasswordRestHttpRequestCredentialFactory method fromRequest.

@Override
public List<Credential> fromRequest(final HttpServletRequest request, final MultiValueMap<String, String> requestBody) {
    if (requestBody == null || requestBody.isEmpty()) {
        LOGGER.debug("Skipping [{}] because the requestBody is null or empty", getClass().getSimpleName());
        return new ArrayList<>(0);
    }
    val username = requestBody.getFirst(RestHttpRequestCredentialFactory.PARAMETER_USERNAME);
    val password = requestBody.getFirst(RestHttpRequestCredentialFactory.PARAMETER_PASSWORD);
    if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
        LOGGER.debug("Invalid payload; missing required fields.");
        return new ArrayList<>(0);
    }
    val c = new UsernamePasswordCredential(username, password);
    return CollectionUtils.wrap(c);
}
Also used : lombok.val(lombok.val) ArrayList(java.util.ArrayList) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

Example 5 with UsernamePasswordCredential

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

the class FileAuthenticationHandlerTests method verifyFailsUserNotInFileWithDefaultSeparator.

@Test
public void verifyFailsUserNotInFileWithDefaultSeparator() {
    val c = new UsernamePasswordCredential();
    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) Test(org.junit.jupiter.api.Test)

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