Wildfly share session between EARs?

前端 未结 2 766
清酒与你
清酒与你 2021-01-24 05:43

I have 2 WAR applications in 2 independent EARs that I want to deploy in a single instance of Wildfly 10/JBoss 7 EAP. How can I share sessions/authentication between the 2 wars

相关标签:
2条回答
  • 2021-01-24 06:33

    If you only need single sign on and session sharing for apps within wildlfy, you don't need any dedicated SSO mechanism - server already has everything you need. First, you need to secure you applications using some existing security-domain via WEB-INF/jboss-web.xml. Example:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web>   
        <security-domain>my-sec-domain</security-domain>    
    </jboss-web>
    

    Next you need to enable SSO handling in Undertow(Jboss/Wildfly web server). You can do it with CLI or by manualy updating the corresponding config. Cli command(for standalone mode):

    /subsystem=undertow/server=default-server/host=default-host/setting=single-sign-on:add(path=/)
    

    Or if you edit the config manually, add <single-sign-on path="/" /> to undertow config like so:

    <subsystem xmlns="urn:jboss:domain:undertow:3.1">
       <buffer-cache name="default"/>
       <server name="default-server">
        <ajp-listener name="ajp" socket-binding="ajp"/>
        <http-listener name="default" max-post-size="20485760" socket-binding="http" redirect-socket="https"/>
        <host name="default-host" alias="localhost">
           <location name="/" handler="welcome-content"/>
           <filter-ref name="server-header"/>
           <filter-ref name="x-powered-by-header"/>
           <single-sign-on/>
       </host>
    </server>
    

    Now we need to enable mechanism for session replication/sharing. In wildfly, it is done using the infinispan subsystem and web cache. You will either need to use full-ha configuraiton profile(standalone-full-ha.xml) or manualy add that subsystem to your config. Here awe are looking for cache container named web. If its there, you should be good to go.
    Now when you visit APP-A in your browser, you should get two session cookies JSESSIONID and JSESSIONIDSSO. After switching to APP-B, you should be automatically logged in.
    Happy Hacking

    0 讨论(0)
  • 2021-01-24 06:36

    Sharing session between two web application which are part of same EAR is possible, go through document for more details on this. For single authentication for both web applications, you have to implement SSO. You can implement SSO using SAML or Kerberos. Hope it helps..!!

    0 讨论(0)
提交回复
热议问题