Search in sources :

Example 1 with KerberosTicketValidation

use of org.pac4j.kerberos.credentials.authenticator.KerberosTicketValidation 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());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) KerberosAuthenticator(org.pac4j.kerberos.credentials.authenticator.KerberosAuthenticator) CommonProfile(org.pac4j.core.profile.CommonProfile) KerberosCredentials(org.pac4j.kerberos.credentials.KerberosCredentials) KerberosTicketValidation(org.pac4j.kerberos.credentials.authenticator.KerberosTicketValidation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MockWebContext (org.pac4j.core.context.MockWebContext)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1 KerberosCredentials (org.pac4j.kerberos.credentials.KerberosCredentials)1 KerberosAuthenticator (org.pac4j.kerberos.credentials.authenticator.KerberosAuthenticator)1 KerberosTicketValidation (org.pac4j.kerberos.credentials.authenticator.KerberosTicketValidation)1