sig.addResourceResolver(EnvelopeIdResolver.getInstance());
KeyInfo info = sig.getKeyInfo();
SecretKey secretKey = null;
KerberosTokenPrincipal principal = null;
if (info != null) {
org.w3c.dom.Node node = WSSecurityUtil.getDirectChild(
info.getElement(), "SecurityTokenReference",
WSConstants.WSSE_NS);
if (node == null) {
throw new WSSecurityException(3, "unsupportedKeyInfo");
}
SecurityTokenReference secRef = new SecurityTokenReference(
(Element) node);
WSDocInfo wsDocInfo = WSDocInfoStore
.lookup(elem.getOwnerDocument());
if (secRef.containsReference()) {
Element token = secRef.getTokenElement(elem.getOwnerDocument(),
wsDocInfo, cb);
QName el = new QName(token.getNamespaceURI(),
token.getLocalName());
if (el.equals(WSSecurityEngine.binaryToken))
try {
if (lastPrincipalFound == null) {
authenticate(cb);
KerberosSecurity ks = createSecurityToken(token);
GSSContext context = acceptSecurityContext(ks);
secretKey = getSessionKey(ks.getToken());
if (log.isDebugEnabled()) {
log.debug("security context accepted with "
+ context.getSrcName().toString()
+ ","
+ context.getSrcName()
.getStringNameType());
}
principal = new KerberosTokenPrincipal(context
.getSrcName().toString());
principal.setTokenElement(token);
principal.setSessionKey(secretKey.getEncoded());
principal.setSecretKey(secretKey);
KrbSession kerberosSession = new KrbSession(
ks.getSHA1(), secretKey);
kerberosSession.setClientPrincipalName(context
.getSrcName().toString());
kerberosSession.setServerPrincipalName(context
.getTargName().toString());
KrbSessionCache.getInstance().addSession(
kerberosSession);
principal.setClientPrincipalName(kerberosSession
.getClientPrincipalName());
principal.setServicePrincipalName(kerberosSession
.getServerPrincipalName());
} else {
secretKey = lastPrincipalFound.getSecretKey();
}
} catch (RuntimeException e) {