Search in sources :

Example 86 with UsernamePasswordCredential

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

the class SurrogateAuthenticationRestHttpRequestCredentialFactoryTests method verifyBasicUsernamePasswordOperationWithoutSurrogatePrincipal.

@Test
public void verifyBasicUsernamePasswordOperationWithoutSurrogatePrincipal() {
    val request = new MockHttpServletRequest();
    val requestBody = new LinkedMultiValueMap<String, String>();
    requestBody.add("username", "test");
    requestBody.add("password", "password");
    val service = new SimpleSurrogateAuthenticationService(Collections.emptyMap(), mock(ServicesManager.class));
    val factory = new SurrogateAuthenticationRestHttpRequestCredentialFactory(service, casProperties.getAuthn().getSurrogate());
    val results = factory.fromRequest(request, requestBody);
    assertFalse(results.isEmpty());
    assertFalse(results.get(0) instanceof SurrogateUsernamePasswordCredential);
    assertTrue(results.get(0) instanceof UsernamePasswordCredential);
    val credential = (UsernamePasswordCredential) results.get(0);
    assertNotNull(credential);
    assertEquals("test", credential.getUsername());
}
Also used : lombok.val(lombok.val) ServicesManager(org.apereo.cas.services.ServicesManager) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SimpleSurrogateAuthenticationService(org.apereo.cas.authentication.surrogate.SimpleSurrogateAuthenticationService) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 87 with UsernamePasswordCredential

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

the class LoadSurrogatesListAction method loadSurrogates.

private boolean loadSurrogates(final RequestContext requestContext) {
    val c = WebUtils.getCredential(requestContext);
    if (c instanceof UsernamePasswordCredential) {
        val username = c.getId();
        LOGGER.debug("Loading eligible accounts for [{}] to proxy", username);
        val surrogates = surrogateService.getEligibleAccountsForSurrogateToProxy(username).stream().sorted().distinct().collect(Collectors.toCollection(ArrayList::new));
        LOGGER.debug("Surrogate accounts found are [{}]", surrogates);
        if (!surrogates.isEmpty()) {
            if (!surrogates.contains(username)) {
                surrogates.add(0, username);
            }
            WebUtils.putSurrogateAuthenticationAccounts(requestContext, surrogates);
            return true;
        }
        LOGGER.debug("No surrogate accounts could be located for [{}]", username);
    } else {
        LOGGER.debug("Current credential in the webflow is not one of [{}]", UsernamePasswordCredential.class.getName());
    }
    return false;
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)

Example 88 with UsernamePasswordCredential

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

the class JcifsSpnegoAuthenticationHandlerTests method verifySupports.

@Test
public void verifySupports() {
    val authenticationHandler = new JcifsSpnegoAuthenticationHandler(StringUtils.EMPTY, null, null, CollectionUtils.wrapList(new MockJcifsAuthentication()), true, true, null);
    assertFalse(authenticationHandler.supports((SpnegoCredential) null));
    assertTrue(authenticationHandler.supports(new SpnegoCredential(new byte[] { 0, 1, 2 })));
    assertFalse(authenticationHandler.supports(new UsernamePasswordCredential()));
}
Also used : lombok.val(lombok.val) SpnegoCredential(org.apereo.cas.support.spnego.authentication.principal.SpnegoCredential) MockJcifsAuthentication(org.apereo.cas.support.spnego.MockJcifsAuthentication) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 89 with UsernamePasswordCredential

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

the class CasSimpleMultifactorAuthenticationHandlerTests method verifyFailsPrincipal.

@Test
public void verifyFailsPrincipal() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    val factory = (CasSimpleMultifactorAuthenticationTicketFactory) defaultTicketFactory.get(CasSimpleMultifactorAuthenticationTicket.class);
    val ticket = factory.create(RegisteredServiceTestUtils.getService(), Map.of());
    ticketRegistry.addTicket(ticket);
    val credential = new CasSimpleMultifactorTokenCredential(ticket.getId());
    assertThrows(FailedLoginException.class, () -> casSimpleMultifactorAuthenticationHandler.authenticate(credential));
    assertFalse(casSimpleMultifactorAuthenticationHandler.supports(new UsernamePasswordCredential()));
    assertFalse(casSimpleMultifactorAuthenticationHandler.supports(UsernamePasswordCredential.class));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) CasSimpleMultifactorAuthenticationTicket(org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicket) CasSimpleMultifactorAuthenticationTicketFactory(org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicketFactory) MockRequestContext(org.springframework.webflow.test.MockRequestContext) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) 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 90 with UsernamePasswordCredential

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

the class BaseThrottledSubmissionHandlerInterceptorAdapterTests method badCredentials.

private static UsernamePasswordCredential badCredentials(final String username) {
    val credentials = new UsernamePasswordCredential();
    credentials.setUsername(username);
    credentials.setPassword("badpassword");
    return credentials;
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

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