Screencast 7 – LDAP Search Portlet for WebCenter with ADF

One of the cornerstones of intranet functionality is the ability to quickly locate colleagues and obtain their contact information. In this episode of Enterprise 2.0 Workbench we take a look at using ADF to create a Data Control on top of a Java Bean that connects with an instance of LDAP / Active Directory.

One of the most powerful aspects of ADF is the ability to leverage Data Controls that abstract a web developer from having to know details of underlying data sources. In our sample we are going to illustrate how a Java Bean can be created, along with a search class and search method to expose LDAP functionality to developers who via the Data Control will be able to drag and drop items within the Data Control to declaratively create this portlet.

Sample Files and Purpose
For the purposes of our portlet development, the following are key files that we will use within our Fusion Web Application

1. – this file contains the method that actually executes the search and returns the results to us. As it receives the results it adds the individual people into a List of Person beans. This class will be used to create our Data Control.

2. – this Java Bean will provide a container to hold the people that come back in the result set. We will take a look at how to create the structure of the bean, so that this same approach could be used with other projects.

3. – this provides a Servlet that will return the image stored for a given user in the LDAP system. We will not cover it in detail, but it provides a nice utility to let us enhance the results shown for a search by including a user’s photo.

4. LDAPSearch.jspx – our ADF page that will make use of the Data Control in order to provide the interface for the search and the result set.

5. web.xml – in this file we will setup Environment Entries that will be used by the GetLDAPUserImage servlet, as well as the DirectorySearch class to connect to LDAP. This allows us to abstract settings that are environment specific from our actual code.

6. WebCenter Template UI Snippet – at the bottom of this post I have included some navigation snippet code based on what we did in the Navigation Episode that now includes this “portlet”. For the purposes of our display in the UI I have chosen to keep things simple and just use an iFrame to hold the application within our nested list items. This is a hack, but a nice way to quickly provide the feature.

Weblogic Server Embedded LDAP Server Config
If you are going to try to use the embedded LDAP server in WLS for testing, keep in mind that you will need to set the password for connectivity. Set the password in the location below, this will be used to authenticate when using the cn=Admin user principal, as we have specified in our web.xml example in the source code below.

Thoughts on Possible Enhancements
This was made as an example to illustrate a series of platform features, but it may be interesting to expand in the following ways

  1. Expose this application via WSRP as a portlet and use portlet preferences to pass the LDAP configuration information. This could allow the base path to support various areas of a directory on the basis of a user’s role – e.g. collaboration portals may only want to expose contact information for peers within a business unit.
  2. Add additional attributes to the person object to make the display more comprehensive
  3. Add more detailed search options to allow filtering prior to the execution of the search

Happy coding!

Project Code
Download LDAP Search Portlet for WebCenter ADF Project Code

The following are the code samples used in our example. For the search it has been commented in a way with its LDAP connection information that will also apply to the LDAP connectivity in Arguably, there are better ways to code this, but I have kept it simple for demonstration purposes.

[gist id=2415841]

  • anshuman4luv
    August 30, 2014

    Hi, What do i need to do if i want to put auto suggest in the text field so that it fetches me the names from ldap and auto suggest me.

  • John Brunswick
    August 30, 2014

    anshuman4luv thanks – that is tricky, as you would need to make real-time calls to LDAP or have a local database with those items available for matching.  The above code would need additional methods and could not be updated as-is.  Hope that helps!

Leave a comment