Subject: KeyCloak poses no login challenge or throws NullPointer for web apps deployed in
Tomcat 7
I wrote a simple reactJS web app ("/rtna2") deployed under Tomcat 7. I followed
the steps below, but keycloak does not seem to work - no login challenge was posed, and
when I type https://<my server ip>/rtna2, it went straight to the the web app. I
did similar set up for one of our existing webapp deployed in Tomcat 7, this one throws
Null pointer exception:
HTTP Status 500 -
type Exception reportmessagedescription The server encountered an internal error that
prevented it from fulfilling this request.exceptionjava.lang.NullPointerException
org.keycloak.adapters.PreAuthActionsHandler.preflightCors(PreAuthActionsHandler.java:107)
org.keycloak.adapters.PreAuthActionsHandler.handleRequest(PreAuthActionsHandler.java:79)
org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:190)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.69
logs.
Here are the steps I performed:
1 - download the tomcat 7 keycloak adaptor zip and unzip in my tomcat lib/2 - rtna2 app is
deployed under tomcat webapps/3 - modify rtna2/META-INF/context.xml:
<?xml version="1.0" encoding="UTF-8"?><Context
path="/rtna2" debug="0" privileged="true" > <Valve
className="org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve"/></Context>4
- add keycloak.json under rtna2/WEB-INF:
{ "realm": "rtna", "realm-public-key":
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhvJlVZqi8KaZDZVPPl29y/nnPBHaPvH+NoG71w6BMDwIImw6vkNlO3CSr+kRAyLnpnP/9248gEZx6YwqEKwE4Oy5R6wuuxwOd2FdpYFM2wDw5zhF7U4oYy0WK1m31/hQdLGnpKtDdGReEwdkMOMtG655Nnqw8WdtmF3S2XcEm2t0gaNoYycd6gl4670nRqx6bRxs6UndERHZmHfkzLcL71RflgO1cyuOqMsjMb7oWIDy5bkE4ddB69TAbrpXVzLvwG1OIaM/XdfXOZIaIAajfacP3Vk8bZFa9eAsh5BVaeGzlqktsdk1JjbV0a14OVXQcCRusnV2wE+zSZhPNxhfFwIDAQAB",
"auth-server-url": "https://135.112.180.27:8666/auth",
"ssl-required": "external", "resource": "rtna2",
"public-client": true}
5. modify rtna2/WEB-INF/web.xml:
<?xml version="1.0" encoding="UTF-8"?><web-app
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >
<!-- Default page to serve
--><module-name>rtna2</module-name><welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> <security-constraint>
<web-resource-collection>
<web-resource-name>rtna2</web-resource-name>
<url-pattern>/rtna2/*</url-pattern>
</web-resource-collection> <auth-constraint>
<role-name>*</role-name> </auth-constraint>
</security-constraint>
<login-config> <auth-method>BASIC</auth-method>
<realm-name>rtna</realm-name> </login-config>
<security-role> <role-name>admin</role-name>
</security-role> <security-role>
<role-name>user</role-name> </security-role>
<security-role> <role-name>sudo</role-name>
</security-role></web-app>
I have tried "<auth-method>KEYCLOAK</auth-method>" also, does not
work
6. in the keycloak admin console, added a "rtna" realm, and added
"rtna2" client in the realm:
client id: rtna2Access type: public (tried "confidential" also)Authorization
enabled: on ("off" also)Root URL: https://135.112.180.27/rtna2Valid Redirect
URLs: https://135.112.180.27/rtna2/*Base URL: https://135.112.180.27/rtna2Admin
URL: https://135.112.180.27/rtna2Web Origins: https://135.112.180.27/rtna2/*
I found relative paths for these URLs do not work, it gave me Http 404 not found
(
https://135.112.180.27/rtna2) error. But once I put the absolute paths, it took me right
to the web app without posing the login challenge!
What could possibly be wrong? Please advise! Thanks!!