use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class FormClientTests method testGetUserProfile.
@Test
public void testGetUserProfile() {
final var formClient = getFormClient();
formClient.setProfileCreator((credentials, context, session) -> {
var username = ((UsernamePasswordCredentials) credentials).getUsername();
final var profile = new CommonProfile();
profile.setId(username);
profile.addAttribute(Pac4jConstants.USERNAME, username);
return Optional.of(profile);
});
final var context = MockWebContext.create();
final var profile = (CommonProfile) formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context, new MockSessionStore()).get();
assertEquals(USERNAME, profile.getId());
assertEquals(CommonProfile.class.getName() + Pac4jConstants.TYPED_ID_SEPARATOR + USERNAME, profile.getTypedId());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class));
assertEquals(USERNAME, profile.getUsername());
assertEquals(1, profile.getAttributes().size());
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class IndirectBasicAuthClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var basicAuthClient = new IndirectBasicAuthClient(NAME, new SimpleTestUsernamePasswordAuthenticator());
basicAuthClient.setCallbackUrl(CALLBACK_URL);
basicAuthClient.setProfileCreator(null);
TestsHelper.expectException(() -> basicAuthClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class RestAuthenticatorIT method testNotFound.
@Test
public void testNotFound() {
final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=notfound");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
final var profile = (RestProfile) credentials.getUserProfile();
assertNull(profile);
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class RestAuthenticatorIT method testProfileOk.
@Test
public void testProfileOk() {
final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=ok");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
final var profile = (RestProfile) credentials.getUserProfile();
assertNotNull(profile);
assertEquals(ID, profile.getId());
assertEquals(1, profile.getRoles().size());
assertEquals(ROLE, profile.getRoles().iterator().next());
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class RestAuthenticatorIT method testHttps.
@Test
public void testHttps() {
final var authenticator = new RestAuthenticator("https://www.google.com");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
}
Aggregations