1 Reply Latest reply on May 18, 2012 1:13 AM by urug

    JBoss AS 7.1 custom login module - obtain client IP address

    urug

      I have a custom login module that has business logic tied to integration with other systems. It extends UsernamePasswordLoginModule. I need access to the source IP address of the received HTTP request (could be end client, or the last hop that inserted the IP). I used to do this using FacesContext.getCurrentInstance().getExternalContext().getRequest().getRemoteAddr(). However, in JBoss AS7.1, FacesContext is null. How can the IP address be retrieved? Is there a way to get access to the Tomcat (catalina) request object that (for some reason) is not passed through?

       

      For reference - https://community.jboss.org/message/631116

       

      Thanks

        • 1. Re: JBoss AS 7.1 custom login module - obtain client IP address
          urug

          Solved this by using a Catalina custom authenticator for Basic/Form and other types of authentication - overrode the authenticate method to set a ThreadLocal context that other components use further up the chain.

           

          https://community.jboss.org/wiki/DRAFTUsingJBossNegotiationOnAS7

           

           

          public class MyAuthenticator extends org.apache.catalina.authenticator.BasicAuthenticator

          {

          ....

           

              @Override

              public boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException

              {

                  MyServletContext.setContext(request, response);  // Servlet context stores ThreadLocal request/response for others to query/retrieve

                  try

                  {

                      return super.authenticate(request, response, config);

                  }

                  finally

                  {

                      MyServletContext.removeContext();

                  }

              }

           

          ....

          }

           

          Message was edited by: Guru Somadder