SlideShare a Scribd company logo
Securing Microservices
WSO2 Identity Server
Anupam Gogoi - Associate Technical Lead
Pre-requisites
• JDK 8
• Maven
• Eclipse or IntelliJ
• WSO2 Identity Server 5.7.0
Lab Exercise 1 - Create Microservice
Part 1
We are going to create a simple Microservice in Spring
Boot. The service contains a resource protected by
OAuth2.
Part 2
Configure WSO2 Identity Server as OAuth2/OpenID
authorization server.
Solution Lab Exercise 1
Part 1
Creating a Spring Boot microservice.
Code repository
https://github.com/anupamgogoi-wso2/wso2-summit
High Level Overview
Spring Boot Microservice
• Visit the site https://start.spring.io/ and create a project with dependencies Web and
Security.
• Import the project in Eclipse/IntelliJ and add one more dependency by hand in the
pom.xml
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
• Add your logic.
• https://github.com/anupamgogoi-wso2/wso2-summit
Spring Boot - Configure Auth. Server
Note that for client id and client secret you need to use valid username password from
WSO2 Identity server.Here i have used default admin username/password.According to
this configuration resource server will use OAuth2 introspection API to validate the
token.
security.oauth2.client.client-id=admin
security.oauth2.client.client-secret=admin
security.oauth2.client.access-token-uri=https://localhost:9443/oauth2/token
security.oauth2.client.user-authorization-uri=https://localhost:9443/oauth2/token/authorize
security.oauth2.client.scope=openid
security.oauth2.resource.filter-order=3
security.oauth2.resource.user-info-uri=https://localhost:9443/oauth2/userinfo
security.oauth2.resource.token-info-uri=https://localhost:9443/oauth2/introspect
security.oauth2.resource.prefer-token-info=true
Spring Boot - Run
The important thing is to pass client truststore details while executing the jar file.Spring
security will use SSL connection to talk with Authorization server to validate the access
token.The spring boot runtime should be provided with certificate store to find out the
authorization server certificate authority and trust it.
java -Djavax.net.ssl.trustStore=/Users/anupamgogoi/softwares/wso2/is/wso2is-
5.7.0/repository/resources/security/client-truststore.jks 
-Djavax.net.ssl.trustStorePassword=wso2carbon 
-jar /Users/anupamgogoi/git/wso2-summit/spring-oauth2-microservice/target/spring-oauth2-microservice-
1.0.0.jar
Solution Lab Exercise 1
Part 2
Configure WSO2 Identity Server as OAuth2
Authorization Server
High Level Overview
• We will use a simple 3 entity
example 1) User, 2) Application
server, and 3) Authentication server.
• The authentication server will
provide the JWT to the user. With
the JWT, the user can then safely
communicate with the application.
Configure WSO2 Identity Server
• Log into the IS (admin/admin)
• Navigate to Service
Providers menu and click
add.
Add Service Provider - IS
Provide Basic Information for the
Service Provider.
Eg.
Service Provider Name: OAUTH2
Inbound Authentication Configuration
Click Inbound
Authentication
Configuration and expand
OAuth/OpenID Connect
Configuration.
OAuth/OpenID Connect Configuration
Configure OAuth2. Choose Token
Issuer as Default (OAuth2).
Note that we can choose JWT
also. (Next lab)
OAuth/OpenID Connect Configuration
Once configuration is saved you
will be provided with the Client
Key and Client Secret.
Microservice Resource
The Spring Boot microservice contains a resource protected by
OAuth2.
GET http://localhost:8080/app/products
To access this resource, an Access Token must be provided in
the Authorization header.
Generating Access Token - Postman
• Token URI of the Identity Server,
https://localhost:9443/oauth2/token
• Use password grant_type and provide necessary
details. Note that the client_id & client_secret are
generated while adding the Service Provider in the
IS.
• Make sure to send the following header,
Content-Type: application/x-www-form-urlencoded
Generating Access Token - CURL
curl -u <CLINET_ID>:<CLIENT_SECRET> -k 
-d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" 
https://localhost:9443/oauth2/token
Invoke Microservice
curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<ACCESS_TOKEN>>
Lab Exercise 2
Using JWT to access the protected resource of the
microservice.
Solution - Lab Exercise 2
We are going to use the same Spring Boot microservice
with the same resource. Only thing we will need to change
is in the Identity Server to generate JWT.
Configure identity.xml - IS
● Open the <IS_HOME>/repository/conf/identity/identity.xml file and set the <Enabled>
element (found under the <OAuth>,<AuthorizationContextTokenGeneration> elements) to true
as shown in the code block below.
● Add the following property under <OAUTH> section to use the JWT Token Builder instead of
the default Token Builder.
<IdentityOAuthTokenGenerator>org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer</IdentityOAuthTokenGenerator>
Configure identity.xml - IS
• Configure the “audiences” parameter as mentioned below so that the token includes information
about the intended audiences who can use the generated token for authenticating the user.
<EnableAudiences>true</EnableAudiences>
<Audiences>
<Audience>${carbon.protocol}://${carbon.host}:${carbon.management.port}/oauth2/token</Audience>
</Audiences>
• Configure a meaningful value to the <IDTokenIssuerID> parameter in the identity.xml file
<IDTokenIssuerID>my-jwt-token</IDTokenIssuerID>
• Start the IS
sh wso2server.sh
Configure Identity Provider - IS
Go into Identity-> Identity Providers and click on “Add”.
Configure Identity Provider - IS
Identity Provider Name—This needs to be the same value as the <IDTokenIssuerID> value you configure at the identity.xml
file since this value will be the issuer ID of the JWT token. Here the value is given as “apim-idp” to match the above mentioned
parameter.
Identity Provider Public Certificate—Here you need to upload the public certificate of the WSO2 Identity Server in a pem
file format. The Identity Provider Public Certificate is the public certificate belonging to the identity provider. Uploading this is
necessary to authenticate the response from the identity provider. This can be any certificate. Since we are using WSO2 Identity
Server as the IDP we can generate the certificate using the below mentioned commands.
Create/Import Certificate
• Open your Command Line interface, go to the
<IS_HOME>/repository/resources/security/directory. Run the following command.
keytool -export -alias wso2carbon -file wso2.crt -keystore wso2carbon.jks -storepass
wso2carbon
Click Choose File and navigate to this location in order to select and upload this file.
• Alias—You need to give the clientID (client key) of the service provider which you will
configure in the WSO2 Identity Server here. This will be checked when verifying the JWT
token.
OAuth/OpenID Connect Configuration
• Create a new Service Provider e.g JWT
• Choose any valid Url in the Callback Url
field.
• Choose Token Issuer as JWT.
Get JWT & Invoke Service
You need to first get a JWT token from the WSO2 identity server by using the token endpoint
with the password grant type. You can use the below mentioned curl command to get a JWT
token,
curl -u <CLIENT_ID>:<CLIENT_SECRET> -k 
-d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" 
https://localhost:9443/oauth2/token
Use the token in Authorization header in the request to access the protected resource of the
microservice,
curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<JWT_TOKEN>>"
Microservice Protection With WSO2 Identity Server
THANK YOU
wso2.com

