Search in sources :

Example 51 with UsernamePasswordCredential

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

the class SurrogateInitialAuthenticationAction method convertToUsernamePasswordCredential.

private static void convertToUsernamePasswordCredential(final RequestContext context, final UsernamePasswordCredential up) throws Exception {
    if (up instanceof SurrogateUsernamePasswordCredential) {
        val sc = new UsernamePasswordCredential();
        BeanUtils.copyProperties(sc, up);
        WebUtils.putCredential(context, sc);
    }
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)

Example 52 with UsernamePasswordCredential

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

the class UsernamePasswordCredentialTests method verifySetGetPassword.

@Test
public void verifySetGetPassword() {
    val c = new UsernamePasswordCredential();
    val password = "test";
    c.setPassword(password);
    assertEquals(password, c.getPassword());
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 53 with UsernamePasswordCredential

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

the class ScimAccountRegistrationProvisioner method provision.

@Override
public AccountRegistrationResponse provision(final AccountRegistrationRequest request) throws Exception {
    val attributes = new LinkedHashMap<String, List<Object>>();
    request.asMap().forEach((key, value) -> attributes.put(key, CollectionUtils.wrapList(value)));
    val principal = principalFactory.createPrincipal(request.getUsername(), attributes);
    val credential = new UsernamePasswordCredential(request.getUsername(), request.getPassword());
    val result = principalProvisioner.provision(principal, credential);
    LOGGER.debug("Provisioned account registration request for [{}]: [{}]", request.getUsername(), BooleanUtils.toString(result, "success", "failure"));
    return result ? AccountRegistrationResponse.success() : new AccountRegistrationResponse();
}
Also used : lombok.val(lombok.val) AccountRegistrationResponse(org.apereo.cas.acct.AccountRegistrationResponse) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with UsernamePasswordCredential

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

the class FileAuthenticationHandlerTests method verifyFailsNullUserNameAndPassword.

@Test
public void verifyFailsNullUserNameAndPassword() {
    val c = new UsernamePasswordCredential();
    c.setUsername(null);
    c.setPassword(null);
    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 55 with UsernamePasswordCredential

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

the class FileAuthenticationHandlerTests method verifyFailsGoodUsernameBadPassword.

@Test
public void verifyFailsGoodUsernameBadPassword() {
    val c = new UsernamePasswordCredential();
    this.authenticationHandler = new FileAuthenticationHandler(StringUtils.EMPTY, null, null, new ClassPathResource("authentication2.txt"), ",");
    c.setUsername("scott");
    c.setPassword("rutgers1");
    assertThrows(FailedLoginException.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)

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