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