More Related Content

PDF
AWSのインフラはプログラミングコードで構築!AWS Cloud Development Kit 入門
PDF
[Cloud OnAir] Google Cloud における RDBMS の運用パターン 2020年11月19日 放送
PPTX
Formation html5 css3 java script
PDF
Presto ベースのマネージドサービス Amazon Athena
PDF
SQLアンチパターン - ジェイウォーク
PDF
API : l'architecture REST
PDF
AWS DevOps와 ECR을 통한 Elastic Beanstalk 배포 환경 구축 및 타 환경과의 비교
PPTX
Why (most) softwareprojects fail silently
AWSのインフラはプログラミングコードで構築!AWS Cloud Development Kit 入門
[Cloud OnAir] Google Cloud における RDBMS の運用パターン 2020年11月19日 放送
Formation html5 css3 java script
Presto ベースのマネージドサービス Amazon Athena
SQLアンチパターン - ジェイウォーク
API : l'architecture REST
AWS DevOps와 ECR을 통한 Elastic Beanstalk 배포 환경 구축 및 타 환경과의 비교
Why (most) softwareprojects fail silently

What's hot (20)

PDF
Exercice java vehicule
PDF
イマドキ!ユースケース別に見るAWS IoT への接続パターン
PDF
Une introduction à Hive
PPTX
Web App for Containers + Cosmos DBで コンテナ対応したMEANアプリを作ろう!
PDF
30分でRHEL6 High Availability Add-Onを超絶的に理解しよう!
PDF
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
PDF
Business Requirement Analyse Requirement Document Requirements
PDF
Improving Pharo Snapshots
PDF
SQLアンチパターン読書会 4章 キーレスエンエントリ(外部キー嫌い)
PPTX
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
PDF
Livre blanc docker
PDF
5分で分かった気になるTekton
PPT
CS 354 Typography
PDF
MindsDB - Machine Learning in ClickHouse - SF ClickHouse Meetup September 2020
PDF
클라우드 여정의 시작 - 클라우드 전문가 조직의 프랙티컬 가이드-김학민, AWS SA Manager::AWS 마이그레이션 A to Z 웨비나
PDF
Amazon SNS+SQSによる Fanoutシナリオの話
PPT
Continuous Integration (Jenkins/Hudson)
PDF
データ活用を加速するAWS分析サービスのご紹介
PPTX
PostgreSQLからのデータ連携/同期も完全対応!DBを『活かす』なら、Syniti DR 9.7!
PDF
천만사용자를 위한 AWS 클라우드 아키텍처 진화하기 – 문종민, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020
Exercice java vehicule
イマドキ!ユースケース別に見るAWS IoT への接続パターン
Une introduction à Hive
Web App for Containers + Cosmos DBで コンテナ対応したMEANアプリを作ろう!
30分でRHEL6 High Availability Add-Onを超絶的に理解しよう!
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
Business Requirement Analyse Requirement Document Requirements
Improving Pharo Snapshots
SQLアンチパターン読書会 4章 キーレスエンエントリ(外部キー嫌い)
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Livre blanc docker
5分で分かった気になるTekton
CS 354 Typography
MindsDB - Machine Learning in ClickHouse - SF ClickHouse Meetup September 2020
클라우드 여정의 시작 - 클라우드 전문가 조직의 프랙티컬 가이드-김학민, AWS SA Manager::AWS 마이그레이션 A to Z 웨비나
Amazon SNS+SQSによる Fanoutシナリオの話
Continuous Integration (Jenkins/Hudson)
データ活用を加速するAWS分析サービスのご紹介
PostgreSQLからのデータ連携/同期も完全対応!DBを『活かす』なら、Syniti DR 9.7!
천만사용자를 위한 AWS 클라우드 아키텍처 진화하기 – 문종민, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020
Ad

