JAVA LDAP 错误 javax.naming.NamingException: [LDAP: 错误代码 1 - 000004DC: LdapErr: DSID-0C09075A
JAVA LDAP ERROR javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C09075A
我有一个连接到 LDAP 服务器的 C# 代码,它工作得很好
下面给出了工作的 C# 代码
user = "myname@myorg.com";
string pwd = "secret";
String uid = "uid=" + user + ",ou=people,dc=myorg,dc=com";
int empID = 0;
DirectoryEntry root = new DirectoryEntry("LDAP://myorg.com", user, pwd, AuthenticationTypes.None);
try
{
object connected = root.NativeObject;
DirectorySearcher search = new DirectorySearcher(root);
search.Filter = "(&(objectClass=user)(objectCategory=Person))";
search.PropertiesToLoad.Add("SAMAccountName");
search.PropertiesToLoad.Add("EmployeeID");
foreach (System.DirectoryServices.SearchResult resEnt in search.FindAll())
{
System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
if (de.Properties["employeeID"].Value != null && de.Properties["userPrincipalName"].Value != null)
{
if (user.Equals(de.Properties["userPrincipalName"].Value))
{
string empIDstr = (string)de.Properties["employeeID"].Value;
int.TryParse(empIDstr, out empID);
Response.Write("EMp ID is No is "+empID);
}
}
}
}
catch(Exception ex)
{
Response.Write("Logon failed");
}
现在我想在 java 中做同样的事情,因为我有另一个应用程序要在 Java 中开发,但是下面的代码抛出异常
public class LdapClient {
public void authenticate(String user, String pwd){
String uid = "uid=" + user + ",ou=people,dc=myorg,dc=com";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://myorg.com");
env.put(Context.SECURITY_AUTHENTICATION, "none");
env.put(Context.SECURITY_PRINCIPAL, uid);
env.put(Context.SECURITY_CREDENTIALS, pwd);
try {
DirContext ctx = new InitialDirContext(env);
**//THE ERROR COMES AT THE LINE BELOW**
NamingEnumeration<?> namingEnum = ctx.search("ou=people,dc=myorg,dc=com", "(&(objectclass=user)(objectCategory=Person))", getSimpleSearchControls());
**strong text**
while (namingEnum.hasMore ()) {
SearchResult result = (SearchResult) namingEnum.next ();
Attributes attrs = result.getAttributes ();
System.out.println(attrs.get("cn"));
}
namingEnum.close();
} catch (Exception e) {
try {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
private SearchControls getSimpleSearchControls() {
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = {"samAccountName","employeeID"};
searchControls.setReturningAttributes(attrIDs);
return searchControls;
}
}
请帮助,因为我认为相应的相同代码在 C# 中有效
javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C09075A, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1 ]; remaining name 'ou=people,dc=myorg,dc=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at javax.naming.directory.InitialDirContext.search(Unknown Source)
at ldap.LdapClient.authenticate(LdapClient.java:51)
at ldap.LdapClient.main(LdapClient.java:30)
我必须在 Java 中执行此操作,因为我需要开发另一个指向同一 LDAP 服务器的应用程序。客户端需要 java。请帮忙
异常说明在执行操作(搜索)之前需要身份验证(绑定)。
如 documentation 所示,尝试使用 simple
身份验证
// Authenticate as S. User and password "mysecret"
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");
我有一个连接到 LDAP 服务器的 C# 代码,它工作得很好
下面给出了工作的 C# 代码
user = "myname@myorg.com";
string pwd = "secret";
String uid = "uid=" + user + ",ou=people,dc=myorg,dc=com";
int empID = 0;
DirectoryEntry root = new DirectoryEntry("LDAP://myorg.com", user, pwd, AuthenticationTypes.None);
try
{
object connected = root.NativeObject;
DirectorySearcher search = new DirectorySearcher(root);
search.Filter = "(&(objectClass=user)(objectCategory=Person))";
search.PropertiesToLoad.Add("SAMAccountName");
search.PropertiesToLoad.Add("EmployeeID");
foreach (System.DirectoryServices.SearchResult resEnt in search.FindAll())
{
System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
if (de.Properties["employeeID"].Value != null && de.Properties["userPrincipalName"].Value != null)
{
if (user.Equals(de.Properties["userPrincipalName"].Value))
{
string empIDstr = (string)de.Properties["employeeID"].Value;
int.TryParse(empIDstr, out empID);
Response.Write("EMp ID is No is "+empID);
}
}
}
}
catch(Exception ex)
{
Response.Write("Logon failed");
}
现在我想在 java 中做同样的事情,因为我有另一个应用程序要在 Java 中开发,但是下面的代码抛出异常
public class LdapClient {
public void authenticate(String user, String pwd){
String uid = "uid=" + user + ",ou=people,dc=myorg,dc=com";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://myorg.com");
env.put(Context.SECURITY_AUTHENTICATION, "none");
env.put(Context.SECURITY_PRINCIPAL, uid);
env.put(Context.SECURITY_CREDENTIALS, pwd);
try {
DirContext ctx = new InitialDirContext(env);
**//THE ERROR COMES AT THE LINE BELOW**
NamingEnumeration<?> namingEnum = ctx.search("ou=people,dc=myorg,dc=com", "(&(objectclass=user)(objectCategory=Person))", getSimpleSearchControls());
**strong text**
while (namingEnum.hasMore ()) {
SearchResult result = (SearchResult) namingEnum.next ();
Attributes attrs = result.getAttributes ();
System.out.println(attrs.get("cn"));
}
namingEnum.close();
} catch (Exception e) {
try {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
private SearchControls getSimpleSearchControls() {
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = {"samAccountName","employeeID"};
searchControls.setReturningAttributes(attrIDs);
return searchControls;
}
}
请帮助,因为我认为相应的相同代码在 C# 中有效
javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C09075A, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1 ]; remaining name 'ou=people,dc=myorg,dc=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at javax.naming.directory.InitialDirContext.search(Unknown Source)
at ldap.LdapClient.authenticate(LdapClient.java:51)
at ldap.LdapClient.main(LdapClient.java:30)
我必须在 Java 中执行此操作,因为我需要开发另一个指向同一 LDAP 服务器的应用程序。客户端需要 java。请帮忙
异常说明在执行操作(搜索)之前需要身份验证(绑定)。
如 documentation 所示,尝试使用 simple
身份验证
// Authenticate as S. User and password "mysecret"
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");