Skip to content

oktadev/okta-spring-session-redis-example

 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published

Languages

  • Java 66.8%
  • TypeScript 29.2%
  • HTML 2.0%
  • JavaScript 1.0%
  • SCSS 0.6%
  • CSS 0.2%
  • Other 0.2%