gpt4 book ai didi

java - 如何使用 keytab 在 LDAP 服务器中进行身份验证

转载 作者:行者123 更新时间:2023-12-01 20:00:10 40 4
gpt4 key购买 nike

是否有可能使用 keytab 文件创建 LdapContext 而不是直接提供凭据?所以我们假设我目前有这样的代码

Hashtable<String,String> env=new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,LDAP_PROVIDER_URL);
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,LDAP_PRINCIPAL);
env.put(Context.SECURITY_CREDENTIALS,LDAP_CREDENTIALS);
LdapContext ctx = new InitialLdapContext(env,null);

正如您所看到的,我手动指定了用户名和密码。那么指定 keytab 文件的正确方法是什么?

最佳答案

是的,您可以,而且效果非常好。看看我的DirContextSource库它将为您完成所有艰苦的工作:

DirContextSource.Builder builder = new DirContextSource.Builder("ldap://hostname");
builder.gssApiAuth("MyAlternativeEntryName");
DirContextSource contextSource = builder.build();
// try and catch block omitted for the sake of brevity,
// handle NamingException appropriately
DirContext context = contextSource.getDirContext();
// Perform operations
context.close();

确保您的 login.conf 配置了条目 MyAlternativeEntryName,如下所示:

MyAlternativeEntryName {
com.sun.security.auth.module.Krb5LoginModule required doNotPrompt=true
principal="myprincipal@EXAMPLE.COM"
useKeyTab=true keyTab="/path/to/krb5.keytab" storeKey=true;
};

关于java - 如何使用 keytab 在 LDAP 服务器中进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48262940/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com