use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class KerberosClientTests method testMissingKerberosHeader.
@Test
public void testMissingKerberosHeader() {
final var client = new DirectKerberosClient(new KerberosAuthenticator(krbValidator));
final var credentials = client.getCredentials(MockWebContext.create(), new MockSessionStore());
assertFalse(credentials.isPresent());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class KerberosClientTests method testWWWAuthenticateNegotiateHeaderIsSetToTriggerSPNEGOWhenNoCredentialsAreFound.
@Test
public void testWWWAuthenticateNegotiateHeaderIsSetToTriggerSPNEGOWhenNoCredentialsAreFound() {
final WebContext context = MockWebContext.create();
final var client = new DirectKerberosClient(new KerberosAuthenticator(krbValidator));
final var credentials = client.getCredentials(context, new MockSessionStore());
assertFalse(credentials.isPresent());
assertEquals("Negotiate", context.getResponseHeader(HttpConstants.AUTHENTICATE_HEADER).get());
}
use of org.pac4j.core.context.session.MockSessionStore 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 var client = new DirectKerberosClient(new KerberosAuthenticator(krbValidator));
final var context = MockWebContext.create();
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Negotiate " + new String(KERBEROS_TICKET, StandardCharsets.UTF_8));
final var credentials = (KerberosCredentials) client.getCredentials(context, new MockSessionStore()).get();
assertEquals(new String(Base64.getDecoder().decode(KERBEROS_TICKET), StandardCharsets.UTF_8), new String(credentials.getKerberosTicket(), StandardCharsets.UTF_8));
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals("garry", profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class KerberosClientsKerbyTests method assertGetCredentialsFailsWithAuthRequired.
// ===============================
// Test helpers
// ===============================
private void assertGetCredentialsFailsWithAuthRequired(IndirectKerberosClient kerbClient, MockWebContext context, String expectedMsg) {
try {
kerbClient.getCredentials(context, new MockSessionStore());
fail("should throw HttpAction");
} catch (final HttpAction e) {
assertEquals(401, e.getCode());
assertEquals("Negotiate", context.getResponseHeaders().get(HttpConstants.AUTHENTICATE_HEADER));
assertEquals(expectedMsg, e.getMessage());
}
}
use of org.pac4j.core.context.session.MockSessionStore 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 var context = MockWebContext.create().addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Negotiate " + "AAAbbAA123");
assertFalse(setupDirectKerberosClient().getCredentials(context, new MockSessionStore()).isPresent());
}
Aggregations