Starting the journey with the ASGARDEO — Integrating your Spring web app with Asgardeo

Shamodya Hashantha
5 min readNov 2, 2021

--

Hi Folks,

Asgardeo is the newly introduced IDaaS solution by WSO2. Asgardeo brings up all the identity and access management functionalities to the cloud-native platform to cater to any requirement within the IAM domain. Additionally, Asgardeo gives you a very user-friendly, handy and smooth experience in each and every flow for the users. You can try out Asgardeo from here and follow the docs as well for more information. Also, you can interact with the Asgardeo community and share your Asgardeo experience among fellow users as well. So you are warmly welcome to an amazing Asgardeo journey here onwards.

While you are travelling in the Asgardeo universe I’ll share an article series about the Asgardeo journey. Here we go with the first one. This is an article about how to integrate the SAML + Spring web app with Asgardeo.

As the first step what you need to do is, creating a spring web app that supports SAML protocol.

Creating Spring web app

This is an easy task. You can directly use https://start.spring.io/ and generate the web app. Please make sure to add relevant dependencies.

As in the above image, Once you finish configuring the Group, Artifact and dependency adding, click on the generate button and it will automatically generate the Spring project.

Then you can import this on your IntelliJ Idea or your preferred IDE.

Creating a Web app in Asgardeo

This is also a pretty easy task which is very much similar to creating a SAML application in the WSO2 identity server. However, Asgardeo is providing a much handier and smooth way than the WSO2 identity server. All you need to do is only follow the below steps.

  1. Log into the Asgardeo and add a “New application” by going through the “Add login to your apps” path

You need to do a simple configuration before adding an application.

  1. First, you need to choose the traditional web app as an application.
  1. Under traditional web app, choose the SAML web app option. You will prompt to configure a few parameters and use the below details to fill that up.
Service Provider : SAML Spring Application
Issuer: http://localhost:8080/saml2/service-provider-metadata/asgardeo
Assertion Consumer service URL : http://localhost:8080/login/saml2/sso/asgardeo

Now register the application in Asgardeo. The registered application will list in your Asgardeo portal as below image.

Now you are all done with the Asgardeo side. Now what is left to deal with is the integration part.

Integrating with Asgardeo

  1. To support SAML protocol it’s needed to add SAML 2 dependency into your web app’s pom file
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-saml2-service-provider</artifactId>
</dependency>

The complete pom file will be as below

2. Then you need to implement the logic in your web app for handling requests and responses. Before that, it’s mandatory to obtain the certificate of registered application in Asgardeo because when validating the web app requests, the IDP public certificate is essential. So you need to navigate to the “Info” tab in your Asgardeo SAML application and download the certificate.

3. Then you need to implement and configure the web app with those details. you can find the implemented logic in the sample app below snippet. (There, I’ve hardcoded the “entityID” & “SSO location” details. But you can configure them via a config file as well). Also, you need to point your Asgardeo application certificate with his path. (I’ve added it “src/resource/cert” directory in the project and you can add it anywhere you need and give the correct path )

You can refer to the complete sample web app below git location. And I’ll explain the implementation logic and high-level architecture of the SAML flow with Asgardeo in the next article.

4. As the final step what you need to do is configure the “YAML” file and create the “HTML” pages to view the requests and responses of authenticated users from Asgardeo side.

Now you have finished with all the implementation in your web app and integration task with Asgardeo.

Testing the Set-up

  1. To run the web app you need to execute the below command.
mvn spring-boot:run

2. Once the web app is deployed, you can access it via “http://localhost:8080/” from your browser. It will land you on a web page like below.

3. Clicking on “here” will redirect you to the Asgardeo for authenticating. With your credentials, you can get successfully authenticated your user from Asgardeo and access your web app.

Hope you will enjoy and experience an amazing Asgadeo journey with this article. Also, you can try out the Asgardeo and follow the docs mentioned at the top for an enhanced IDaaS experience. And don’t hesitate to reach out to the Asgardeo community to share your experience among the other IAM enthusiasts. If you have met any concerns while you are working with Asgardeo, please drop a mail to “asgardeo-help@wso2.com” as well.

So we will meet with a new article. Until then wish you an amazing Asgardeo journey.

Cheers…!!!

References:

--

--