Table of Contents
Your favourite Java IDE
Spring Boot CLI: https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-installing-spring-boot.html#getting-started-installing-the-cli
Git client
Heroku account: https://signup.heroku.com/
Heroku CLI: https://devcenter.heroku.com/articles/heroku-cli
CXN Pass account: https://pass.chemaxon.com/
Optionally check these to verify settings:
Open http://localhost:8080/health
The easiest way to create a welcome page is to add an index.html
to src/main/resources/static/
:
Our application’s app-info endpoint should look like this:
We define the following features here:
The health endpoint that Synergy uses to check if your application is running fine
The icon that is used in Synergy for your application
The logout endpoint that Synergy calls when a user logs out from Synergy (we will implement this later)
A service called producer-service
, that is a sample for a custom service provided by your application (we will implement this later)
To learn more about these features, check the Synergy Feature Catalogue.
The class should be placed in the com.example
package so that Spring Boot finds it automatically.
Open http://localhost:8080/app-info
If you send us your deployment’s application info URL, we’ll register it for you.
Add new dependencies in your pom.xml
:
It can be done by adding @EnableOAuth2Sso
annotation.
Security must be disabled on health and app-info endpoints.
Create class SynergySecurityConfiguration
, extend WebSecurityConfigurerAdapter
and override configure method:
Rename empty config file application.properties
to application.yml
.
Add these to application.yml
:
Ask for your client id and client secret!
There should be a redirect to authenticate you when opening the application. (You might not notice it, when already logged in to Synergy.)
The logged in user's info is contained in the JWT access token provided by Synergy. To demonstrate how it can be accessed, we will print it on the welcome page.
Create class SynergyAccessTokenConfigurer
and implement JwtAccessTokenConverterConfigurer
:
In order to do this, we will convert index.html
to a template. We will use Thymeleaf as our template engine, so you need to add the following dependency to your pom.xml
:
In order to convert index.html
to a template, we need to move it from src/main/resources/static/
to src/main/resources/templates/
. Once it's a template, we can add the user info:
We also need to create a controller that uses the template, let's call it IndexPageController
:
When opening your application, you should see the user info contained in the access token from Synergy.
Public rest enpoints must understand Synergy tokens sent in a http header.
Create new class ResourceServerConfiguration
:
Notice here we have created a RequestMatcher
to separate API calls. For now it is matched when request contains an Authorization
header (which should contain the token).
Now SSO is only configured for requests which are not handled by the resource server configuration.
We will discuss two forms of logout. In the first case the logout will be initiated from your application, in the second case it will be initiated from Synergy.
We suggest logging users out of Synergy too when they log out of your application. This allows users to log in as a different user after they log out from your application. In order to implement this, you need to redirect users to Synergy's logout URL after your application has successfully logged them out. That can be set in SynergySecurityConfiguration
:
To add a logout button to the welcome page, change index.html
:
Pressing this logout button will log you out from both your application and Synergy.
When users log out from Synergy, they expect they will be logged out from the connected applications too. This can be achieved for your application by implementing the synergy/logout feature that we already registered with the application info above. This requires an endpoint for front-channel logout, which we will configure in a new class called FrontChannelLogoutConfig
:
If you now log out from either your application or Synergy, you will be logged out from both.
It configures a rest service client to forward the current OAuth2 token in Authorization
header of each request.
It’s a client for Synergy service discovery.
It contains an 2 endpoint for consuming another application’s producer service:
one using the token of the logged in user /consume
one is requesting a new token in the name of your application (server-to-server communication) /consume-as-app