Search in sources :

Example 1 with CasRestProfile

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);
}
Also used : CasProfile(org.pac4j.cas.profile.CasProfile) MockWebContext(org.pac4j.core.context.MockWebContext) CasRestProfile(org.pac4j.cas.profile.CasRestProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) TokenCredentials(org.pac4j.core.credentials.TokenCredentials)

Example 2 with CasRestProfile

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");
}
Also used : CasProfile(org.pac4j.cas.profile.CasProfile) MockWebContext(org.pac4j.core.context.MockWebContext) CasRestProfile(org.pac4j.cas.profile.CasRestProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) TokenCredentials(org.pac4j.core.credentials.TokenCredentials)

Aggregations

CasProfile (org.pac4j.cas.profile.CasProfile)2 CasRestProfile (org.pac4j.cas.profile.CasRestProfile)2 MockWebContext (org.pac4j.core.context.MockWebContext)2 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)2 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)2