Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-2008, 09:12 AM
Trained Alumni
 
Posts: 343
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
Reply With Quote
  #2 (permalink)  
Old 10-22-2008, 11:22 AM
Trained Alumni
 
Posts: 343
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...

Quote:
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
Reply With Quote
  #3 (permalink)  
Old 10-22-2008, 05:07 PM
Project Contributor
 
Posts: 67
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()%>
Reply With Quote
  #4 (permalink)  
Old 10-22-2008, 08:43 PM
Trained Alumni
 
Posts: 343
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
Reply With Quote
  #5 (permalink)  
Old 10-25-2008, 06:20 AM
Junior Member
 
Posts: 7
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...
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.