Spring security saml2.0 sso with wso2 - spring

I'm using Spring SAML2.0 For SSO and Identity server as WSO2 5.4.0
I have done that with the SAML single sign on and now I want to define the role of the USERS and according to the roles of the user they can access the some sort of functionality in my application.
Ideally the User credential is stored in wso2 identity server and I defined there the role of the user.
When I fetch the assertion xml which is coming from wso2 IDP I can't find the role of the users.

Related

How to create an own IDP (identity provider) with saml 2.0 protocol using java spring?

Here is my situation where I am suppose create an IDP (Identity provider) of my own which follows SAML 2.0 protocol and should be able to authenticate users and let them log in to any service provider (service provider can be anything).? Can anyone help me with the brief whole process and let me tell you I do not know have any idea from where to start. (I have to use java spring).
Whenever the registered user with IDP tries to sign into any service provider the IDP should be able to authenticate and also authorize the user. Also the IDP should be capable to storing users data in any form.

How to generate access token for testing with Azure AD

We have a spring boot REST API which will be used by mobile client. Azure AD is used for auth. We need to generate access token for initial testing spring boot REST API. What is the recommended option for this?
Basically we need to to generate access token using client credentials and call the REST API end point using the access token. Then on the REST API, validate access token and print the app roles assigned in Azure AD.
To get the access token from Azure AD to authenticate and authorize users from Azure AD.
First, you need to register both the application mobile client and spring boot applications in your Azure AD. Refer register your application in the Azure AD.
To generate access token using client credentials flow, there would be no user involvement, so your server application needs to create an appRole, and then grant the app Role as an application permission to the client application.
The administrator must grant the correct application permissions via a consent process to access the application.
Configure the application's details registered in Azure AD to your spring boot application.properties file with application id, tenant id, client-secret and scope.
Refer guide to configure client application to access a web API using spring boot step by step.

Spring Boot REST service – End User Authentication vs APP (REST client) Authentication

I have gone through many posts and articles but didn't find a straightforward solution for the case below which I have to implement.
Platform: Spring Boot 2.x.x (Spring Security 5.x.x) with embed Tomcat
Solution: REST service that consume many client apps and many end users.
I have to implement a REST end point /api/search which accessible for many client application. As an example, web application APP-X (Angular), web application APP-Y(Jquery/Bootstrap) and mobile application APP-Z (IOS). All three clients are separate entities (both technical perspective and business perspective).
So I have to authenticate above application using onetime token. Therefore I planned to go for Spring OAuth2 by enabling #EnableAuthorizationServer and #EnableResourceServer. For each app client I’ll generate a token and they can use it when they connect with my REST service. Is this approach correct?
Apart from the app clients system has capability to register and login functionality for end users. Also my end point (/api/search) can access both anonymous users and users who registered under ROLE_REGUSER role. And through the security context, I need to access the user details as usual user authentication.
This is the place I got stuck. How can I handle the following points together using Spring Security 5.x.x (Spring Boot 2.x.x).
I. Both client apps and end users authentications.
II. Allow access for anonymous users and registered users for same end point.
I have attached small diagram to elaborate the above scenario.
Thanks
I found a solution when I upgraded my spring security version to 5.2. In version 5.2, they have depreciated #EnableAuthorizationServer and #EnableResourceServer. So I had to move with an external authorization provider who supports auth2. I chose AWS Cognito, and fulfill the above requirement, using the user pool option.
In AWS Cognito
I created a user pool.
Then created two app clients in the same user pool.
One app client configured as support to the client credentials flow.
The second app client configured as support to the user authentication flow.
In client applications
Retrieve access token directly from AWS Cognito using client credentials and used to secure all API calls.
If a user login at any stage, retrieve access token directly from AWS Cognito using the authorization code and replace any existing access token.
The advantage is, the resources server can validate any access token that generated related to the same user pool.
In resources server (backend API/Spring Boot)
Validate access token.

Spring Security 5 OAuth2 client password grant type

I have 2 applications:
Spring Application 1 is client and resource server.
Spring Application 2 is authorization server.
User will be able to login in Application 1 and access its resources.
And I want to implement the following flow:
User enter his credentials in login form -> Application 1 will get token from Application 2 using user credentials and its clientId with password grant type -> Access resources of Application 1 with token.
The question is if Spring Security 5 supports password grant type for client? I found all rest grant types, but not password in Spring Security 5 implementation.
Spring Security 5.1.x doesn't support it, see Spring Security Reference:
6.6 OAuth 2.0 Client
The OAuth 2.0 Client features provide support for the Client role as defined in the OAuth 2.0 Authorization Framework.
The following main features are available:
Authorization Code Grant
Client Credentials Grant
WebClient extension for Servlet Environments (for making protected resource requests)
HttpSecurity.oauth2Client() provides a number of configuration options for customizing OAuth 2.0 Client.
However, you could use Spring Security OAuth2, see OAuth 2 Developers Guide:
Accessing Protected Resources
As a general rule, a web application should not use password grants, so avoid using ResourceOwnerPasswordResourceDetails if you can in favour of AuthorizationCodeResourceDetails. If you desparately need password grants to work from a Java client, then use the same mechanism to configure your OAuth2RestTemplate and add the credentials to the AccessTokenRequest (which is a Map and is ephemeral) not the ResourceOwnerPasswordResourceDetails (which is shared between all access tokens).
Or you could update to Spring Security 5.2.x, see Spring Security Reference:
11.2 OAuth 2.0 Client
The OAuth 2.0 Client features provide support for the Client role as defined in the OAuth 2.0 Authorization Framework.
At a high-level, the core features available are:
Authorization Grant support
Authorization Code
Refresh Token
Client Credentials
Resource Owner Password Credentials

SSO SAML in Spring - supporting dynamic Multi-Tenant settings

I am new to SAML
I currently have a Spring Restful web server application which use spring security with Basic Authentication.
Since I have multiple enterprise customers i would like to support SAML SSO.
Trying to find documentation and preferably examples of how to set up SAML to authenticate with different IDPs for different customers, where the SAML IDP details are read from a persistence layer (DB).
Also would like to know the strategy for supporting the right login in the web application. Would i need now to support different URLs for each customer, so i know against which IDP to authenticate against?
For example I have two customers
Customer A - uses SAML IDP server A'
Customer B - uses SAML IDP server B'
When customer A's user gets to my site:
how would i know that now i need to authenticated against SAML IDP A'?
is it by the url, or some url parameter?
Once i know who he is, how do i setup spring saml to authenticate with IDP A' (read that from the DB settings for that customer). Notice i cant pre-set the IDPs in the spring configuration, as new customers can join later with new IDP.
thanks

Resources