如果有人能提供帮助,那将不胜感激。我是 Kerberos 的新手,不确定这是否是一个明显的问题,请原谅我的新手。
我在 Kerberos 配置的 Windows 机器上。两个用户 user1 和 user2 有权限。
下面是我的 Java 代码:
System.setProperty("java.security.krb5.conf", "\lib\security\
System.setProperty("java.security.auth.login.config", "jaas.conf");
/*
* Content of jaas.conf:
* JAAS {
* com.sun.security.auth.module.Krb5LoginModule required
* useTicketCache=true debug=true;
* };
*/
// kinit of user1
// Content of kinituser1.bat: "<JRE Path>\bin\kinit.exe" -A -k -t "/user1.keytab" "<user1 principal>"
String[] cmdScript1 = new String[]{"kinituser1.bat"};
Process procScript1 = Runtime.getRuntime().exec(cmdScript1);
LoginContext context1 = AccessController.doPrivileged(
new PrivilegedExceptionAction<LoginContext>() {
public LoginContext run() throws LoginException {
return new LoginContext("JAAS");
}
});
context1.login();
Subject subject1 = context1.getSubject();
System.out.println("Connected as:" + subject1); // This returns the expected user1 user ticket.
context1.logout();
// kinit of user2
// Content of kinituser1.bat: "<JRE Path>\bin\kinit.exe" -A -k -t "/user2.keytab" "<user2 principal>"
String[] cmdScript2 = new String[]{"kinituser2.bat"};
Process procScript2 = Runtime.getRuntime().exec(cmdScript2);
LoginContext context2 = AccessController.doPrivileged(
new PrivilegedExceptionAction<LoginContext>() {
public LoginContext run() throws LoginException {
return new LoginContext("JAAS");
}
});
context2.login();
Subject subject2 = context2.getSubject();
System.out.println("Connected as:" + subject2); // Here we are seeing the issue: This is still returning user1 ticket subject, I was expecting user2 here.
context2.logout();
在运行上面的应用程序时,尽管在执行 kinituser2.bat 后缓存与 user2 一起刷新,但我在 context2 主题中获取 user1 票证缓存。 如果我交换 user1 和 user2,则两种情况都会返回 user2 的票证详细信息。这给人的印象是,无论票证缓存是否与其他用户票证一起更新,初始用户票证总是返回用于以后的 LoginContext。
有人遇到过上面这样的脸吗? 有人可以告诉我我是否失踪或做错了什么吗?