Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't the Keycloak with Spring Boot tutorial work?

Tags:

keycloak

I've been trying to follow the Keycloak tutorial from DZone (EDIT: which seems to be a nearly verbatim repost from the tutorial on the official Keycloak blog, apparently by the same author), but I've run into the following problems:

  • index.html not being found

  • when clicking on the link to the interior page, the error

    We're sorry...

    Page not found

  • on that same page, the error

    javax.servlet.ServletException: Circular view path [products]: would dispatch back to the current handler URL [/products] again.

  • the Keycloak admin panel appearing instead of the sample app

What am I doing wrong?

like image 514
SOLO Avatar asked May 10 '18 18:05

SOLO


1 Answers

There are a number of subtle but significant inconsistencies/typos in that tutorial. In order of appearance:

Main tutorial

  1. the location of index.html is given as /src/resources/static. If you are using Spring Initializr, the pre-made code will have both main and test directories under src, so the correct location will instead be src/main/resources/static.

  2. In the code for the controller, line 9 is

    return "products";
    

    This tells Spring to use products.html. The actual HTML file will be product, singular, because it is generated from product.ftl. Take the 's' off of the return value.

  3. In the application.properties file, one of the lines given is

    keycloak.realm=springboot
    

    Earlier, when in the Keycloak admin panel, the guide suggested naming the realm "SpringBoot". These values need to match, and they are case-sensitive. Change either one.

  4. After setup is complete, the instructions say

    Now browse to “http://localhost:8080”

    The correct URL is http://localhost:8081, since server.port was set to 8081 in application.properties. Port 8080 should still be in use by the admin console.

With these changes, the test app should load and behave as described.

Adding Spring Security

Be careful not to reintroduce the products/product typo when copying in the new getProducts() method.

like image 109
SOLO Avatar answered Sep 19 '22 04:09

SOLO