Authenticate JBoss application using JAAS and LDAP

Authenticate JBoss application using JAAS and LDAP

It is easy to connect a JBoss to an LDAP server and creating Java EE applications that use the LDAP information for authorization and authentication.

Following these simple steps, you will be able to configure your JBoss and a web application (configuring an ejb deployment is similar; Just read the Java EE API to map the attributes from web.xml to ejb annotations).

For this example, we already have an Apache Directory Server running locally, with the sample LDIF with the sevenSeas company imported. You can find the file and tutorial in the Apache DS documentation.

There are two main steps to be able to use LDAP as an authentication mechanism:

  1. Configure JBoss to connect to LDAP server
  2. Configure the application to use the application policy

Configure JBoss to connect to LDAP server

The JBoss connects to the LDAP server using an application-policy, which is configured in %server_path%/conf/login-config.xml

Just add the following entry in the login-config.xml. You can see the description of the important attributes:

com.sun.jndi.ldap.LdapCtxFactory ldap://localhost:10389 simple uid=admin,ou=system secret ou=people,o=sevenSeas (uid={0}) ou=groups,o=sevenSeas (uniquemember={1}) cn SUBTREE_SCOPE 0 true

As you can see, the bindCredential is not encrypted. In order to do so, you can check out our post about securing the LdapExtLoginModule.

Configure the web application to use the application policy

First, we need to connect the java web application to the application policy defined in JBoss. In order to do this, you need to create the file jboss-web.xml in the WEB-INF folder, the same folder where the web.xml resides.

Here is the content of the file (this works for JBoss 5 in a windows machine, you may need to change the header of the file):


This will tell the container to use the ApacheDS application-policy we defined previously in JBoss.

After this, we only need to restrict the specific urls or servlets to certain roles. In this example, we will only allow access for users in the group “HMS Bounty”, otherwise a 403 (forbidden) will be issued.

In order to do this, we need to edit the web.xml file, adding the following configuration:

AServlet AServlet /AServlet All resources All resources /* HMS Bounty BASIC

Following this example, you can restrict access to different resources to other roles.

Configure an EJB based WS to use the application policy

If, in turn, you want to secure an EJB based WS, just adding these annotations at the start of the implementing class will do:

@org.jboss.wsf.spi.annotation.WebContext(contextRoot=”MyCtxRoot” , authMethod = “BASIC”, secureWSDLAccess = false) @org.jboss.ejb3.annotation.SecurityDomain( “java:/jaas/ApacheDS” ) @RolesAllowed(“HMS Bounty”) public class MyWSImplementation implements MyWSInterface{

See more posts
Have a project or an idea?
Let's make it real!
Prefer a meeting?
Book a meeting or call us (512) 842 9784
Yes! Book me
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.