You are here

iPerson & jsp - how to for Luminis 3.x

Submitted by Jason on Fri, 06/17/2005 - 18:07

I recently had a need to develop a method of passing multiple LDAP attributes to external systems.  I worked with SCT to come up with the following solution, and hope it might be of use to some of you.

The variables available to you are defined in $CP_ROOT/webapps/luminis/WEB-INF/config/PersonDirs.xml, for instance, my PersonDirs.xml file looks like this:

<?xml version="1.0"?>
<PersonDirs>
    <PersonDirInfo>

        <url>ldap://ourserver:389/o=pcc.edu,o=cp</url>
        <logonid>xxxxxxxx</logonid>
        <logonpassword>xxxxxx</logonpassword>
        <uidquery>(uid={0})</uidquery>
        <usercontext>ou=People</usercontext>
     
        <attributes>
            <attribute>
                <name>uid</name>
                <alias>uid</alias>
            </attribute>
            <attribute>
                <name>sn</name>
                <alias>sn</alias>
            </attribute>

            <attribute>
                <name>mail</name>
                <alias>mail</alias>
            </attribute>
            <attribute>
                <name>pdsRole</name>
                <alias>pdsRole</alias>
            </attribute>
            <attribute>
                <name>displayName</name>
            </attribute>
            <attribute>
                <name>cn</name>
            </attribute>
            <attribute>
                <name>givenName</name>
            </attribute>
        </attributes>

    </PersonDirInfo>
</PersonDirs>

In order to serve jsp code, you must setup a few things:

Modify /webapps/luminis/WEB-INF/web.xml. 
At the bottom of the servlet section, include code to create a new 'servlet' for
your JSP:

               
<servlet>
               
<servlet-name>cp_test_webct_sso</servlet-name>
               
<servlet-class>com.pipeline.uportal.JspBoffoServlet</servlet-class>
               
<init-param>
               
<param-name>pathinfo</param-name>
               
<param-value>cp/Test</param-value>
               
</init-param>
               
</servlet>

Modify /webapps/luminis/WEB-INF/web.xml. 
At the bottom of the mapping section, include code for a virtual path to your
JSP:

               
<servlet-mapping>
               
<servlet-name>cp_test_webct_sso</servlet-name>
               
<url-pattern>/webct/*</url-pattern>
               
</servlet-mapping>

Modify /webapps/luminis/WEB-INF/config/webapps.xml. 
This allows the jsp to be served. 

               
<url path="/Test" servlet="com.pipeline.web.JspWebApplication"/>

        The final result of these three
settings, is the ability to serve jsp from /webapps/luminis/Test, to create a
servlet from jsp found in /Test, and to refer to this physical path of /Test by
the virtual name /webct.

Finally, this is the code used to query the LDAP for any variables defined in PersonDirs.xml:

------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html" %>
<%@ page import="java.util.*" %>
<%@ page import="org.jasig.portal.security.provider.*" %>
<%@ page import="org.jasig.portal.security.*" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>

<%!
 private String iPersonStuff(HttpServletRequest hsr)
    throws PortalSecurityException
 {
     StringBuffer sb = new StringBuffer();
    SimplePersonManager spm = new SimplePersonManager();
    IPerson i = spm.getPerson(hsr);
    sb.append( "IPerson username: " + (String)i.getAttribute("username") + "<br/>" );
    sb.append( "IPerson mail: " + (String)i.getAttribute("mail") + "<br />" );
    sb.append( "IPerson role: " + (String)i.getAttribute("role") + "<br />" );
    sb.append( "IPerson displayName: " + (String)i.getAttribute("displayName") + "<br />" );
    sb.append( "IPerson firstName: " + (String)i.getAttribute("firstName") + "<br />" );
    sb.append( "IPerson lastName: " + (String)i.getAttribute("lastName") + "<br />" );
    return sb.toString();
}

%>
------------------------------------------------------------------------------

If you want to put each attribute in its own variable, another useful method is this:

<%!
 private String getUserID(HttpServletRequest hsr)
    throws PortalSecurityException
 {
     StringBuffer sb = new StringBuffer();
    SimplePersonManager spm = new SimplePersonManager();
    IPerson i = spm.getPerson(hsr);
    sb.append( (String)i.getAttribute("username"));
    return sb.toString();
}

private String getFullName(HttpServletRequest hsr)
    throws PortalSecurityException
 {
     StringBuffer sb = new StringBuffer();
    SimplePersonManager spm = new SimplePersonManager();
    IPerson i = spm.getPerson(hsr);
    sb.append( (String)i.getAttribute("cn"));
    return sb.toString();
}

private String getEmail(HttpServletRequest hsr)
    throws PortalSecurityException
 {
     StringBuffer sb = new StringBuffer();
    SimplePersonManager spm = new SimplePersonManager();
    IPerson i = spm.getPerson(hsr);
    sb.append( (String)i.getAttribute("mail"));
    return sb.toString();
}
.....etc

Using the above code, you can then refer to each attribute in the body, links, or whatever, like this:

getUserID(request),getFullName(request),getEmail(request), etc..

---------------------------------------------------------------------------------------------

Jason Whitener
Portland Community College
jwhitene@pcc.edu

Luminis Version:

Hi Jason,

I have been using the iPerson object via webproxy channels up to this point. I saw your example of setting up a jsp servlet and accessing the iPerson Object using a jsp page instead. I descided to try my attempt. I get the page to render, but the username is defaulting back as "guest", and no other request variables are being returned.

I started looking at the http request duration using the luminis admin center, and saw that my servlet is not in the duration list.
I then started playing with the servlet parms in the web.xml and webapp.xml files. I now see the servlet being called in the duration list, but the page will not render.

I am a bit confused by the correlation between then
com.pipeline.uportal.JspBoffoServlet
in the web.xml file and the com.pipeline.web.JspWebApplication in the
webapps.xml file.

Thanks for any insight!

Some of the gotcha's that I found out later about this:

1. The URL and real path can't be the same in your mappings. so using /test as the physical directory and /test as the virtual path won't work.
2. Make sure that the changes to webapps.xml and web.xml are in the appropriate sections of the file.

If you are getting 'guest' and not the correct uid that is logged in at the time, it sounds like your jsp isn't being served as an official application that has persistent session status. I'm guessing that #2 will fix what you are seeing.

This code in web.xml, for simplicity sake, just put it at the very bottom of all the servlet sections:

servlet>
servlet-name>cp_test_webct_sso
servlet-class>com.pipeline.uportal.JspBoffoServlet
init-param>
param-name>pathinfo
param-value>cp/Test
/init-param>
/servlet>

This code, same thing, but at the bottom of all the servlet-mapping sections:
servlet-mapping>
servlet-name>cp_test_webct_sso
url-pattern>/webct/*
/servlet-mapping>

make sure that url-pattern and pathinfo in the above two code snippets are not equal.

in webapp.xml, make sure you include the code:
url path="/Test" servlet="com.pipeline.web.JspWebApplication"/>

This is what makes the jsp act as an application.. I guess:), I didn't write any of that. SCT told me that in order to make the jsp behave as an application that persists for each user session, you need the above code line. Its possible that you are seeing 'guest' because there is a typo with this line. Sorry, not 100% sure on the interplay of these code snippets. I got it to work, then moved on:).

param-value>cp/Test, from the web.xml changes, needs to match the path value, minus the cp, of the webapps.xml line.

Or something like this is even simpler for retrieving IPerson attributes


private String getIPersonAttribute(HttpServletRequest hsr, String attr)
    throws PortalSecurityException
 {
     StringBuffer sb = new StringBuffer();
    SimplePersonManager spm = new SimplePersonManager();
    IPerson i = spm.getPerson(hsr);
    sb.append( (String)i.getAttribute(attr));
    return sb.toString();
}

.....etc


String userId   = getIPersonAttribute(request, "username");
String fullName = getIPersonAttribute(request, "cn");
String email    = getIPersonAttribute(request, "mail");

Thanks for the pointer btw. It looks extremely useful

Regards, David

This has been extremely useful for us with Luminis 3, but we're moving to Luminis IV and I'm finding out that alot of stuff behind the scenes has changed. Has anyone implemented this using Luminis IV?

Thanks,
Jeff