LDAP taglib ver. 1.7

    Custom JSP taglib. Two body tags check authentication against the given LDAP server. Tag isAuthenticated executes own body if user is authenticated and tag isNotAuthenticated executes own body if user is not authenticated.

For example:
 


<%@ taglib uri="taglib.tld" prefix="if" %>

<if:isAuthenticated user="uid=guest" password="12345"
url="ldap://localhost:389" factory="com.sun.jndi.ldap.LdapCtxFactory">
    ...
   I am a guest
    ...
</if:isAuthenticated>

<if:isNotAuthenticated user="cn=test,o=company" password="my_secret_word"
  url="ldap://localhost:636"
  level="simple" factory="com.sun.jndi.ldap.LdapCtxFactory"
  protocol="ssl">
   ...
   Sorry, you are not allowed
   ...
</if:isNotAuthenticated>

For the authenticated users tag isAuthenticated can create a nested page scope variable with the directory context. You can request the attributes for example:
 


<%@ taglib uri="taglib.tld" prefix="if" %>

<if:isAuthenticated user="uid=guest" password="12345" id="dir"
url="ldap://localhost:389" factory="com.sun.jndi.ldap.LdapCtxFactory">
 ...
 <%
  javax.naming.directory.Attributes attrs = dir.getAttributes("cn = Ted Geisel, ou=People");
  Object sn = attrs.get("sn").get();
 %>
 ...
</if:isAuthenticated>

Tags are:

isAuthenticated

Executes own body if user is authenticated against the given LDAP. Parameters are:

1) factory context factory class. E.g.: com.sun.jndi.ldap.LdapCtxFactory
2) user user name.
3) password describes a password
4) url url for LDAP server
5) level Optional parameter: authentication level. Possible values are none, simple, strong.
6) protocol Optional parameter: authentication protocol. E.g. ssl
7) base Optional parameter: base for search. E.g. ou=people,dc=example,dc=com
8) sAMAccountName Optional parameter: describes an attribute from Active Directory
9) id Optional parameter. Describes a name for the nested page scope variable (type is javax.naming.directory.InitialDirContext) with the context.

isNotAuthenticated

Executes own body if user is not authenticated against the given LDAP. Parameters are:

1) factory context factory class. E.g.: com.sun.jndi.ldap.LdapCtxFactory
2) user user name.
3) password describes a password
4) url url for LDAP server
5) level Optional parameter: authentication level. Possible values are none, simple, strong.
6) protocol Optional parameter: authentication protocol. E.g. ssl
7) base Optional parameter: base for search. E.g. ou=people,dc=example,dc=com
8) sAMAccountName Optional parameter: describes an attribute from Active Directory

for downloading:

Library: ldaptag.jar    Description: taglib.tld

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

     

Also in Coldtags: