October 28, 2018

Using JAAS in Tomcat Example

JAAS is part of the Java SE since Java 5, so choosing that API, when you want to deploy to only a web container, such as Tomcat or Jetty, is a good choice.

/META-INF/context.xml. See where best to put your configuration How to handle Configuration in Tomcat with Context


<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Realm className="org.apache.catalina.realm.JAASRealm" 
    appName="BytesLoungeLogin"
    userClassNames="com.byteslounge.jaas.UserPrincipal"
    roleClassNames="com.byteslounge.jaas.RolePrincipal" />
</Context>

$CATALINA_BASE/conf/jaas.config


BytesLoungeLogin {
    com.byteslounge.jaas.BytesLoungeLoginModule required debug=true;
};

And starting


JAVA_OPTS=$JAVA_OPTS "-Djava.security.auth.login.config==$CATALINA_BASE/conf/jaas.config"

JAAS authentication in Tomcat example

No comments: