use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectCasClientTests method testTicketExistsValidationOccurs.
@Test
public void testTicketExistsValidationOccurs() {
final CasConfiguration configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
configuration.setDefaultTicketValidator((ticket, service) -> {
if (TICKET.equals(ticket) && CALLBACK_URL.equals(service)) {
return new AssertionImpl(TICKET);
}
throw new TechnicalException("Bad ticket or service");
});
final DirectCasClient client = new DirectCasClient(configuration);
final MockWebContext context = MockWebContext.create();
context.setFullRequestURL(CALLBACK_URL + "?" + CasConfiguration.TICKET_PARAMETER + "=" + TICKET);
context.addRequestParameter(CasConfiguration.TICKET_PARAMETER, TICKET);
final TokenCredentials credentials = client.getCredentials(context);
assertEquals(TICKET, credentials.getToken());
final CommonProfile profile = credentials.getUserProfile();
assertTrue(profile instanceof CasProfile);
assertEquals(TICKET, profile.getId());
}
use of org.pac4j.core.context.MockWebContext 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.core.context.MockWebContext in project pac4j by pac4j.
the class KerberosClientTests method testAuthentication.
@Test
public void testAuthentication() {
when(krbValidator.validateTicket(any())).thenReturn(new KerberosTicketValidation("garry", null, null, null));
final DirectKerberosClient client = new DirectKerberosClient(new KerberosAuthenticator(krbValidator));
final MockWebContext context = MockWebContext.create();
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Negotiate " + new String(KERBEROS_TICKET, StandardCharsets.UTF_8));
final KerberosCredentials credentials = client.getCredentials(context);
assertEquals(new String(Base64.getDecoder().decode(KERBEROS_TICKET), StandardCharsets.UTF_8), new String(credentials.getKerberosTicket(), StandardCharsets.UTF_8));
final CommonProfile profile = client.getUserProfile(credentials, context);
assertEquals("garry", profile.getId());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class KerberosClientsKerbyTests method mockWebRequestContext.
private MockWebContext mockWebRequestContext(String spnegoWebTicket) {
System.out.println("spnegoWebTicket:" + spnegoWebTicket);
final MockWebContext context = MockWebContext.create();
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Negotiate " + spnegoWebTicket);
return context;
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class KerberosClientsKerbyTests method testDirectIncorrectAuth.
// =====================
// Indirect client below
// =====================
@Test
public void testDirectIncorrectAuth() {
// a request with an incorrect Kerberos token, yields NULL credentials also
final MockWebContext context = MockWebContext.create().addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Negotiate " + "AAAbbAA123");
assertNull(setupDirectKerberosClient().getCredentials(context));
}
Aggregations