SecretKey secretKey = null;
KerberosTokenPrincipal principal = null;
try {
authenticate(handler);
KerberosSecurity ks = createSecurityToken(elem);
GSSContext context = acceptSecurityContext(ks);
secretKey = getSessionKey(ks.getToken());
if (log.isDebugEnabled()) {
log.debug((new StringBuilder())
.append("security context accepted with ")
.append(context.getSrcName().toString())
.append(",")
.append(context.getSrcName().getStringNameType()
.toString()).toString());
}
principal = new KerberosTokenPrincipal(context.getSrcName()
.toString());
principal.setTokenElement(elem);
if (secretKey != null) {
principal.setSessionKey(secretKey.getEncoded());
} else {
log.error("null secret key");
throw new WSSecurityException(3, "nullSecretKey",
new Object[] { "null secret key" });
}
principal.setSecretKey(secretKey);
KrbSession kerberosSession = new KrbSession(ks.getSHA1(), secretKey);
kerberosSession.setClientPrincipalName(context.getSrcName()
.toString());
kerberosSession.setServerPrincipalName(context.getTargName()
.toString());
KrbSessionCache.getInstance().addSession(kerberosSession);