// Validate the ticket
KerberosServiceExceptionAction action =
new KerberosServiceExceptionAction(token, service,
isUsernameServiceNameForm(), spnego);
KerberosServiceContext krbServiceCtx = null;
try {
krbServiceCtx = Subject.doAs(subject, action);
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause instanceof WSSecurityException) {
throw (WSSecurityException) cause;
} else {
throw new WSSecurityException(
ErrorCode.FAILURE, "kerberosTicketValidationError", new Object[] {}, cause
);
}
}
credential.setPrincipal(krbServiceCtx.getPrincipal());
credential.setDelegationCredential(krbServiceCtx.getDelegationCredential());
// Check to see if the session key is available in KerberosServiceContext
LOG.debug("Trying to obtain the Session Key from the KerberosServiceContext.");
Key sessionKey = krbServiceCtx.getSessionKey();
if (null != sessionKey) {
LOG.debug("Found session key in the KerberosServiceContext.");
credential.setSecretKey(sessionKey.getEncoded());
} else {
LOG.debug("Session key is not found in the KerberosServiceContext.");