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:
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:
As you can see, the bindCredential is not encrypted. In order to do so, you can check out our post about securing the LdapExtLoginModule.
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:
Following this example, you can restrict access to different resources to other roles.
If, in turn, you want to secure an EJB based WS, just adding these annotations at the start of the implementing class will do: