title: javax.security.auth.login.LoginException: No LoginModules configured for SomeLogin
body: <p>Well I'm trying to create JAAS authentication for my Servlet (running on Tomcat 7 in Eclipse), but I'm getting this error.</p>
  
  <p>He're's the complete stack trace:
  '`</p>
  
  <pre><code>INFO: Starting Servlet Engine: Apache Tomcat/7.0.32
  Geg 19, 2013 9:53:08 PM org.apache.coyote.AbstractProtocol start
  INFO: Starting ProtocolHandler ["http-bio-8080"]
  Geg 19, 2013 9:53:08 PM org.apache.coyote.AbstractProtocol start
  INFO: Starting ProtocolHandler ["ajp-bio-8009"]
  Geg 19, 2013 9:53:08 PM org.apache.catalina.startup.Catalina start
  INFO: Server startup in 1786 ms
  Geg 19, 2013 9:53:30 PM org.apache.catalina.realm.JAASRealm authenticate
  SEVERE: Unexpected error
  javax.security.auth.login.LoginException: No LoginModules configured for GdiaLogin
      at javax.security.auth.login.LoginContext.init(Unknown Source)
      at javax.security.auth.login.LoginContext.&lt;init&gt;(Unknown Source)
      at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:392)
      at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:332)
      at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:158)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:544)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  
  Geg 19, 2013 10:29:20 PM org.apache.catalina.realm.JAASRealm authenticate
  SEVERE: Unexpected error
  javax.security.auth.login.LoginException: No LoginModules configured for GdiaLogin
      at javax.security.auth.login.LoginContext.init(Unknown Source)
      at javax.security.auth.login.LoginContext.&lt;init&gt;(Unknown Source)
      at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:392)
      at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:332)
      at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:158)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:544)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>`</p>
  
  <p>In context.xml:</p>
  
  <pre><code>&lt;Realm className="org.apache.catalina.realm.JAASRealm" 
  appName="GdiaLogin"
  userClassNames="org.ktu.gdia.core.security.UserPrincipal"
  roleClassNames="org.ktu.gdia.core.security.RolePrincipal" /&gt;
  </code></pre>
  
  <p>In jaas.config (I'm pretty sure Tomcat finds it correctly because I added the correct path with arguments for "run configurations" in eclipse):</p>
  
  <pre><code>  GdiaLogin {
      org.ktu.gdia.core.security.GdiaLoginModule required debug=true;
  };
  </code></pre>
  
  <p>I'm assuming there has to be something wrong with the jaas.config...</p>
  
  <p>My Login Module, not sure if I need to provide it here, though, it's almost straight from a tutorial I've been following:</p>
  
  <pre><code>    package org.ktu.gdia.core.security;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  
  import javax.security.auth.Subject;
  import javax.security.auth.callback.Callback;
  import javax.security.auth.callback.CallbackHandler;
  import javax.security.auth.callback.NameCallback;
  import javax.security.auth.callback.PasswordCallback;
  import javax.security.auth.callback.UnsupportedCallbackException;
  import javax.security.auth.login.LoginException;
  import javax.security.auth.spi.LoginModule;
  
  import org.ktu.gdia.core.businesslogic.ControllerFactory;
  import org.ktu.gdia.core.interfaces.SecurityControllerInterface;
  
  public class GdiaLoginModule implements LoginModule {
  
    private CallbackHandler handler;
    private Subject subject;
    private UserPrincipal userPrincipal;
    private RolePrincipal rolePrincipal;
    private String login;
    private List&lt;String&gt; userGroups;
  
    private SecurityControllerInterface securityController;
  
  
    @Override
      public void initialize(Subject subject, CallbackHandler callbackHandler,
              Map&lt;String, ?&gt; sharedState, Map&lt;String, ?&gt; options) {
  
        try {
  
          securityController = ControllerFactory.getInstance().getSecurityController();
  
      } catch (ClassNotFoundException | InstantiationException
              | IllegalAccessException e) {
  
          throw new RuntimeException("Failed to initialize SecurityController in " + this.getClass().getSimpleName(), e);
      }
        handler = callbackHandler;
        this.subject = subject;
    }
  
    @Override
    public boolean login() throws LoginException {
  
      Callback[] callbacks = new Callback[2];
      callbacks[0] = new NameCallback("login");
      callbacks[1] = new PasswordCallback("password", true);
  
      try {
        handler.handle(callbacks);
        String name = ((NameCallback) callbacks[0]).getName();
        String password = String.valueOf(((PasswordCallback) callbacks[1])
            .getPassword());
  
        // Here we validate the credentials against some
        // authentication/authorization provider.
        // It can be a Database, an external LDAP, 
        // a Web Service, etc.
        // For this tutorial we are just checking if 
        // user is "user123" and password is "pass123"
  
        if (securityController.credentialsValid(name, password)) {
  
            // TODO authenticate
  
            login = name;
            userGroups = new ArrayList&lt;String&gt;();
            userGroups.add("admin");
            return true;
  
        }
  
        if (name != null &amp;&amp;
            name.equals("user123") &amp;&amp;
            password != null &amp;&amp;
            password.equals("pass123")) {
  
          // We store the username and roles
          // fetched from the credentials provider
          // to be used later in commit() method.
          // For this tutorial we hard coded the
          // "admin" role
          login = name;
          userGroups = new ArrayList&lt;String&gt;();
          userGroups.add("admin");
          return true;
        }
  
        // If credentials are NOT OK we throw a LoginException
        throw new LoginException("Authentication failed");
  
      } catch (IOException e) {
        throw new LoginException(e.getMessage());
      } catch (UnsupportedCallbackException e) {
        throw new LoginException(e.getMessage());
      }
  
    }
  
    @Override
    public boolean commit() throws LoginException {
  
      userPrincipal = new UserPrincipal(login);
      subject.getPrincipals().add(userPrincipal);
  
      if (userGroups != null &amp;&amp; userGroups.size() &gt; 0) {
        for (String groupName : userGroups) {
          rolePrincipal = new RolePrincipal(groupName);
          subject.getPrincipals().add(rolePrincipal);
        }
      }
  
      return true;
    }
  
    @Override
    public boolean abort() throws LoginException {
      return false;
    }
  
    @Override
    public boolean logout() throws LoginException {
      subject.getPrincipals().remove(userPrincipal);
      subject.getPrincipals().remove(rolePrincipal);
      return true;
    }
  
  }
  </code></pre>
  
  <p>Edit: My run configuration arguments in eclipse for tomcat:</p>
  
  <pre><code>-Dcatalina.base="D:\Dropbox\EclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp7" -Dcatalina.home="D:\Servers\GenTreeUploader_Tomcat7" -Dwtp.deploy="D:\Dropbox\EclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp7\wtpwebapps" -Djava.endorsed.dirs="D:\Servers\GenTreeUploader_Tomcat7\endorsed" -Djava.security.auth.login.config="D:\Dropbox\EclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp7\conf\jaas.config"
  </code></pre>
  
  <p>Well? Any ideas?</p>