Why is Tomcat manager using my LoginModule?

回眸只為那壹抹淺笑 提交于 2020-01-02 21:53:44

问题


I'm running Tomcat 6.0.29 and created a realm and loginmodule of my own. They are defined in server.xml like so:

<Realm className="mycompany.tomcat.MyRepositoryRealm" appName="My_Realm" userClassNames="mycompany.tomcat.IdentityPrincipal" roleClassNames="mycompany.tomcat.RolePrincipal" useContextClassLoader="true"/>

I have added the library containing these classes to my tomcat/lib folder. Other than that, I have not changed Tomcat from it's default configuration.

When I go to fire up the Tomcat manager application at http://localhost:9080/manager/html, I can't log in and the tomcat log shows an error and stacktrace for my login module.

Any ideas? Thanks!

Edit:

Per request, here is the stacktrace. My realm connects to a JBoss service, so that's why I get the NamingContextFactory error.

javax.security.auth.login.LoginException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory at mycompany.tomcat.MyRepositoryLoginModule.login(MyRepositoryLoginModule.java:88) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769) at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186) at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680) at javax.security.auth.login.LoginContext.login(LoginContext.java:579) at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:410) at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:335) at mycompany.tomcat.MyRepositoryRealm.authenticate(MyRepositoryRealm.java:34) at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:181) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619)


回答1:


I was able to figure out the problem.

Security realms can be defined for an engine, host, or context. I had defined the realm for the whole host (in server.xml), so the tomcat manager application was trying to use it. I fixed the problem by defining the realm in a META-INF/context.xml file inside of my web application.



来源:https://stackoverflow.com/questions/3859160/why-is-tomcat-manager-using-my-loginmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!