use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class KerberosClientsKerbyTests method checkWithGoodTicket.
private void checkWithGoodTicket(Client<KerberosCredentials, KerberosProfile> client) throws Exception {
String spnegoWebTicket = SpnegoServiceTicketHelper.getGSSTicket(clientPrincipal, clientPassword, serviceName);
// mock web request
final MockWebContext context = mockWebRequestContext(spnegoWebTicket);
final KerberosCredentials credentials = client.getCredentials(context);
assertNotNull(credentials);
System.out.println(credentials);
final KerberosProfile profile = client.getUserProfile(credentials, context);
assertNotNull(profile);
assertEquals(clientPrincipal, profile.getId());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class IpExtractorTests method testRetrieveIpOk.
@Test
public void testRetrieveIpOk() {
final MockWebContext context = MockWebContext.create().setRemoteAddress(GOOD_IP);
final TokenCredentials credentials = extractor.extract(context);
assertEquals(GOOD_IP, credentials.getToken());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class ParameterExtractorTests method testRetrieveGetParameterNotSupported.
@Test
public void testRetrieveGetParameterNotSupported() {
final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.GET.name()).addRequestParameter(GOOD_PARAMETER, VALUE);
TestsHelper.expectException(() -> postExtractor.extract(context), CredentialsException.class, "GET requests not supported");
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class ParameterExtractorTests method testRetrievePostParameterOk.
@Test
public void testRetrievePostParameterOk() {
final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.POST.name()).addRequestParameter(GOOD_PARAMETER, VALUE);
final TokenCredentials credentials = postExtractor.extract(context);
assertEquals(VALUE, credentials.getToken());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CsrfAuthorizerTests method testNoTokenCheckAll.
@Test
public void testNoTokenCheckAll() {
final MockWebContext context = MockWebContext.create().addSessionAttribute(Pac4jConstants.CSRF_TOKEN, VALUE);
authorizer.setOnlyCheckPostRequest(true);
Assert.assertTrue(authorizer.isAuthorized(context, null));
}
Aggregations