DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Leveraging Salesforce Using Spring Boot
  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service

Trending

  • Don't Adopt Anything Announced at re:Invent for 90 Days
  • Designing Distributed Counters: A Redis Challenge for Frontend Engineers
  • Five Common Time-Series Queries Made Simple With Enterprise Java
  • Building Enterprise Desktop, Web, Mobile, and Docker Applications From One Shared Platform

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Boot REST Service Protected Using Keycloak Authorization Services

Spring Boot REST Service Protected Using Keycloak Authorization Services

Learn more about one open-source IAM solution that provides authentication and authorization to protect Spring Boot REST services.

By 
ravinder thirumala
·
Updated Jan. 24, 20 · Presentation
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
17.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Keycloak is an open-source Identity and Access Management (IAM) solution aimed at modern applications and services. Keycloak provides out-of-the-box authentication and authorization services as well as advanced features like User Federation, Identity Brokering, and Social Login.

Keycloak provides fine-grained authorization services as well. This allows you to manage permissions for all your services from the Keycloak admin console and gives you the power to define exactly the policies you need.

We are going to see how to use Keycloak Authorization services to protect REST APIs by using a set of permissions and policies defined in Keycloak. Access to these APIs is enforced by a policy enforcer that intercepts every REST call.

Spring Boot and Keycloak

Keycloak Client Adapters makes it really easy to secure applications and services. The Client Adapter is available for a number of platforms and programming languages. There are adapters for JBoss EAP/Wildfly, Spring Boot, Angular, NodeScript, and JavaScript.

We will write a RESTful service with SpringBoot and then secure it with Keycloak. Here, we will create REST API for course management at a university. Before that, we need to set up Keycloak Server.

Set Up Keycloak

Download Keycloak from here, unzip, and start the Keycloak using the following:

./standalone.sh(bat)


In your browser, go to http://localhost:8080/auth/.

Since it’s the first time that the Keycloak server is running, you will have to create an admin user, so let’s create an admin user with admin as the username and password as admin.

Keycloak admin dashboard

Now, log in to Keycloak using admin user and start configuring Keycloak; the admin user is created in the default realm called master.

A realm secures and manages security metadata for a set of users, applications, and registered oauth clients. Users can be created within a specific realm within the Administration console. Roles (permission types) can be defined at the realm level and you can also set up user role mappings to assign these permissions to specific users.

Creating a Realm

Now, we will create a new realm called University using Add Realm button under master Realm.adding a realm

Now, create a client called Course-managment under University realm; we are going to secure course-management Client, which provides REST Service for managing university courses.

securing course-management client

Here, you need to note we are setting Access Type as confidential and set Authorization Enabled to on so we can configure set permissions for our course-management REST API services.

REST Web Protocols Keycloak Spring Framework Spring Boot authentication

Opinions expressed by DZone contributors are their own.

Related

  • Leveraging Salesforce Using Spring Boot
  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook