Skip to content

Jaas Basic Authentication tomcat 7

I keep on getting the same error, I have already changed the tomcat7w file that specifies the jaas config file location

        javax.security.auth.login.LoginException: No LoginModules configured for    JaaSExample:
        at javax.security.auth.login.LoginContext.init(LoginContext.java:273)
    at javax.security.auth.login.LoginContext.<init>(LoginContext.java:514)
    at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:417)
    at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:356)
    at org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:146)
    at org.apache.catalina.realm.LockOutRealm.authenticate(LockOutRealm.java:180)
    at    org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:166)
    at  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:574)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

I have already added this tom my tomcat7w.exe file.

    -Djava.security.auth.login.config=C:Program Files (x86)Apache Software                 FoundationTomcat 7.0confjaas.config

another is that I also have this realm

    <Realm className="org.apache.catalina.realm.JAASRealm" 
    appName="JaaSExample"
    userClassNames="Security.UserPrincipal" roleClassNames="Security.RolePrincipal" />

so what am I missing? please help me,

I am using netbeans, tomcat 7.0.47.

thank you very much,

I have resolved to using glassfish!

Answer

According to http://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html#JAASRealm

You should set up a login.config file for Java and tell Tomcat where to find it by specifying its location to the JVM, for instance by setting the environment variable: JAVA_OPTS=$JAVA_OPTS -Djava.security.auth.login.config=$CATALINA_BASE/conf/jaas.config

Added

For Windows open startup.bat Add the following line: set JAVA_OPTS=%JAVA_OPTS% -Djava.security.auth.login.config=%CATALINA_HOME%/conf/jaas.config after okHome

e.g.

set JAVA_OPTS=%JAVA_OPTS% -Djava.security.auth.login.config=%CATALINA_HOME%/conf/jaas.config
set "EXECUTABLE=%CATALINA_HOME%bincatalina.bat"