[keycloak-user] No 'Access-Control-Allow-Origin' header is present on the requested resource

Grant Marrow grantmarrow at gmail.com
Wed Nov 16 14:08:59 EST 2016


Hi,

I really need some help. I keep on getting the following error:


*No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:9000 <http://localhost:9000/>' is
therefore not allowed access. The response had HTTP status code 500.*

This is my setup:

*Front End:*
- angular 1.5 web application running at http://localhost:9000
- client configuration on keycloak admin console:
- keycloak.json:

{
  "realm": "leap",
  "auth-server-url": "http://localhost:8080/auth",
  "ssl-required": "external",
  "resource": "leap-web",
  "public-client": true
}


*Auth Server*
- keycloak version 2.30Final running at http://localhost:8080

*Web service*
- java REST service running on Tomcat version 8.5
- client config on keycloak admin console:
- web.xml of rest service:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="
http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">
  <display-name>Archetype Created Web Application</display-name>
  <module-name>leap-service</module-name>
 <listener>
    <listener-class>com.hm.leap.service.init.ContextListener</listener-class>

  </listener>
<context-param>
<param-name>persistentUnit</param-name>
<param-value>leap</param-value>
</context-param>

  <security-constraint>
  <web-resource-collection>
  <web-resource-name>Leap-Service</web-resource-name>
  <url-pattern>/resources/private/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
  <role-name>user</role-name>
  </auth-constraint>
  </security-constraint>

   <login-config>
        <auth-method>KEYCLOAK</auth-method>
        <realm-name>leap</realm-name>
   </login-config>

  <security-role>
  <role-name>user</role-name>
  </security-role>

</web-app>

- I also have the valve setup on my context.xml that lives in the META-INF
directory
<Context path="/leap-service">
<Valve
className="org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve"/>

</Context>

- keycloak.json:

{
  "realm": "leap",
  "bearer-only": true,
  "auth-server-url": "http://localhost:8080/auth",
  "ssl-required": "external",
  "resource": "leap-service",
  "enable-cors": true
}

The error occurs in the following scenario:
- The angular web app launches, the user clicks the login button which
redirects to Keycloak. The user signs in. The user then tries navigates to
another page. This page then executes a GET request on my REST service
which returns a list which is displayed in a table. But while executing the
GET request, I receive the error:

*No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:9000 <http://localhost:9000/>' is
therefore not allowed access. The response had HTTP status code 500.*

In my Tomcat log file. I see the following warning message:


*11-Nov-2016 11:28:19.464 WARNING [http-nio-8081-exec-2]
org.apache.catalina.authenticator.FormAuthenticator.forwardToLoginPage No
login page was defined for FORM authentication in context [/leap-service]*

I really can't seen to pinpoint the error. I find it quite strange because
I have the same setup but using an older version of keycloak (1.9*), which
worked fine. I know this might be a silly problem, but if you have some
time to help me, I would really appreciate it. Thanks.

Regards
Grant


More information about the keycloak-user mailing list