Code Monkey home page Code Monkey logo

spring-webflux-keycloak-demo's Introduction

Reactive Spring Security with OAuth2 and Keycloak (demo)

This repository demonstrates how to use reactive Spring Security with OAuth2 and Keycloak.

Keycloak server with all components can be started using docker-compose and utility script.

Features

  • OAuth2 resource server.
  • Keycloak integration.
  • Reactive method security.
  • Reactive test support.
  • Wiremock integration.
  • Automated script for creation of demo realm.
  • Postman collection with Oauth2 setup.

Getting Started

Prerequisites

  • Java 11
  • Docker
  • Docker Compose

Usage

  • Start docker compose (keycloak and postgres)

    cd docker
    
    docker-compose up -d
  • Check if all services started.

    docker-compose ps   
    
    # Name                     Command               State                Ports
    # ---------------------------------------------------------------------------------------------
    # docker_keycloak_1   /opt/jboss/tools/docker-en ...   Up      0.0.0.0:8081->8080/tcp, 8443/tcp
    # docker_postgres_1   docker-entrypoint.sh postgres    Up      5432/tcp
  • Open your web browser and go to Keycloak login page. On the login page, enter admin for a username and password.

  • Start creation script for demo realm.

    sh setupDemoRealm.sh
    
    # Starting creation of demo realm. Your clientId: spring_keycloak_demo_client clientSecret: 9ee1dcb4-4983-4ee5-b8a2-ae384f6fc4e5
    # Logging into http://localhost:8080/auth as user admin of realm master
    # Created new realm with id 'demo'
    # Created new client-scope with id '706cd55d-0c22-4596-bdfe-ee9e35bc5c73'
    # Created new client with id '619b7a78-61eb-4d98-8bce-0b85801d36f6'
    # Created new role with id 'ROLE_USER'
    # Created new role with id 'ROLE_ADMIN'
    # Created new user with id '2dac543f-7c8a-4a89-9487-c054f03a2a5b'
    # Created new user with id 'e06db8fc-e401-424f-803e-8191abe8857c'
  • Verify that demo realm and users exist in Keycloak. keycloak-demo-realm.png

  • Start resource server.

    ./gradlew bootRun
  • Import postman collection (demo.postman_collection.json).

  • Get the OAuth Access Token from Postman. postman-get-oauth-token.png

  • Use demo_user/demo_user or demo_admin/demo_admin credentials inside Keycloak login popup.

  • Play with API.

  • Stop demo and cleanup volumes.

    docker-compose down -v

Additional tips

Record stub mappings using WireMock

References

License

Distributed under the MIT License. See LICENSE for more information.

spring-webflux-keycloak-demo's People

Contributors

rbiedrawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

spring-webflux-keycloak-demo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.