Awesome Open Source
Awesome Open Source


Demo for configuring Keycloak authentication for a spring-boot rest service and AngularJs web client


  • Keycloack (1.1.0) server installed
  • Java (1.8)
  • Maven (3.2.2)
  • Source code


  1. Clone

  2. Download (or later version).

Start keycloack and import the realm provided with the source code.

  1. Start the rest server:

mvn spring-boot:run 4. Start the angular application

mvn spring-boot:run 5. Go to localhost:7005 and login using user/pass.

  1. Press reload to create a hello-world request to server.


As all three applications run on different domains, we have to configure CORS.

Enable CORS in rest project

In keycloak.json a new line has to be added:

"enable-cors": true Also, CORSFilter has to be added in order to provide required headers for XMLHttpRequests.

AngularJS project configuration

The application must be public. Also, configure the web origin and the matching redirect URL.

Spring Security Context

In some cases we may need to access the user in context. Keycloak configuration is configured at container level, so Spring Security filters cannot be used.

Add security context dependency in order to have SpringContextHolder class. Do not use spring-boot-security as then the web application will be secure by default with ‘basic’ authentication on all HTTP endpoints.

We can add a simple HttpFilter which sets the securityContext:


For writing integration tests we need Kecloak's Direct Access API.


Alternatives To Keycloak Spring Boot Rest Angular Demo
Select To Compare

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,090,062
Security (31,926
Rest (29,241
Spring (28,670
Authentication (26,919
Spring Boot (16,046
Angularjs (11,901
Cors (2,974
Keycloak (1,304
Keycloak Configuration (3