- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 C# 代码来连接到 LDAP 服务器,它工作得很好
下面给出了工作的 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。请帮忙
最佳答案
异常(exception)情况是在执行操作(搜索)之前需要身份验证(绑定(bind))。正如 documentation 所示尝试使用简单
身份验证
// 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");
关于JAVA LDAP 错误 javax.naming.NamingException : [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C09075A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53954017/
我得到错误: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.Na
我有一个直接使用 Java Transaction API 资源的 hibernate 应用程序。我正在尝试使用 UserTransaction 来完成一些基本的数据库事务 The UserTrans
我尝试向 activemq 发布消息。但是我在 java 应用程序中遇到一个命名异常。这是代码如下 Properties props = new Properties(); props.se
我在 Weblogic 11g 上运行 Java 6。 我正在开发一个使用 EJB 与数据库通信的 Web 服务项目。目前我正在处理错误,因此我尝试在调用 Web 服务之前取消部署 EJB。我的 EJ
我正在使用 maven 跟踪错误 tomcat 7.0.53。我在 server.xml 的 Resource 标签中使用了 factory="org.apache.commons.dbcp.Basi
当我运行以下命令时: package NonServletFiles; import java.sql.Connection; import java.sql.PreparedStatement; i
我新使用 j2ee,当我使用 netbean 6.9 运行这个项目时。我遇到了这个问题 javax.naming.NamingException: Lookup failed for 'java:co
我在 web.xml 中添加了以下内容: ejb/userManagerBean Session gha.ywk.name.entry.ejb.use
我在 machine1 上部署了一个安全的 ejb,当我在同一台机器上运行客户端代码时,它工作正常。但是当我在任何其他机器上运行客户端代码时,它会抛出错误。粘贴在下面。 在错误中可以看出它没有获取所提
我的监听器代码如下 package org.javaimplant.newsfeed.Init; import javax.naming.Context; import javax.naming.In
我有两个项目,第一个是Ejb3项目,名称是SessionBean,另一个是java项目,名称是SessionBeanClient。对于 IDE,我使用 eclipse indigo。我已经完成了代码,
我已经尝试了下面的大量变体来使数据源工作但无济于事。我已经研究/尝试了几天,所以我认输并寻求帮助。不过首先,我很难在这篇文章中格式化我的代码。没有缩进,某些 xml 标记正在消失。可能是愚蠢的 IE
我正在使用 tomcat 和 mysql(ide 是 eclipse)。我正在使用连接池。 在 context.xml 中,我有: 一开始我一直在easyphp中使用mysql(root用户没有p
我有两个实现接口(interface)的无状态 EJB。为了加载实现,我使用了 InitialContext,但它总是失败并出现 NamingException。 界面 package app.ejb
我试图通过一个简单的 jsp 表单来持久化一个实体,但它不起作用。出现的异常是:javax.naming.NamingException: Lookup failed for 'java:global
我是 java EE 的新手。最近我正在开发一个使用 bean stateless 的项目,但出现以下错误 bean : @Stateless(mappedName = "FlightServiceB
我知道这个问题已经被问过很多次了,但即使在遵循所有答案之后我仍然有一个异常(exception)。我的配置是: 上下文.xml web.xml Prod C
我正在使用 wildfly10。这是我的 Java 代码。 private Hashtable mEnv = new Hashtable(); InitialContext e = new Initi
尝试通过 tomcat Context.xml 公开一个 Oracle 连接时,我得到了一个 NamingException。我已经学习了几个教程,但仍然遇到异常。帮助! Java: String e
关于这个问题似乎有几个主题,但还没有找到答案。我对 JSF 很陌生,想创建一个 postgresql 连接池,使用: JSF 2.2.9 Tomcat 8.0.27 但是 tomcat 总是给我一个
我是一名优秀的程序员,十分优秀!