This discussion is archived
1 Reply Latest reply: Mar 12, 2013 2:47 AM by gimbal2 RSS

Referral Ldap Problem at Jboss as7

ManPakHong,Dave Newbie
Currently Being Moderated
The Problems:
- Java program which can get any Referral Ldap Node Object(<---------------- Referral to another ldap) at Unit Test/ console mode, but
failed when put it onto jboss and call the same method from jsp.
- We have tested that if the Object which is not Referral, that finds no problem at
Unit test/ console or put it and run one the jboss calling by jsp.



##########################Ldap structure######################################################

root: o=com,dc=rabbitforever
.
.
.
ou=People #1st level
ou=Profile #1st level
ou=HQ2-BR # 1st level <---------------- Referral to another ldap
+ou=TSB #2nd level
+ou=LTEST29 #2nd level
+ou=IIC #2nd level
+ou=People # 3rd level
+uid=IICCIO #4th level
+uid=IICSIO1 #4th level
+ou=Terminal # 3rd level

xxxxxxxxxxxxxxxxxxxxxxxxxx error Message from jboss jsp xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
15:18:45,819 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[testLdap].[jsp]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception: javax.naming.NotContextException: Cannot create context for: ldap://devuaeldp31.uat.immd.hksarg:389/ou%3dHQ2-BR,o%3dimmd,dc%3dhksarg; remaining name 'ou=HQ2-BR,o=immd,dc=hksarg'
     at com.sun.jndi.ldap.LdapReferralContext.<init>(LdapReferralContext.java:141) [rt.jar:1.7.0_15]
     at com.sun.jndi.ldap.LdapReferralException.getReferralContext(LdapReferralException.java:150) [rt.jar:1.7.0_15]
     at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1861) [rt.jar:1.7.0_15]
     at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1772) [rt.jar:1.7.0_15]
     at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:386) [rt.jar:1.7.0_15]
     at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:356) [rt.jar:1.7.0_15]
     at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:339) [rt.jar:1.7.0_15]
     at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267) [rt.jar:1.7.0_15]
     at smartics.FullUserExtract.searchLDAP(FullUserExtract.java:69) [classes:]
     at org.apache.jsp.hello_jsp._jspService(hello_jsp.java:82)
     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
     at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
     at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_15]


===================== The main program =========================================
     public void searchLDAP(String ldapUrl, String userName, String password,
               String searchBase) throws Exception {

          printDebug("Start extract full user list");
          Hashtable<String, String> env = new Hashtable<String, String>();

          String sp = "com.sun.jndi.ldap.LdapCtxFactory";
          env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
          env.put(Context.PROVIDER_URL, ldapUrl);
          env.put(Context.SECURITY_PRINCIPAL, userName);
          env.put(Context.SECURITY_CREDENTIALS, password);
          env.put(Context.REFERRAL, "follow");
//          env.put(Context.REFERRAL, "ignore");

          DirContext dctx = new InitialDirContext(env);
          try {
               SearchControls sc = new SearchControls();
               String[] attributeFilter = { "uid", "ca-AccessFlag",
                         "pa-AccessFlag", "smartics-AccessFlag", "td-AccessFlag",
                         "logonLocation", "sn", "post", "rank" };
               sc.setReturningAttributes(attributeFilter);
               sc.setSearchScope(SearchControls.SUBTREE_SCOPE);

               String filter = "(&(uid=*)(objectType=User)(objectClass=immdPerson))";

               openOutputFile();
               printLineToFile("uid,name,post,rank,ca-AccessFlag,pa-AccessFlag,smartics-AccessFlag,td-AccessFlag,locationCode,branchCode,logonLocation");

               NamingEnumeration results = dctx.search(searchBase, filter, sc);
               int i = 0;
               while (results.hasMore()) {

                    SearchResult sr = (SearchResult) results.next();
                    Attributes attrs = sr.getAttributes();

                    String partialDn = sr.getName();
                    try {
                         if (!shouldSkip(partialDn)) {
                              LDAPUser user = new LDAPUser();
                              user.setUid(getAttributeAsString(attrs.get("uid")));
                              user.setCaAccessFlag(getAttributeAsString(attrs
                                        .get("ca-AccessFlag")));
                              user.setPaAccessFlag(getAttributeAsString(attrs
                                        .get("pa-AccessFlag")));
                              user.setScAccessFlag(getAttributeAsString(attrs
                                        .get("smartics-AccessFlag")));
                              user.setTdAccessFlag(getAttributeAsString(attrs
                                        .get("td-AccessFlag")));
                              user.setName(getAttributeAsString(attrs.get("sn")));
                              user.setPost(getAttributeAsString(attrs.get("post")));
                              user.setRank(getAttributeAsString(attrs.get("rank")));
                              user.setSecondaryLocations(getAttributeMVAsString(attrs
                                        .get("logonLocation")));
                              user.setLocationCode(getLocationCodeFromDn(partialDn
                                        + "," + searchBase));
                              user.setBranchCode(getBranchCodeFromDn(partialDn + ","
                                        + searchBase));

                              printEntryToFile(user);
                              i++;
                         } else {
                              printDebug(sr.getName() + " is skipped");
                         }
                    } catch (Exception ex) {
                         printDebug("Error pausing ldap entry, partialDn=["
                                   + partialDn + "]");
                         ex.printStackTrace();
                    }
               }

               printDebug("Number of LDAP user extracted: " + i);
          } finally {
               if (dctx != null)
                    dctx.close();
               closeOutputFile();
          }
          printDebug("End extract full user list");
     }
================= a very clean jsp test page ==========================================
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test</title>
</head>
<body>

<%
String ldapUrl = "ldap://10.26.186.156:389";
String ldapUserName = "uid=referral,ou=people,o=immd,dc=hksarg";
String ldapPwd = "referral";
String searchBase = "ou=HQ2-BR,o=immd,dc=hksarg";

smartics.FullUserExtract fue = new smartics.FullUserExtract("c:/temp/out.txt");
fue.searchLDAP(ldapUrl, ldapUserName, ldapPwd, searchBase);
%>

</body>
</html>

Regards,
Man Pak Hong, Dave
manpakhong@hotmail.com
  • 1. Re: Referral Ldap Problem at Jboss as7
    gimbal2 Guru
    Currently Being Moderated
    The exception is very much not helpful, it does not say WHY the context cannot be created. You need to figure out how to get the why to be able to continue. Check the server logs to see if there is more information in there. I can only guess that it is networking related; which I base on the fact that you can make the code work through another path. The code itself must then not be wrong.

    Meanwhile, your question is dangerously close to being JBoss 7 related. You will want to ask in the wonderful forums on the JBoss site.

    https://community.jboss.org/en/jbossas7?view=discussions

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points