Similar to Microservice Protection With WSO2 Identity Server (20)

PDF
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
PDF
Using a Third Party Key Management System with WSO2 API Manager
PPTX
Microservices security - jpmc tech fest 2018
PDF
API Security In Cloud Native Era
PDF
Microservices Security Landscape
PDF
Talk Microservices to Me: The Role of IAM in Microservice Architecture
PDF
Secured REST Microservices with Spring Cloud
PDF
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2
PPTX
OAuth Well Played – Mods and Combos for the Cloud Native API Security Game - ...
PDF
[Webinar] WSO2 API Microgateway with Okta as Key Manager
PDF
Authentication in microservice systems - fsto 2017
PDF
The Role of IAM in Microservices
PDF
Security Patterns with WSO2 ESB
PDF
WSO2 ITALIA SMART TALK #3 WSO2 IS NEW FEATURE
PDF
[WSO2Con Asia 2018] Talk Microservices to Me: The Role of IAM in Microservice...
PDF
Building Highly Secure Cloud-Native Applications on PAS with Ease - Jignesh S...
PPTX
Introduction to the WSO2 Identity Server &Contributing to an OS Project
PDF
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
PDF
InterCon 2016 - Segurança de identidade digital levando em consideração uma a...
PDF
iMasters Intercon 2016 - Identity within Microservices
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
Using a Third Party Key Management System with WSO2 API Manager
Microservices security - jpmc tech fest 2018
API Security In Cloud Native Era
Microservices Security Landscape
Talk Microservices to Me: The Role of IAM in Microservice Architecture
Secured REST Microservices with Spring Cloud
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2
OAuth Well Played – Mods and Combos for the Cloud Native API Security Game - ...
[Webinar] WSO2 API Microgateway with Okta as Key Manager
Authentication in microservice systems - fsto 2017
The Role of IAM in Microservices
Security Patterns with WSO2 ESB
WSO2 ITALIA SMART TALK #3 WSO2 IS NEW FEATURE
[WSO2Con Asia 2018] Talk Microservices to Me: The Role of IAM in Microservice...
Building Highly Secure Cloud-Native Applications on PAS with Ease - Jignesh S...
Introduction to the WSO2 Identity Server &Contributing to an OS Project
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
InterCon 2016 - Segurança de identidade digital levando em consideração uma a...
iMasters Intercon 2016 - Identity within Microservices
Ad

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Nekopoi APK 2025 free lastest update
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
ai tools demonstartion for schools and inter college
PPTX
history of c programming in notes for students .pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Transform Your Business with a Software ERP System
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
L1 - Introduction to python Backend.pptx
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers
Nekopoi APK 2025 free lastest update
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
ai tools demonstartion for schools and inter college
history of c programming in notes for students .pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
ManageIQ - Sprint 268 Review - Slide Deck
Navsoft: AI-Powered Business Solutions & Custom Software Development
Transform Your Business with a Software ERP System
Odoo Companies in India – Driving Business Transformation.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
2025 Textile ERP Trends: SAP, Odoo & Oracle
L1 - Introduction to python Backend.pptx
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms II-SECS-1021-03
Online Work Permit System for Fast Permit Processing
How to Choose the Right IT Partner for Your Business in Malaysia

