nee*_*rle 5 java kerberos jaas java.security
我想指向一个不同的 krb.conf 文件,dynamically, without restarting the JVM. 我在 Stackoverflow 上搜索了不同的解决方案,并尝试相应地实施该解决方案。但是有些方法,即使我更新 System.property("java.security.krb5.conf", ...)以指向the new krb.conf file,JAAS 也无法理解这一点并且仍然使用早期的 conf 文件。以下是我使用代码的解决方案的详细信息:
我的 Jaas.conf 文件如下:
Mutual {
com.sun.security.auth.module.Krb5LoginModule required client=TRUE;
};
sp.kerb.sso.KinitExample {
com.sun.security.auth.module.Krb5LoginModule required
client=TRUE
refreshKrb5Config=true
debug=true;
};
Run Code Online (Sandbox Code Playgroud)
我refreshKrb5Config=true出于显而易见的原因进行了设置,因为我想重新加载 krb 配置文件。
这是我试图执行的代码:package sp.kerb.sso;
import sun.security.krb5.internal.tools.Kinit;
public class KinitExample {
public static void main(String[] args) {
String kerberosFileName = "C:\\Windows\\krb5.ini";
String jaas_config_file_name = "C:\\Users\\User1\\temp\\howrah.jaas.conf";
System.setProperty("java.security.auth.login.config", jaas_config_file_name); // setting the jaas config file
System.setProperty("java.security.krb5.conf" , kerberosFileName); // setting the kerberos file
System.setProperty("java.security.krb5.debug" , "true");
final String administrator = "admin@exampledomain.lab".toUpperCase();
String cacheFileLoc = "C:\\Users\\User1\\temp\\admin.cache";
// Perfoming Kinit ...
Kinit.main(new String[]{"-c",cacheFileLoc, administrator , "Password123" });
kerberosFileName = "C:\\Users\\User2\\temp\\new.krb.conf"; // Using new KRB configuration file
System.setProperty("java.security.krb5.debug" , "true");
System.setProperty("java.security.auth.login.config", jaas_config_file_name); // setting the property again
System.setProperty("java.security.krb5.conf" , kerberosFileName); // setting the property again
System.out.println(System.getProperty("java.security.krb5.conf")); // Prints the updated conf file location.
cacheFileLoc = "C:\\Users\\User2\\temp\\newadmin.cache";
String newAdmin = "administrator@test.lab".toUpperCase();
Kinit.main(new String[]{"-c",cacheFileLoc, newAdmin , "Password123" });
}
}
Run Code Online (Sandbox Code Playgroud)
对于缓存admin被创建,但对于高速缓存newAdmin未创建作为各自krb.conf文件具有完全不同的领域和JAAS似乎并没有能够连接到从境界不new.krb.conf,并且因此不会与臭名昭著的 906 错误代码。
我做错了什么?我想要达到的目标是可能的吗?我应该如何解决这个问题?
另请注意,如果我完全评论管理缓存创建逻辑并从 new.krb.conf(与 newAdmin 相关的所有代码)开始,它运行良好并为 newAdmin 创建缓存