簡體   English   中英

javax.naming.InvalidNameException:[LDAP:錯誤代碼34 - 無效的DN]

[英]javax.naming.InvalidNameException: [LDAP: error code 34 - invalid DN]

我是一名大學生。 現在,我正在做一個必須使用LDAP連接來驗證登錄過程中用戶的用戶名和密碼的項目。 所以,我的網站是用JSP開發的。 我試圖解決代碼的錯誤,但我不能。 我犯了一些錯誤嗎?

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="java.util.regex.*" %>
<%@ page import="javax.naming.directory.*" %>
<%@ page import="java.util.Hashtable.*" %>
<%@ page import="javax.naming.ldap.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            String username = request.getParameter("email");
String password = request.getParameter("password");
            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://ldap-pj.sit.kmutt.ac.th");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);

try {
            //Connect with ldap
            new InitialLdapContext(env, null);  

            //Connection succeeded
            System.out.println("Connection succeeded!");
        } catch (AuthenticationException e) {

            //Connection failed
            System.out.println("Connection failed!");
            e.printStackTrace();
        }  
%>
    </body>
</html>

我從運行代碼中得到了這個錯誤信息。

HTTP狀態500 -

類型異常報告

信息

description服務器遇到內部錯誤(),導致無法完成此請求。

例外

org.apache.jasper.JasperException:在第33行處理JSP頁面/ldap_checking.jsp時發生異常

30:31:嘗試{32://使用ldap 33連接:新的InitialLdapContext(env,null); 34:35://連接成功36:System.out.println(“連接成功!”);

Stacktrace:org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)org.apache.jasper.servlet.JspServlet.serviceJspFile( JspServlet.java:390)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)javax.servlet.http.HttpServlet.service(HttpServlet.java:722)根本原因

javax.servlet.ServletException:javax.naming.InvalidNameException:[LDAP:錯誤代碼34 - 無效的DN] org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)org.apache.jasper.runtime.PageContextImpl。 handlePageException(PageContextImpl.java:840)org.apache.jsp.ldap_005fchecking_jsp._jspService(ldap_005fchecking_jsp.java:212)org.apache.jasper.runtime.HttpJspBase.service(httpJspBase.java:70)javax.servlet.http.HttpServlet。 service(HttpServlet.java:722)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)org.apache.jasper。 servlet.JspServlet.service(JspServlet.java:334)javax.servlet.http.HttpServlet.service(HttpServlet.java:722)根本原因

javax.naming.InvalidNameException:[LDAP:錯誤代碼34 - 無效的DN] com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3028)com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java: 2835)com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2749)com.sun.jndi.ldap.LdapCtx。(LdapCtx.java:316)com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory .java:193)com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:211)com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)com.sun.jndi.ldap.LdapCtxFactory .getInitialContext(LdapCtxFactory.java:84)javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)javax.naming.InitialContext.init(InitialContext.java) :242)javax.naming.ldap.InitialLdapContext。(InitialLdapContext.java:153)org.apache.jsp.ldap_005fchecking_jsp._jspService(ldap_005fchecking_jsp.java:97)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java: 7 0)javax.servlet.http.HttpServlet.service(HttpServlet.java:722)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet。 java:390)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)javax.servlet.http.HttpServlet.service(HttpServlet.java:722)注意根本原因的完整堆棧跟蹤可用於Apache Tomcat / 7.0.27日志。

Apache Tomcat / 7.0.27

這是重要的一行:javax.naming.InvalidNameException:[LDAP:錯誤代碼34 - 無效的DN]

您可以在這里查看: https//wiki.servicenow.com/index.php?title = ENDAP_Error_Codes

對於34的意思,但看起來你嘗試使用的專有名稱是不正確的。 看起來你的校長可能格式不正確。 在執行ldap身份驗證時請參閱oracle的本指南: http//docs.oracle.com/javase/jndi/tutorial/ldap/security/ldap.html

特別注意它們設置環境條目的這一部分:

env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");

堆棧跟蹤中的“javax.naming.InvalidNameException:[LDAP:錯誤代碼34 - 無效DN]”是關鍵。 您的LDAP服務器不喜歡您發送它的值。 我建議完全限定用戶名,例如cn = username,ou = some_container,o = mycompany。 實際語法將由LDAP服務器驅動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM