[英]JNDI search not working after GSSAPI (Authenticate with Kerberos)
我從互聯網獲得以下示例,以使用JNDI測試GSSAPI。
public class GssExample {
public static void main(String[] args) {
System.setProperty("java.security.auth.login.config", "C:\\gssapi_jaas.conf");
System.setProperty("java.security.krb5.conf", "C:\\krb5.conf");
LoginContext lc = null;
try {
lc = new LoginContext(GssExample.class.getName(),
new LoginCallBackHandler());
lc.login();
} catch (LoginException le) {
}
Subject.doAs(lc.getSubject(), new JndiAction(args));
}
}
class JndiAction implements java.security.PrivilegedAction {
public Object run() {
performJndiOperation(args);
return null;
}
private static void performJndiOperation(String[] args) {
Hashtable<String, String> env = new Hashtable<String, String>(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,
"ldap://XXXX.domain.lab:389/OU=StackOverFlow,dc=domain,dc=lab");
env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");
env.put("javax.security.sasl.server.authentication", "true");
try {
DirContext ctx = new InitialDirContext(env);
// Fails here with exception as shown below
NamingEnumeration<SearchResult> _result = ctx.search("DC=domain,DC=lab","(objectClass=User)", null);
ctx.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
我得到例外
javax.naming.NameNotFoundException:[LDAP:錯誤代碼32-0000208D:NameErr:DSID-03100241,問題2001(NO_OBJECT),數據0,最佳匹配項:'OU = StackOverFlow,DC = domain,DC = lab'
請注意: OU在AD系統上存在。
LoginCallBackHandler
代碼如下
class LoginCallBackHandler implements CallbackHandler {
@Override
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
if(callbacks != null && callbacks.length > 0) {
if(callbacks[0] instanceof NameCallback) {
((NameCallback)(callbacks[0])).setName("User@DOMAIN.LAB");
}
else if(callbacks[0] instanceof PasswordCallback) {
((PasswordCallback)(callbacks[0])).setPassword("Password".toCharArray());
}
}
}
}
我錯過了什么還是做錯了什么?
該錯誤與身份驗證無關。 您錯誤地使用了LDAP搜索。 您已經限制了搜索基礎DN ldap://XXXX.domain.lab:389/OU=StackOverFlow,dc=domain,dc=lab
。 然后,您提供了ctx.search("DC=domain,DC=lab",...
,但是沒有樹DC=domain,DC=lab,OU=StackOverFlow,dc=domain,dc=lab
。
請僅提供另一個RootDSE的LDAP URL,或者為search()
提供一個空字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.