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);
}
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();
}
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;
}
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;
}
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());
}
Aggregations