Search in sources :

Example 11 with UsernamePasswordCredentials

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

the class DbProfileServiceTests method login.

private UsernamePasswordCredentials login(final String username, final String password, final String attribute) {
    final DbProfileService dbProfileService = new DbProfileService(ds, attribute);
    dbProfileService.setPasswordEncoder(DbServer.PASSWORD_ENCODER);
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    dbProfileService.validate(credentials, null);
    return credentials;
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 12 with UsernamePasswordCredentials

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

the class DirectFormClientTests method testGetUserProfile.

@Test
public void testGetUserProfile() {
    final DirectFormClient formClient = getFormClient();
    formClient.setProfileCreator((credentials, context) -> {
        String username = credentials.getUsername();
        final CommonProfile profile = new CommonProfile();
        profile.setId(username);
        profile.addAttribute(Pac4jConstants.USERNAME, username);
        return profile;
    });
    final MockWebContext context = MockWebContext.create();
    final CommonProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context);
    assertEquals(USERNAME, profile.getId());
    assertEquals(CommonProfile.class.getName() + CommonProfile.SEPARATOR + USERNAME, profile.getTypedId());
    assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class));
    assertEquals(USERNAME, profile.getUsername());
    assertEquals(1, profile.getAttributes().size());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CommonProfile(org.pac4j.core.profile.CommonProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 13 with UsernamePasswordCredentials

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

the class FormClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final FormClient formClient = new FormClient(LOGIN_URL, new SimpleTestUsernamePasswordAuthenticator());
    formClient.setCallbackUrl(CALLBACK_URL);
    formClient.setProfileCreator(null);
    TestsHelper.expectException(() -> formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null");
}
Also used : SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 14 with UsernamePasswordCredentials

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

the class FormClientTests method testGetRightCredentials.

@Test
public void testGetRightCredentials() {
    final FormClient formClient = getFormClient();
    final UsernamePasswordCredentials credentials = formClient.getCredentials(MockWebContext.create().addRequestParameter(formClient.getUsernameParameter(), USERNAME).addRequestParameter(formClient.getPasswordParameter(), USERNAME));
    assertEquals(USERNAME, credentials.getUsername());
    assertEquals(USERNAME, credentials.getPassword());
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 15 with UsernamePasswordCredentials

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

the class IndirectBasicAuthClientTests method testGetCredentialsGoodCredentials.

@Test
public void testGetCredentialsGoodCredentials() {
    final IndirectBasicAuthClient basicAuthClient = getBasicAuthClient();
    final String header = USERNAME + ":" + USERNAME;
    final UsernamePasswordCredentials credentials = basicAuthClient.getCredentials(getContextWithAuthorizationHeader("Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8))));
    assertEquals(USERNAME, credentials.getUsername());
    assertEquals(USERNAME, credentials.getPassword());
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Aggregations

UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)80 lombok.val (lombok.val)34 JEEContext (org.pac4j.core.context.JEEContext)24 CommonProfile (org.pac4j.core.profile.CommonProfile)22 Test (org.junit.Test)21 Test (org.junit.jupiter.api.Test)21 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)20 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)20 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)10 BasicAuthExtractor (org.pac4j.core.credentials.extractor.BasicAuthExtractor)9 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)6 Map (java.util.Map)5 MockWebContext (org.pac4j.core.context.MockWebContext)5 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)4 CredentialsException (org.pac4j.core.exception.CredentialsException)4 ArrayList (java.util.ArrayList)3 WebContext (org.pac4j.core.context.WebContext)3