Microservice Protection With WSO2 Identity Server

  • 1. Securing Microservices WSO2 Identity Server Anupam Gogoi - Associate Technical Lead
  • 2. Pre-requisites • JDK 8 • Maven • Eclipse or IntelliJ • WSO2 Identity Server 5.7.0
  • 3. Lab Exercise 1 - Create Microservice Part 1 We are going to create a simple Microservice in Spring Boot. The service contains a resource protected by OAuth2. Part 2 Configure WSO2 Identity Server as OAuth2/OpenID authorization server.
  • 4. Solution Lab Exercise 1 Part 1 Creating a Spring Boot microservice. Code repository https://github.com/anupamgogoi-wso2/wso2-summit
  • 6. Spring Boot Microservice • Visit the site https://start.spring.io/ and create a project with dependencies Web and Security. • Import the project in Eclipse/IntelliJ and add one more dependency by hand in the pom.xml <dependency> <groupId>org.springframework.security.oauth.boot</groupId> <artifactId>spring-security-oauth2-autoconfigure</artifactId> <version>2.0.6.RELEASE</version> </dependency> • Add your logic. • https://github.com/anupamgogoi-wso2/wso2-summit
  • 7. Spring Boot - Configure Auth. Server Note that for client id and client secret you need to use valid username password from WSO2 Identity server.Here i have used default admin username/password.According to this configuration resource server will use OAuth2 introspection API to validate the token. security.oauth2.client.client-id=admin security.oauth2.client.client-secret=admin security.oauth2.client.access-token-uri=https://localhost:9443/oauth2/token security.oauth2.client.user-authorization-uri=https://localhost:9443/oauth2/token/authorize security.oauth2.client.scope=openid security.oauth2.resource.filter-order=3 security.oauth2.resource.user-info-uri=https://localhost:9443/oauth2/userinfo security.oauth2.resource.token-info-uri=https://localhost:9443/oauth2/introspect security.oauth2.resource.prefer-token-info=true
  • 8. Spring Boot - Run The important thing is to pass client truststore details while executing the jar file.Spring security will use SSL connection to talk with Authorization server to validate the access token.The spring boot runtime should be provided with certificate store to find out the authorization server certificate authority and trust it. java -Djavax.net.ssl.trustStore=/Users/anupamgogoi/softwares/wso2/is/wso2is- 5.7.0/repository/resources/security/client-truststore.jks -Djavax.net.ssl.trustStorePassword=wso2carbon -jar /Users/anupamgogoi/git/wso2-summit/spring-oauth2-microservice/target/spring-oauth2-microservice- 1.0.0.jar
  • 9. Solution Lab Exercise 1 Part 2 Configure WSO2 Identity Server as OAuth2 Authorization Server
  • 10. High Level Overview • We will use a simple 3 entity example 1) User, 2) Application server, and 3) Authentication server. • The authentication server will provide the JWT to the user. With the JWT, the user can then safely communicate with the application.
  • 11. Configure WSO2 Identity Server • Log into the IS (admin/admin) • Navigate to Service Providers menu and click add.
  • 12. Add Service Provider - IS Provide Basic Information for the Service Provider. Eg. Service Provider Name: OAUTH2
  • 13. Inbound Authentication Configuration Click Inbound Authentication Configuration and expand OAuth/OpenID Connect Configuration.
  • 14. OAuth/OpenID Connect Configuration Configure OAuth2. Choose Token Issuer as Default (OAuth2). Note that we can choose JWT also. (Next lab)
  • 15. OAuth/OpenID Connect Configuration Once configuration is saved you will be provided with the Client Key and Client Secret.
  • 16. Microservice Resource The Spring Boot microservice contains a resource protected by OAuth2. GET http://localhost:8080/app/products To access this resource, an Access Token must be provided in the Authorization header.
  • 17. Generating Access Token - Postman • Token URI of the Identity Server, https://localhost:9443/oauth2/token • Use password grant_type and provide necessary details. Note that the client_id & client_secret are generated while adding the Service Provider in the IS. • Make sure to send the following header, Content-Type: application/x-www-form-urlencoded
  • 18. Generating Access Token - CURL curl -u <CLINET_ID>:<CLIENT_SECRET> -k -d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token Invoke Microservice curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<ACCESS_TOKEN>>
  • 19. Lab Exercise 2 Using JWT to access the protected resource of the microservice.
  • 20. Solution - Lab Exercise 2 We are going to use the same Spring Boot microservice with the same resource. Only thing we will need to change is in the Identity Server to generate JWT.
  • 21. Configure identity.xml - IS ● Open the <IS_HOME>/repository/conf/identity/identity.xml file and set the <Enabled> element (found under the <OAuth>,<AuthorizationContextTokenGeneration> elements) to true as shown in the code block below. ● Add the following property under <OAUTH> section to use the JWT Token Builder instead of the default Token Builder. <IdentityOAuthTokenGenerator>org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer</IdentityOAuthTokenGenerator>
  • 22. Configure identity.xml - IS • Configure the “audiences” parameter as mentioned below so that the token includes information about the intended audiences who can use the generated token for authenticating the user. <EnableAudiences>true</EnableAudiences> <Audiences> <Audience>${carbon.protocol}://${carbon.host}:${carbon.management.port}/oauth2/token</Audience> </Audiences> • Configure a meaningful value to the <IDTokenIssuerID> parameter in the identity.xml file <IDTokenIssuerID>my-jwt-token</IDTokenIssuerID> • Start the IS sh wso2server.sh
  • 23. Configure Identity Provider - IS Go into Identity-> Identity Providers and click on “Add”.
  • 24. Configure Identity Provider - IS Identity Provider Name—This needs to be the same value as the <IDTokenIssuerID> value you configure at the identity.xml file since this value will be the issuer ID of the JWT token. Here the value is given as “apim-idp” to match the above mentioned parameter. Identity Provider Public Certificate—Here you need to upload the public certificate of the WSO2 Identity Server in a pem file format. The Identity Provider Public Certificate is the public certificate belonging to the identity provider. Uploading this is necessary to authenticate the response from the identity provider. This can be any certificate. Since we are using WSO2 Identity Server as the IDP we can generate the certificate using the below mentioned commands.
  • 25. Create/Import Certificate • Open your Command Line interface, go to the <IS_HOME>/repository/resources/security/directory. Run the following command. keytool -export -alias wso2carbon -file wso2.crt -keystore wso2carbon.jks -storepass wso2carbon Click Choose File and navigate to this location in order to select and upload this file. • Alias—You need to give the clientID (client key) of the service provider which you will configure in the WSO2 Identity Server here. This will be checked when verifying the JWT token.
  • 26. OAuth/OpenID Connect Configuration • Create a new Service Provider e.g JWT • Choose any valid Url in the Callback Url field. • Choose Token Issuer as JWT.
  • 27. Get JWT & Invoke Service You need to first get a JWT token from the WSO2 identity server by using the token endpoint with the password grant type. You can use the below mentioned curl command to get a JWT token, curl -u <CLIENT_ID>:<CLIENT_SECRET> -k -d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token Use the token in Authorization header in the request to access the protected resource of the microservice, curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<JWT_TOKEN>>"