use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class DirectFormClientTests method testGetGoodCredentials.
@Test
public void testGetGoodCredentials() {
final var formClient = getFormClient();
final var credentials = (UsernamePasswordCredentials) formClient.getCredentials(MockWebContext.create().addRequestParameter(formClient.getUsernameParameter(), USERNAME).addRequestParameter(formClient.getPasswordParameter(), USERNAME), new MockSessionStore()).get();
assertEquals(USERNAME, credentials.getUsername());
assertEquals(USERNAME, credentials.getPassword());
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class DirectFormClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var formClient = new DirectFormClient(new SimpleTestUsernamePasswordAuthenticator(), null);
TestsHelper.expectException(() -> formClient.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 DirectBasicAuthClientTests method testAuthentication.
@Test
public void testAuthentication() {
final var client = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
final var context = MockWebContext.create();
final var header = USERNAME + ":" + USERNAME;
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8)));
final var credentials = (UsernamePasswordCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals(USERNAME, profile.getId());
}
use of org.pac4j.core.credentials.UsernamePasswordCredentials in project pac4j by pac4j.
the class DirectBasicAuthClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var basicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator(), 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 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");
}
Aggregations