Java GSSAPI之后JNDI搜索不工作(使用Kerberos进行身份验证)
我从互联网上获得了以下示例,用JNDI测试GSSAPIJava GSSAPI之后JNDI搜索不工作(使用Kerberos进行身份验证),java,jndi,kerberos,gssapi,mit-kerberos,Java,Jndi,Kerberos,Gssapi,Mit 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:\\krb
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();
}
}
我是遗漏了什么还是做错了什么?该错误与身份验证无关。您未正确使用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()提供空字符串
该错误与身份验证无关。您未正确使用LDAP搜索。您已经限制了搜索基础DNldap://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()提供空字符串
非常感谢!!我一直在努力完成这项工作,却没有注意到这样一个简单的事实。你是一个救世主!非常感谢!!我一直在努力完成这项工作,却没有注意到这样一个简单的事实。你是一个救世主!
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());
}
}
}
}