![](/img/trans.png)
[英]Java and Kerberos authentication krb5.conf versus System.setProperty
[英]Updating the kerberors krb.conf file using “java.security.krb5.conf” System.property() is not working
我想動態地指向不同的 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;
};
出於明顯的原因,我設置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" });
}
}
admin
的緩存已創建,但newAdmin
的緩存未創建,因為相應的 krb.conf 文件具有不同的領域,並且 JAAS 似乎無法從 new.krb.conf 連接到realm並因此失敗帶有臭名昭著的 906 錯誤代碼。
我做錯了什么? 我想實現的可能嗎? 我應該如何解決這個問題?
另請注意,如果我完全注釋了管理緩存創建邏輯並從 new.krb.conf(與 newAdmin 相關的所有代碼)開始,它工作得非常好,並為 newAdmin 創建緩存
你應該調用sun.security.krb5.Config.refresh();
為了從新文件重新加載配置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.