use of org.pac4j.kerberos.credentials.KerberosCredentials 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.kerberos.credentials.KerberosCredentials in project pac4j by pac4j.
the class KerberosClientTests method testMissingKerberosHeader.
@Test
public void testMissingKerberosHeader() {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
final DirectKerberosClient client = new DirectKerberosClient(new KerberosAuthenticator(krbValidator));
KerberosCredentials credentials = client.getCredentials(new J2EContext(request, response));
assertNull(credentials);
}
use of org.pac4j.kerberos.credentials.KerberosCredentials 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.kerberos.credentials.KerberosCredentials in project pac4j by pac4j.
the class IndirectKerberosClient method retrieveCredentials.
@Override
protected KerberosCredentials retrieveCredentials(final WebContext context) {
CommonHelper.assertNotNull("credentialsExtractor", getCredentialsExtractor());
CommonHelper.assertNotNull("authenticator", getAuthenticator());
// set the www-authenticate in case of error
context.setResponseHeader(HttpConstants.AUTHENTICATE_HEADER, "Negotiate");
final KerberosCredentials credentials;
try {
// retrieve credentials
credentials = getCredentialsExtractor().extract(context);
logger.debug("kerberos credentials : {}", credentials);
if (credentials == null) {
throw HttpAction.unauthorized(context);
}
// validate credentials
getAuthenticator().validate(credentials, context);
} catch (final CredentialsException e) {
throw HttpAction.unauthorized(context);
}
return credentials;
}
Aggregations