Display LDAP attributes within a portlet
The portlet in the image below contains information from LDAP:
To keep it simple, two LDAP attributes are being displayed:
- email address
- department
Hopefully you have some LDAP attributes similar to these. If not substitute them with some other LDAP attributes.
Firstly, install LDAP appropriately. Easier said than done. I promise to do a write up sometime. I use LDAPUserFolderEXT, Plone 2 with ZEO, on SUSE 8.1.
Use an LDAP browser tool such as Softerra to browse for information you can extract from your LDAP tree.
In the ZMI, go to your portal root. Select the 'acl_users folder.' Click the 'content' tab. Click the 'users folder.' Click the 'acl_users' LDAP folder. Select 'LDAP Schema.'
Here's a brief example is below of what could be displayed:
In the 'Add LDAP schema item' fields, complete the 'LDAP attribute name' you queried using the LDAP browser tool. In the image above it's 'mail' quite obviously. Give it a friendly name such as 'email address.' However, as you may notice, department has the LDAP attribute of 'description,' so do use the friendly name.
You now need to extract the attributes into a portlet.
There are several ways to create a new portlet, this is one of them.
In the ZMI, change to portal_root/portal_skins/custom or whatever your custom folder is.
From the drop down menu, select 'page template.' Give it an id of portlet_ldap. Paste the code below into it:
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
i18n:domain="plone">
<body>
<div metal:define-macro="portlet">
<div class="portlet" id="portlet-ldap">
<h5 i18n:translate="box_statis">add header</h5>
<div class="portletBody">
content here
</div>
</div>
</body>
</html>
Replace 'content here' with the following:
<ul>
<li class="portalUser" tal:condition="not: isAnon">
<span tal:define="mail python:member.getProperty('mail')"
tal:omit-tag=""
tal:on-error="string:no known name"> Your email address<br /><br
/> <span tal:replace="mail"><strong>replace email</strong></span></span>
</li>
<p></p>
<li class="portalUser" tal:condition="not: isAnon">
<span tal:define="description python:member.getProperty('description')"
tal:omit-tag=""
tal:on-error="string:no known department"> Department<br /><br
/> <span tal:replace="description"><strong>replace
department</strong></span></span> </li>
<p></p>
</ul>
The above simply brings both mail and department attributes into the portlet. The portlet is not visible by anonymous users. Plus it wouldn't matter if it was visible; anonymous users would just see the on-error statement.
Now, go to the portal_root in the ZMI and click Properties. Complete as below, then click Add.
Or add here/portlet_ldap/macros/portlet to the right_slots property list if it already exists.
Be sure to click Save Changes when finished.
View the site and hopefully the portlet is displayed correctly.
Troubleshooting
- If you receive errors when viewing, try flushing the cache. I cannot remember
the exact error message. However, when I create a new portlet, no matter how simple,
flushing the cache solves this. In the ZMI root for the Zope instance (not just the
Plone site root):
/Control_Panel/Database/main/flush cache/Minimize

Author: