Search in sources :

Example 71 with UsernamePasswordCredentials

use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.

the class LocalCachingAuthenticatorTests method testDoubleCalls.

@Test
public void testDoubleCalls() {
    final var authenticator = new OnlyOneCallAuthenticator();
    final var localCachingAuthenticator = new LocalCachingAuthenticator(authenticator, 10, 10, TimeUnit.SECONDS);
    localCachingAuthenticator.init();
    final Credentials credentials1 = new UsernamePasswordCredentials("a", "a");
    localCachingAuthenticator.validate(credentials1, null, null);
    final Credentials credentials2 = new UsernamePasswordCredentials("a", "a");
    localCachingAuthenticator.validate(credentials2, null, null);
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Credentials(org.pac4j.core.credentials.Credentials) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 72 with UsernamePasswordCredentials

use of org.pac4j.core.credentials.UsernamePasswordCredentials in project cas by apereo.

the class RegisteredServiceResource method authenticateRequest.

private Authentication authenticateRequest(final HttpServletRequest request, final HttpServletResponse response) {
    val extractor = new BasicAuthExtractor();
    val webContext = new JEEContext(request, response);
    val credentialsResult = extractor.extract(webContext, JEESessionStore.INSTANCE);
    val credentials = (UsernamePasswordCredentials) credentialsResult.get();
    LOGGER.debug("Received basic authentication request from credentials [{}]", credentials);
    val c = new UsernamePasswordCredential(credentials.getUsername(), credentials.getPassword());
    val serviceRequest = this.serviceFactory.createService(request);
    val result = authenticationSystemSupport.finalizeAuthenticationTransaction(serviceRequest, c);
    if (result == null) {
        throw new BadRestRequestException("Unable to establish authentication using provided credentials for " + c.getUsername());
    }
    return result.getAuthentication();
}
Also used : lombok.val(lombok.val) BasicAuthExtractor(org.pac4j.core.credentials.extractor.BasicAuthExtractor) JEEContext(org.pac4j.jee.context.JEEContext) BadRestRequestException(org.apereo.cas.rest.BadRestRequestException) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 73 with UsernamePasswordCredentials

use of org.pac4j.core.credentials.UsernamePasswordCredentials in project cas by apereo.

the class OidcClientSecretJwtAuthenticatorTests method getCredentials.

private UsernamePasswordCredentials getCredentials(final MockHttpServletRequest request, final String uid, final String password, final String clientId) throws Exception {
    val credentials = new UsernamePasswordCredentials(uid, password);
    val code = defaultOAuthCodeFactory.create(RegisteredServiceTestUtils.getService(), RegisteredServiceTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), new ArrayList<>(), StringUtils.EMPTY, StringUtils.EMPTY, clientId, new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
    ticketRegistry.addTicket(code);
    request.addParameter(OAuth20Constants.CODE, code.getId());
    return credentials;
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 74 with UsernamePasswordCredentials

use of org.pac4j.core.credentials.UsernamePasswordCredentials in project cas by apereo.

the class OidcPrivateKeyJwtAuthenticatorTests method getCredential.

private UsernamePasswordCredentials getCredential(final MockHttpServletRequest request, final String uid, final String password, final String clientId) throws Exception {
    val credentials = new UsernamePasswordCredentials(uid, password);
    val code = defaultOAuthCodeFactory.create(RegisteredServiceTestUtils.getService(), RegisteredServiceTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), new ArrayList<>(), StringUtils.EMPTY, StringUtils.EMPTY, clientId, new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
    ticketRegistry.addTicket(code);
    request.addParameter(OAuth20Constants.CODE, code.getId());
    return credentials;
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 75 with UsernamePasswordCredentials

use of org.pac4j.core.credentials.UsernamePasswordCredentials in project cas by apereo.

the class OidcPrivateKeyJwtAuthenticatorTests method verifyBadCred.

@Test
public void verifyBadCred() {
    val auth = getAuthenticator();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    val credentials = new UsernamePasswordCredentials(OAuth20Constants.CLIENT_ASSERTION_TYPE_JWT_BEARER, null);
    auth.validate(credentials, context, JEESessionStore.INSTANCE);
    assertNull(credentials.getUserProfile());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.jee.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.jupiter.api.Test)

Aggregations

UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)91 lombok.val (lombok.val)35 Test (org.junit.Test)25 JEEContext (org.pac4j.jee.context.JEEContext)24 CommonProfile (org.pac4j.core.profile.CommonProfile)23 Test (org.junit.jupiter.api.Test)21 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)21 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)21 MockSessionStore (org.pac4j.core.context.session.MockSessionStore)17 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)10 BasicAuthExtractor (org.pac4j.core.credentials.extractor.BasicAuthExtractor)10 OAuth20DefaultCode (org.apereo.cas.ticket.code.OAuth20DefaultCode)8 HardTimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy)8 HashMap (java.util.HashMap)7 SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)7 Map (java.util.Map)6 WebContext (org.pac4j.core.context.WebContext)5 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)4 CasRestProfile (org.pac4j.cas.profile.CasRestProfile)4 CredentialsException (org.pac4j.core.exception.CredentialsException)4