Giter Club home page Giter Club logo

springone2019's Introduction

Multi-tenancy with OAuth 2.0 and Spring Security

This repo consists of four Spring Boot applications that are secured using Spring Security and OAuth 2.0.

For the application to work, please take the following steps after cloning to your local machine:

  1. Modify your /etc/hosts file

    The demo code points to the endpoint idp:9999 for the Identity Provider. It also refers to each tenant by hostname. So, your machine can resolve this hostname on its own by adding the following to /etc/hosts:

    127.0.0.1   idp
    127.0.0.1   one
    127.0.0.1   two
    127.0.0.1   three
    127.0.0.1   four

    You may need sudo privileges to edit the file.

  2. Start the keycloak docker container

    These demos work with a pre-configured Authorization Server, which you can start up with the following command inside the /etc directory of the demo:

    docker-compose up -d

    Thereafter, you can stop this server with:

    docker-compose stop

    And start it with:

    docker-compose start
  3. Configure tenant

    To do the more advanced demo of adding a tenant dynamically, the tenant application needs to be configured with the master-realm password in Keycloak.

    To do this

     - Log into Keycloak at http://idp:9999 with admin/asdfasdfasdf
     - Select the `master` realm
     - Select `Clients`, and select `master-realm`
     - Change `Access Type` to `confidential`
     - Disable `Direct Access Grants Enabled`
     - Enable `Service Accounts Enabled`
     - Save the client
     - Go to the `Service Account Roles` tab
     - Add `admin` to the effective roles
     - Go to the `Credentials` tab
     - Copy the secret into the `tenant` `application.yml` file
    
  4. Start the servers

    There are four servers, message, user, inbox, tenant. To start each one, you can simply run from the command line from each directory:

    ../mvnw spring-boot:run
  5. Use the application:

    When you navigate to http://one:8080, you'll be invited to authenticate. You can do:

    • rob / password
    • joe / password
    • josh / password

    When you navigate to http://two:8080, you'll be invited to authenticate as well. You can do:

    • filip / password
    • ria / password
    • josh / password
  6. Add a tenant

    To add a tenant, simple run from the etc directory in the project:

    ./add-tenant three

    Then, you'll be able to navigate to http://three:8080 and be invited to authenticate. You can do:

    • rob / password
    • joe / password
    • josh / password

Also, take a look at the Java to HTTP mappings for the Spring Security-powered OAuth 2.0 handshakes.

springone2019's People

Contributors

jzheaux avatar

Watchers

James Cloos avatar

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.