Wednesday, August 22, 2007

Tomcat, JAAS and config file

As you know Tomcat is able to use JAAS Login Module for Realm authentication. But if you use standard implementation you should start Tomcat with parameter$CATALINA_HOME/conf/jaas.config, where jaas.config is your JAAS configuration file.

So I extended JAASRealm with jaasConfigFile attribute.

package my.realm;

import org.apache.catalina.realm.JAASRealm;

 * This is customization of JAASRealm, created for taking ability of setting JAAS Config File via realm properties.
 * @author Sergey Vinogradov
public class GDJaasRealm extends JAASRealm {
    private String jaasConfigFile;

    public void init() {
        System.setProperty("", jaasConfigFile);


    public String getJaasConfigFile() {
        return jaasConfigFile;

    public void setJaasConfigFile(String jaasConfigFile) {
        this.jaasConfigFile = jaasConfigFile;

Thus you may declare this Realm at server.xml instead of org.apache.catalina.realm.JAASRealm
<Realm className="my.realm.GDJaasRealm"                 


Mohsin Khan said...

Do you have sample application for this

for IT the said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.