Search in sources :

Example 6 with UsernamePasswordCredentials

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

the class LdapProfileServiceTests method authentFailed.

@Test(expected = BadCredentialsException.class)
public void authentFailed() {
    final LdapProfileService ldapProfileService = new LdapProfileService(connectionFactory, authenticator, LdapServer.BASE_PEOPLE_DN);
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(BAD_USERNAME, PASSWORD);
    ldapProfileService.validate(credentials, null);
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 7 with UsernamePasswordCredentials

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

the class MongoProfileServiceIT method login.

private UsernamePasswordCredentials login(final String username, final String password, final String attribute) {
    final MongoProfileService authenticator = new MongoProfileService(getClient(), attribute);
    authenticator.setPasswordEncoder(MongoServer.PASSWORD_ENCODER);
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    authenticator.validate(credentials, null);
    return credentials;
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 8 with UsernamePasswordCredentials

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

the class MongoProfileServiceIT method testNullPassword.

@Test
public void testNullPassword() {
    final MongoProfileService authenticator = new MongoProfileService(getClient(), FIRSTNAME, MongoServer.PASSWORD_ENCODER);
    authenticator.setPasswordAttribute(null);
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
    TestsHelper.expectException(() -> authenticator.validate(credentials, null), TechnicalException.class, "passwordAttribute cannot be blank");
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 9 with UsernamePasswordCredentials

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

the class MongoProfileServiceIT method testGoodUsernameNoAttribute.

@Test
public void testGoodUsernameNoAttribute() {
    final UsernamePasswordCredentials credentials = login(GOOD_USERNAME, PASSWORD, "");
    final CommonProfile profile = credentials.getUserProfile();
    assertNotNull(profile);
    assertTrue(profile instanceof MongoProfile);
    final MongoProfile dbProfile = (MongoProfile) profile;
    assertEquals(GOOD_USERNAME, dbProfile.getId());
    assertNull(dbProfile.getAttribute(FIRSTNAME));
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) MongoProfile(org.pac4j.mongo.profile.MongoProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 10 with UsernamePasswordCredentials

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

the class DbProfileServiceTests method testGoodUsernameAttribute.

@Test
public void testGoodUsernameAttribute() {
    final UsernamePasswordCredentials credentials = login(GOOD_USERNAME, PASSWORD, FIRSTNAME);
    final CommonProfile profile = credentials.getUserProfile();
    assertNotNull(profile);
    assertTrue(profile instanceof DbProfile);
    final DbProfile dbProfile = (DbProfile) profile;
    assertEquals(GOOD_USERNAME, dbProfile.getId());
    assertEquals(FIRSTNAME_VALUE, dbProfile.getAttribute(FIRSTNAME));
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) DbProfile(org.pac4j.sql.profile.DbProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

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