Results 1 to 5 of 5

Thread: Querying LDAP from a Zimlet

  1. #1
    Chewie71 is offline Trained Alumni
    Join Date
    Sep 2006
    Location
    Illinois
    Posts
    371
    Rep Power
    8

    Default Querying LDAP from a Zimlet

    I posted back a couple weeks ago but thought I would try again...

    I'm trying to figure out how to query an LDAP server from Zimlets, with several use cases in mind. The basic functionality I need to figure out is how to query the LDAP server with Zimlet JSP and then return some results back to the client in the Zimlet JS. Here's a specific example...

    Courses Zimlet
    - Instructor would click the Zimlet and be presented with a list of the courses they are teaching (LDAP query)
    - Instructor could then click on a course name and it would then create a new email message with all the enrolled students listed in the BCC (another LDAP query)

    That's the one I want to try to tackle first as it looks pretty simple on the surface.

    Thanks,
    Matt

  2. #2
    Chewie71 is offline Trained Alumni
    Join Date
    Sep 2006
    Location
    Illinois
    Posts
    371
    Rep Power
    8

    Default

    OK....I'm making a little progress with this....but not much. I'll show what I've got and see if anyone has suggestions.

    I took some ideas from some of the sample zimlets...specifically jspsample and compose_mail_example. I've got two files in my zimlet... edu_wiu_email_starnum.xml, and ldap.jsp.

    edu_wiu_email_starnum.xml
    Code:
    <zimlet name="edu_wiu_email_starnum" version="1.0" description="EmailStarnum">
    
    <userProperties>
      <property type="string" name="uname" label="Username"/>
      <property type="string" name="pass" label="Password"/>
      <property type="string" name="url" label="Page URL"/>
      <property type="enum" name="dlstyle" label="Download Style">
         <item label="Attachments Only" visualType="radio"/>
    	 <item label="Body Only" visualType="radio"/>
      </property>
    </userProperties>
    
    <zimletPanelItem label="EmailStarnum"> 
      <toolTipText>
      Drag'n'Drop a message or folder here to send props to the JSP
      </toolTipText>
    
      <dragSource type="ZmMailMsg">
          <canvas type="dialog" width="600" height="350"/>
          <actionUrl target="/service/zimlet/_dev/edu_wiu_email_starnum/ldap.jsp">
              <param name="subject">${obj.subject}</param>
              <param name="id">${obj.id}</param>
          </actionUrl>
      </dragSource>
    
      <dragSource type="ZmConv">
          <canvas type="dialog" width="600" height="350"/>
          <actionUrl target="/service/zimlet/_dev/edu_wiu_email_starnum/ldap.jsp">
    	      <param name="subject">${obj.subject}</param>
    		  <param name="id">${obj.id}</param>
    	  </actionUrl>
      </dragSource>
    
      <dragSource type="ZmFolder">
          <canvas type="dialog" width="600" height="350"/>
          <actionUrl target="/service/zimlet/_dev/edu_wiu_email_starnum/ldap.jsp">
    	      <param name="name">${obj.name}</param>
    		  <param name="path">${obj.path}</param>
    	  </actionUrl>
      </dragSource>
    
    </zimletPanelItem>
    
    </zimlet>
    The params passed to the ldap.jsp are ignored for now, all I try to do is return results to the popup window.
    ldap.jsp
    Code:
    <%@ page language="java" import="com.sun.jndi.ldap.*, java.io.*, java.util.*, javax.naming.*, javax.naming.directory.*"%>
    
    <%
      String ldapServerName = "ldap";
      String user = "AUTHUSER";
      String pass = "AUTHPASS";
    
      String dn= "uid=" . concat(user) . concat(",ou=blahblahblah");
      String rootContext = "ou=" . concat(user);
    
      Properties env = new Properties();
      
      env.put( Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.LdapCtxFactory" );
      env.put("java.naming.ldap.version", "3");
      env.put( Context.PROVIDER_URL, "ldap://"+ ldapServerName + "/");
      env.put( Context.SECURITY_AUTHENTICATION, "simple");
      env.put( Context.SECURITY_PRINCIPAL, dn );
      env.put( Context.SECURITY_CREDENTIALS, pass);
    
      try {
    	//Create the initial directory context
    	DirContext ctx = new InitialDirContext( env);
    	//Ask for all attributes of the object
    	Attributes attrs = ctx.getAttributes("uid=USERNAME,ou=blahblahblah");
    	//Find the surname attribute ("sn") and print it
    	//System.out.println("sn: "+ attrs.get("sn").get());
    	}
      catch (NamingException e){
    	//Authentication Failed
    	}
      	PrintWriter pw = response.getWriter();
    	pw.println("sn: "+ attrs.get("sn").get());
    %>
    This works in the compose_email_example zimlet, but here where I try to do the same thing, the window pops up with errors in it...

    HTTP ERROR: 500

    PWC6033: Unable to compile class for JSP

    PWC6197: An error occurred at line: 19 in the jsp file: /zimlet/_dev/edu_wiu_email_starnum/ldap.jsp
    PWC6199: Generated servlet error:
    PrintWriter cannot be resolved to a type


    RequestURI=/service/zimlet/_dev/edu_wiu_email_starnum/ldap.jsp
    Can anyone help me resolve this?

    Eventually I want to add a .js file that opens a new compose window, and I think I have that part figured out, but I need to know if I can even get this LDAP Query JSP to work first.

    Thanks,
    Matt

  3. #3
    ab5602 is offline Project Contributor
    Join Date
    Nov 2007
    Location
    Detroit, MI
    Posts
    67
    Rep Power
    7

    Default

    I'm not sure what the PrintWriter object is, but you may want to try sending the contents of the output to the browser by exiting the .jsp tags instead like:

    Code:
      
            catch (NamingException e){
    	//Authentication Failed
    	}
    %>
    
    sn: <%=attrs.get("sn").get()%>

  4. #4
    Chewie71 is offline Trained Alumni
    Join Date
    Sep 2006
    Location
    Illinois
    Posts
    371
    Rep Power
    8

    Default

    I got the PrintWriter example from another zimlet that I was trying to model....but didn't work for me.

    I took that out and tried your code but still got an error. It didn't know how to handle that. Anyone know how to make some results from that JSP file appear in the zimlet popup?

    Matt

  5. #5
    kbos is offline Junior Member
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    7
    Rep Power
    6

    Default

    I don't see why the type is uknown, but I do know that PrintWriter is in java.io.* (java.io.PrintWriter). If you move the 'pw =' line to the top (just below var def block) and do a pr.println and comment the rest out...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 21
    Last Post: 02-04-2010, 10:06 AM
  2. Replies: 8
    Last Post: 08-07-2008, 05:18 AM
  3. [SOLVED] Install Problem in Ubuntu 6.06 Server
    By xtimox in forum Installation
    Replies: 16
    Last Post: 03-27-2008, 09:36 AM
  4. Zimbra Install Problem - getDirectContext
    By bsimzer in forum Installation
    Replies: 27
    Last Post: 07-19-2007, 10:12 AM
  5. Post instsallation problems
    By Assaf in forum Installation
    Replies: 14
    Last Post: 01-29-2007, 11:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •