Giter Site home page Giter Site logo

asgardeo / asgardeo-tomcat-saml-agent Goto Github PK

View Code? Open in Web Editor NEW
15.0 35.0 25.0 744 KB

SAML Agent for Tomcat using Java SAML SDK for Asgardio

License: Apache License 2.0

Java 59.41% HTML 12.06% Shell 17.29% Dockerfile 2.91% CSS 8.32%
hacktoberfest

asgardeo-tomcat-saml-agent's Introduction

Asgardeo Tomcat SAML Agent

Build Status Stackoverflow Join the chat at https://discord.gg/wso2 License Twitter

Asgardeo Tomcat SAML Agent enables you to add SAML based login, logout to your Apache Tomcat web apps in simple manner.

Getting started

You can experience the capabilities of Asgardeo Tomcat SAML Agent by following this small guide which contains main sections listed below.

Prerequisites

Configuring the sample

  1. Open a terminal window inside a preferred directory on your machine.

  2. Deploy the sample app.

    • a. Execute the following command to start the sample Docker container.
    docker container run --rm --name tomcat-saml-agent-sample -itdp 8080:8080 asgardeo/tomcat-saml-agent-sample
    
    • b. You can also manually deploy the sample app in a Tomcat server without using the docker image. Simply download sample-app.war from here and deploy.
  3. Add the following entry to the /etc/hosts file of your machine to configure the hostname.

    127.0.0.1 localhost.com
    

Create an Application in Asgardeo

Here we are using Asgardeo as the SAML Identity Provider.

  1. Navigate to Asgardeo Console and click on Applications under Develop tab.

  2. Click on New Application and then Traditional Web Application.

  3. Select SAML from the selection and enter any name as the name of the app and add the Assertion Consumer Service URL and Issuer.

  4. Click on Register. You will be navigated to management page of the created application.

Running the sample

Try out the application by accessing the URL http://localhost.com:8080/sample-app/index.html in your web browser.

How it works

This section explains detailed walkthrough on how key aspects handled in the Asgardeo Tomcat SAML Agent.

Classify secure resources, unsecured resources

In the sample-app, we have two pages. A landing page (index.html) which we have not secured, and another page (home.jsp) which we have secured.

IndexPage property of the sample-app.properties file in the <APP_HOME>/WEB-INF/classes directory is used to define the landing page of the webapp which is also considered as an unsecured page. Also the same page is used as the page that the user get redirected once the logout is done. Here we have set <APP_HOME>/index.html as the value of IndexPage property. IndexPage=/sample-app/index.html

By default, all the other pages are considered as secured pages. Hence home.jsp will be secured without any other configurations.

Trigger authentication

In the <APP_HOME>/index.html page, we have added the action for the login button to trigger a SAML authentication:

<form action="samlsso?SAML2.HTTPBinding=HTTP-POST" method="post">
    <div class="element-padding">
        <input style="height: 30px; width: 60px" type="submit" value="log in">
    </div>
</form>

The button click would trigger an authentication request, and redirect the user to the IdP authentication page. Upon successful authentication, the user would be redirected to the <APP_HOME>/home.jsp page.

Retrieve user attributes

In the <APP_HOME>/home.jsp file, we have added the following to get the user subject value and the user attributes referring the SDK API.

<%
    // Retrieve the session bean.
    LoggedInSessionBean sessionBean = (LoggedInSessionBean) session.getAttribute(SSOAgentConstants.SESSION_BEAN_NAME);

    // SAML response
    SAML2SSO samlResponse = sessionBean.getSAML2SSO();

    // Autheticated username
    String subjectId = samlResponse.getSubjectId();

    // Authenticated user's attributes
    Map<String, String> saml2SSOAttributes = samlResponse.getSubjectAttributes();
%>

Trigger logout

In the <APP_HOME>/home.jsp file, we have added the following to trigger a SLO flow:

<a href="logout?SAML2.HTTPBinding=HTTP-POST">Logout</a>

Clicking on the logout link would trigger the SLO flow engaging the same filter mentioned above. The user would be redirected to the page configured via the IndexPage property previously discussed.

Integrating Asgardeo Tomcat SAML Agent

Asgardeo Tomcat SAML Agent can be integrated in to your applications in two different ways.

It can be integrated to your java source project of the webapp when the web application is in development stage.

And, the Tomcat SAML agent can be integrated into a pre-built webapp as well.

To your existing webapp

To integrate the Tomcat SAML Agent into your pre-built webapps, follow the guide here.

To your Java source project

To integrate the Tomcat SAML Agent into your java source project, follow the guide here.

Contributing

Please read Contributing to the Code Base for details on our code of conduct, and the process for submitting pull requests to us.

Reporting issues

We encourage you to report issues, improvements, and feature requests creating git Issues.

Important: And please be advised that security issues must be reported to [email protected], not as GitHub issues, in order to reach the proper audience. We strongly advise following the WSO2 Security Vulnerability Reporting Guidelines when reporting the security issues.

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

asgardeo-tomcat-saml-agent's People

Contributors

chamathns avatar cnapagoda avatar darshanasbg avatar deshankoswatte avatar dinikasen avatar emswbandara avatar gayashanbc avatar godwinamila avatar hasinthaindrajee avatar isharak avatar jkaushalya avatar kanchanagodage avatar kasungayan avatar kayathiri4 avatar madumalt avatar madurangasiriwardena avatar maheshika avatar malithie avatar mefarazath avatar nilagini avatar nipunibhagya avatar omindu avatar piyarathnalakmali avatar pulasthi7 avatar rashmini avatar senthalan avatar thanujalk avatar thivi avatar vihanga-liyanage avatar wso2-jenkins-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asgardeo-tomcat-saml-agent's Issues

