use of org.pac4j.cas.profile.CasRestProfile in project pac4j by pac4j.
the class CasRestClientIT method internalTestRestForm.
private void internalTestRestForm(final Authenticator authenticator) {
final CasRestFormClient client = new CasRestFormClient();
client.setConfiguration(getConfig());
client.setAuthenticator(authenticator);
final MockWebContext context = MockWebContext.create();
context.addRequestParameter(client.getUsernameParameter(), USER);
context.addRequestParameter(client.getPasswordParameter(), USER);
final UsernamePasswordCredentials credentials = client.getCredentials(context);
final CasRestProfile profile = client.getUserProfile(credentials, context);
assertEquals(USER, profile.getId());
assertNotNull(profile.getTicketGrantingTicketId());
final TokenCredentials casCreds = client.requestServiceTicket(PAC4J_BASE_URL, profile, context);
final CasProfile casProfile = client.validateServiceTicket(PAC4J_BASE_URL, casCreds, context);
assertNotNull(casProfile);
assertEquals(USER, casProfile.getId());
assertTrue(casProfile.getAttributes().size() > 0);
}
use of org.pac4j.cas.profile.CasRestProfile in project pac4j by pac4j.
the class CasRestClientIT method internalTestRestBasic.
private void internalTestRestBasic(final CasRestBasicAuthClient client, int nbAttributes) {
final MockWebContext context = MockWebContext.create();
final String token = USER + ":" + USER;
context.addRequestHeader(VALUE, NAME + Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8)));
final UsernamePasswordCredentials credentials = client.getCredentials(context);
final CasRestProfile profile = client.getUserProfile(credentials, context);
assertEquals(USER, profile.getId());
assertNotNull(profile.getTicketGrantingTicketId());
final TokenCredentials casCreds = client.requestServiceTicket(PAC4J_BASE_URL, profile, context);
final CasProfile casProfile = client.validateServiceTicket(PAC4J_BASE_URL, casCreds, context);
assertNotNull(casProfile);
assertEquals(USER, casProfile.getId());
assertEquals(nbAttributes, casProfile.getAttributes().size());
client.destroyTicketGrantingTicket(profile, context);
TestsHelper.expectException(() -> client.requestServiceTicket(PAC4J_BASE_URL, profile, context), TechnicalException.class, "Service ticket request for `#CasRestProfile# | id: " + USER + " | attributes: {} | roles: [] | permissions: [] | " + "isRemembered: false | clientName: CasRestBasicAuthClient | linkedId: null |` failed: (404) Not Found");
}
Aggregations