我被要求研究从 IBM WAS 7 下的 Web 应用程序中移植一些代码,以便它可以在 Tomcat 7 下运行。
这是更大的 SPNEGO/Kerberos SSO 系统的一部分,但出于讨论的目的,我将代码提炼为以下代码,显示了对两个 WebSphere 类 AccessController 和 WSSubject 的依赖关系:
GSSCredential clientCreds = (GSSCredential) com.ibm.ws.security.util.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
javax.security.auth.Subject subject = com.ibm.websphere.security.auth.WSSubject.getCallerSubject();
GSSCredential clientCreds = (GSSCredential) subject.getPrivateCredentials(GSSCredential.class).iterator().next();
return clientCreds;
}
});
我希望能够在Tomcat中做到这一点。
[编辑] 我认为上面的蒸馏代码可能没有清楚地解释需要什么。我不需要配置 Tomcat 来控制对 Web 应用程序的访问,也不需要模拟远程用户。我真正需要的是未加密的 Kerberos 票证,以便我可以将其传递给另一个将完成身份验证的进程。这是一个更完整的片段:
com.ibm.ws.security.util.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2");
Oid krb5PrincipalNameType = new Oid("1.2.840.113554.1.2.2.1");
GSSManager manager = GSSManager.getInstance();
GSSName serverName = manager.createName("HOST/my.host.org", krb5PrincipalNameType);
javax.security.auth.Subject subject = com.ibm.websphere.security.auth.WSSubject.getCallerSubject();
GSSCredential clientCreds = (GSSCredential) subject.getPrivateCredentials(GSSCredential.class).iterator().next();
GSSContext secContext = manager.createContext(serverName, krb5Mechanism, clientCreds, GSSContext.DEFAULT_LIFETIME);
// After this the Kerberos ticket is extracted from secContext, converted to a String and passed to the other process for authentication
}
});