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
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.
public class MyAuthenticator extends org.apache.catalina.authenticator.BasicAuthenticator
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
return super.authenticate(request, response, config);
Message was edited by: Guru Somadder
|Retrieving data ...|