-
1. Re: Client IP in LoginModule
prateek_n Jul 14, 2008 1:22 PM (in response to prateek_n)Is there a non portable way to retrieve the client IP for an EJB request for Jboss 4.2.2.GA ?
-
2. Re: Client IP in LoginModule
ragavgomatam Jul 16, 2008 9:50 PM (in response to prateek_n)I assume that client is calling the ejb directly like a java client, which would be using jndi to look up the ejb & connecting to the bean. Usually there is no straight forward way, except to use java.net.ServerSocket and other java.net API. But if you read the ejb spec, this is one of the DO NOT DO LIST & is certainly not recommended. You can try however.
Try to use the following method:
java.rmi.server.RemoteServer.getClientHost().
See if you have any luck. Mostly ejb's use RMI over IIOP so above call may or maynot work depending on container -
3. Re: Client IP in LoginModule
prateek_n Jul 16, 2008 10:36 PM (in response to prateek_n)I tried java.rmi.server.RemoteServer.getClientHost().
But that doesn't work.
It gives an exception.
Any other suggestions ? -
4. Re: Client IP in LoginModule
ragavgomatam Jul 17, 2008 9:35 PM (in response to prateek_n)Socket API
-
5. Re: Client IP in LoginModule
anil.saldhana Jul 23, 2008 10:16 AM (in response to prateek_n)What is needed is a interceptor pair (one on the client side to pick up the IP and one on the server side to place it in a static context for pick up by the login module).
-
6. Re: Client IP in LoginModule
prateek_n Jul 23, 2008 10:30 AM (in response to prateek_n)But the problem with having an interceptor pair is that there is no guarantee that the client will be using the interceptor to call the EJB
-
7. Re: Client IP in LoginModule
prateek_n Jul 23, 2008 10:32 AM (in response to prateek_n)Ragav,
Can you please expand on Socket API ? -
8. Re: Client IP in LoginModule
anil.saldhana Jul 23, 2008 10:56 AM (in response to prateek_n)It will work. If you want to muck around with something else, then be my guest.
-
9. Re: Client IP in LoginModule
ragavgomatam Jul 23, 2008 8:32 PM (in response to prateek_n)I agree with what anil says...Its probably cleaner way than Socket API...When I mentioned Socket API, I had in mind java.net.ServerSocket API..You could perhaps hack it & use it to get IP...But once again not at all an elegant way & is frowned by specs....If you are still interested, I can post the code
-
10. Re: Client IP in LoginModule
prateek_n Jul 23, 2008 9:29 PM (in response to prateek_n)It is definitely cleaner. But how can we guarantee that all clients will use the interceptor on the client end ?
-
11. Re: Client IP in LoginModule
prateek_n Jul 23, 2008 9:30 PM (in response to prateek_n)It is definitely cleaner. But how can we guarantee that all clients will use the interceptor on the client end ?
-
12. Re: Client IP in LoginModule
hedinant Jul 24, 2008 3:25 AM (in response to prateek_n)I use the first way in my login module works fine.
HttpServletRequest request = null;
try {
request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest");
} catch (PolicyContextException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
throw new RuntimeException("PolicyContext.getContext(javax.servlet.http.HttpServletRequest) failed");
}
String ip = request.getRemoteHost();
Map map = request.getParameterMap();
Host host = new Host(ip, hostKey);// TODO put registry key
return host; -
13. Re: Client IP in LoginModule
prateek_n Jul 24, 2008 11:57 AM (in response to prateek_n)This is what I did. But it only works for some client accessing web.
When a client is calling an EJB directly , then you do not get the HttpServletRequest in the PolicyContext .
The issue is retrieving the client IP in a direct EJB call.