Search in sources :

Example 36 with UsernamePasswordCredential

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

the class AcceptUsersAuthenticationHandlerTests method verifySupportsSpecialCharacters.

@Test
public void verifySupportsSpecialCharacters() throws Exception {
    val c = new UsernamePasswordCredential();
    c.setUsername("brian");
    c.setPassword("t�st");
    assertEquals("brian", getAuthenticationHandler().authenticate(c).getPrincipal().getId());
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 37 with UsernamePasswordCredential

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

the class AcceptUsersAuthenticationHandlerTests method verifyFailsNullUserName.

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

Example 38 with UsernamePasswordCredential

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

the class AcceptUsersAuthenticationHandlerTests method verifyAuthenticatesUserInMap.

@Test
public void verifyAuthenticatesUserInMap() {
    val c = new UsernamePasswordCredential();
    c.setUsername(SCOTT);
    c.setPassword(RUTGERS);
    try {
        assertEquals(SCOTT, getAuthenticationHandler().authenticate(c).getPrincipal().getId());
    } catch (final GeneralSecurityException e) {
        throw new AssertionError("Authentication exception caught but it should not have been thrown.", e);
    }
}
Also used : lombok.val(lombok.val) GeneralSecurityException(java.security.GeneralSecurityException) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 39 with UsernamePasswordCredential

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

the class UsernamePasswordCredentialTests method verifyOperation.

@Test
public void verifyOperation() {
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val input = new UsernamePasswordCredential("casuser", "Mellon", StringUtils.EMPTY, Map.of());
    assertTrue(input.isValid());
    assertEquals(UsernamePasswordCredential.class, input.getClass());
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val validationContext = new DefaultValidationContext(context, "submit", mock(MappingResults.class));
    input.validate(validationContext);
    assertTrue(context.getMessageContext().hasErrorMessages());
}
Also used : lombok.val(lombok.val) DefaultValidationContext(org.springframework.webflow.validation.DefaultValidationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) MappingResults(org.springframework.binding.mapping.MappingResults) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with UsernamePasswordCredential

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

the class BasicCredentialMetaDataTests method verifySerializeABasicCredentialMetaDataToJson.

@Test
public void verifySerializeABasicCredentialMetaDataToJson() throws Exception {
    val credentialMetaDataWritten = new BasicCredentialMetaData(new UsernamePasswordCredential());
    MAPPER.writeValue(JSON_FILE, credentialMetaDataWritten);
    val credentialMetaDataRead = MAPPER.readValue(JSON_FILE, BasicCredentialMetaData.class);
    assertEquals(credentialMetaDataWritten, credentialMetaDataRead);
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) 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