oktadev / okta-spring-session-redis-example

Spring Session + Redis Example for Scaling Spring Security

Home Page:https://developer.okta.com/blog/2020/12/14/spring-session-redis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple Session Sharing for JHipster with Spring Session + Redis

This repository contains all the code for using Spring Session + Redis in a JHipster microservices architecture, with Okta for authentication and HAProxy load balancer for load balancing. Please read Scaling Secure Applications with Spring Session and Redis to see how it was created.

Prerequisites:

Okta has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage and secure users and roles in any application.

Getting Started

To run this example, run the following commands:

git clone https://github.com/oktadev/okta-spring-session-redis-example.git
cd okta-spring-session-redis-example

Create the OIDC Application in Okta

Register for a free developer account with the following simple commands using the Okta CLI, in the project root folder:

okta register

Provide the required information. Once you register, create a client application in Okta with the following command:

okta apps create

You will be prompted to select the following options:

  • Type of Application: 1: Web
  • Type of Application (again): 3: JHipster

The application configuration will be generated in the file .okta.env and it will look like this:

export SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI="https://{yourOktaDomain}/oauth2/default"
export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID="{clientId}"
export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET="{clientSecret}"

Create a file docker-compose/.env and set the value of the OKTA_OAUTH_* environment variables for Docker Compose, copy the values from .okta.env:

OKTA_OAUTH2_ISSUER=https://{yourOktaDomain}/oauth2/default
OKTA_OAUTH2_CLIENT_ID={clientId}
OKTA_OAUTH2_CLIENT_SECRET={clientSecret}

Run with Docker Compose

Go through each application store, product, invoice, notification and build the container images with Maven:

./mvnw -ntp -Pprod verify jib:dockerBuild

Run the services with Docker Compose:

cd docker-compose
docker compose up

The JHipster registry will log the following message once it is ready:

... | 2022-03-08 17:44:26.245  INFO 1 --- [           main] t.jhipster.registry.JHipsterRegistryApp  :
... | ----------------------------------------------------------
... | 	Application 'jhipster-registry' is running! Access URLs:
... | 	Local: 		http://localhost:8761/
... | 	External: 	http://172.19.0.11:8761/
... | 	Profile(s): 	[composite, dev, api-docs, oauth2]
... | ----------------------------------------------------------
... | 2022-03-08 17:44:26.246  INFO 1 --- [           main] t.jhipster.registry.JHipsterRegistryApp  :
... | ----------------------------------------------------------
... | 	Config Server: 	Connected to the JHipster Registry running in Docker
... | ----------------------------------------------------------

You can sign in to http://localhost:8761/ to check if all services are up.

Once all services are up, access the store at http://localhost:8080 and sign in with your Okta credentials.

Links

This example uses the following open source libraries from Okta:

Help

Please post any questions as comments on the blog post, or visit our Okta Developer Forums.

License

Apache 2.0, see LICENSE.

About

Spring Session + Redis Example for Scaling Spring Security

https://developer.okta.com/blog/2020/12/14/spring-session-redis

License:Apache License 2.0


Languages

Language:Java 66.8%Language:TypeScript 29.2%Language:HTML 2.0%Language:JavaScript 1.0%Language:SCSS 0.6%Language:CSS 0.2%Language:Shell 0.2%Language:Batchfile 0.0%Language:Dockerfile 0.0%