Server Error when key store properties are not included.

Describe the issue:
The following error prevents the web app from deploying if the keyStore related properties are not included in the .properties file.

org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [io.asgardeo.tomcat.saml.agent.SSOAgentContextEventListener]
        java.lang.NullPointerException
                at io.asgardeo.tomcat.saml.agent.SSOAgentContextEventListener.contextInitialized(SSOAgentContextEventListener.java:80)
                at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4716)
                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5172)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:706)
                at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1023)
                at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1903)
                at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
                at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
...

How to reproduce:

Remove the Keystore-related configurations from the properties file and deploy the web app.

Threadrace bug

Describe the issue:

SSOAgentConfig is singleton, so changing this object with requests should be synchronized or use copy of object. Concrete example of code is here:
https://github.com/asgardio/asgardio-tomcat-saml-agent/blob/master/io.asgardio.tomcat.saml.agent/src/main/java/io/asgardio/tomcat/saml/agent/SAML2SSOAgentFilter.java#L148-L151

After incorrect case variable ssoAgentConfig.getSAML2().isPassiveAuthn ends with value true a then all next logins will be passive.

I made pull request for this bug, that includes changes after code review.

How to reproduce:

I wrote test for this case https://github.com/boulik/tomcat-saml-agent-stressTest
Expected behavior:

--

Environment information (Please complete the following information; remove any unnecessary fields) :

  • Product Version: [IS 5.7.0]
  • OS: [Windows, Linux, Mac]
  • Browser: [Chrome, Firefox, Edge, Safari]
  • SDK Version: [0.1.18]
    --

Optional Fields

Related issues:

Suggested labels:

Single Logout flow not working as expected.

Description:
After initiating an SLO request from a secondary application and then, refreshing the logged-in secured page (eg: home.jsp in the sample-app in tomcat-saml-agent) of the primary app does not redirect the user to a login page nor does it prompt the user for authentication. Instead a new logged in session would be created and the secured page would be accessible.

logout

Steps to reproduce:

  1. Configure two webapps with the WSO2-IS. In my testing, I configured the pickup-dispatch webapp (OIDC) and the sample-app (SAML).
  2. Enable Single Logout under the service provider configurations (Inbound Authentication Configuration -> SAML2 Web SSO Configuration) of the sample-app.
  3. Login from the pickup-dispatch app providing the user credentials.
  4. Open a new tab on the same browser and log in to the sample-app. (Should not be prompted for authentication in this step)
  5. After getting to the home page of both the applications, click on logout from the pickup-dispatch app.
  6. Verify if the user is logged out. (The user should be redirected to the log in page of the pickup-dispatch app.)
  7. Switch to the sample-app application, (The user should be on the home.jsp page of the sample-app), and hit refresh on browser.
  8. The home.jsp page of the sample-app would still be accessible.

Cross protocol SLO is not working properly for SAML

Describe the issue:

Cross protocol SLO is not working properly for SAML tomact agent sample applictaion

When logout from the OIDC application which is SSO and SLO enabled, below behavior found

  1. Stay in same page when refresh is done from the SAML application for IDP initiated SSO in SAML application.
  2. Prompt the Login page when refresh is done from the SAML application for SP initiated SSO in SAML application.

Logout from the SAML application is not functioning properly in both cases.

How to reproduce:

1.Setup the sample SAML agent application
2. Setup OIDC Application in order to work the SSO
( SSO & SLO enabled, IDP initialed SSO & SLO enabled with back channel logout enabled both applications)
3. Logout from the OIDC application
4. behavior

  • Refresh the SAML application when SSO initiated by IDP, it will stay in same page without knowing back channel is logout.

  • Refresh the SAML application when SSO initaied by SP itself, then it will prompt Login page because of SAML2RequestID is null in [1] and send SSO request again to IS. This is always gives null even without logout is performed every refresh it calls the SSO request to IS.

Here, InResponseTo value not there in the IDP initialed SAML response while SAML response in SP initialed scenario has some value. Both case it doesn't fire /logout flow in the SAML2SSOAgentFilter instead always fire [2] condition

[1] https://github.com/asgardio/asgardio-java-saml-sdk/blob/master/io.asgardio.java.saml.sdk/src/main/java/io/asgardio/java/saml/sdk/SAML2SSOManager.java#L376
[2] https://github.com/asgardio/asgardio-tomcat-saml-agent/blob/master/io.asgardio.tomcat.saml.agent/src/main/java/io/asgardio/tomcat/saml/agent/SAML2SSOAgentFilter.java#L94
Expected behavior:

Environment information (Please complete the following information; remove any unnecessary fields) :

  • Product Version: [IS 5.10.0]
  • OS: [Linux,]
  • Browser: [Chrome]
  • SDK Version: [io.asgardio.tomcat.saml.agent:0.1.16 ]

Optional Fields

Related issues:

Suggested labels:

Dockerize the sample app

Description

The sample app needs to be dockerized in order to facilitate convenient deployments.

Add support for target page.

Describe the issue:

Currently, upon successful authentication, the SSO agent redirects the user to the page registered in the ACS URL (eg: app/home).

However, if a user tries to access another secured page (eg: app/myAccount) without having an authenticated session with the IdP, the user is first prompted for authentication. Then upon successful authentication, the user is redirected to the app/home where the user should have been redirected to the original page he tried to access; app/myAccount.

Expected behaviour

The Agent should keep track of the original page the user tried to access (target page), and redirect the user to the target page upon successful authentication.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.