6 Replies Latest reply on Dec 29, 2001 3:22 PM by starksm64

    Knowing client IP address

    rajesh_sp

      Hi,

      Is it possible to the know the clients IP address from the app sever?

      like

      I want to know IP address of client before giving access to ejb?

      Thanks in advance

      Rajesh

        • 1. Re: Knowing client IP address

          No. From a servlet you can call the method getRemoteHost() on the class ServletRequest, but there isn't any corresponding way of obtaining this kind of information.

          You would probably have to do some substantial hacking of the server at the RMI lever to make this available.

          It probably isn't really the sort of logic you want to code in an EJB anyway. What exactly are you trying to do?

          Luke.

          • 2. Re: Knowing client IP address
            rajesh_sp

            Thanks luke,

            We are using EJB server and it can be connected by any kind of client like web client (here servlets become client), stand alone desktop clients etc. so here I want to know from where the request has come ?

            If a user is giving requests from one system he should not be allowed from any other system.

            and I want to know the number of live systems connected to the EJB server. ie if I configure for 5 live clients the ejb server should not take the request from the sixth system.

            I thought of this idea because ejb server works on RMI calls and in that we can know the clients IP address, so at first instant request to server it knows from where the request is coming (it can know )I dont know how to catch at my level. here I have written a authentication cache of my own with out touching jaassecuritymanager. I want know at cache level.

            Thank u
            Rajesh

            • 3. Re: Knowing client IP address

              Hi,

              I'd have to confess that I don't actually know a great deal about RMI - but after looking at the JDK docs, since the call takes place in a single thread, you could call RemoteServer.getClientHost() at any time during the invocation, and use this as you see fit in your security code...

              Hey it works. I just tried it. You learn something every day.

              Luke.

              • 4. Re: Knowing client IP address
                rajesh_sp

                Thanks Luke
                It is simple and straight forward, I am sorry to post the question with out checking this basic facility. What I thought is JBoss will have some form to catch it. It is not fair for JBoss to have some thing like that since it will be round about to know it.

                Thank you very much for co operating..

                Rajesh

                • 5. Re: Knowing client IP address

                  I don't think there is any guarantee in the EJB spec that the bean will be invoked using RMI, so this is probably why there is no standard api for obtaining the remote address. Also, if the bean is being invoked from a local web container then the information will be lost.

                  But in your case none of this should matter.

                  • 6. Re: Knowing client IP address
                    starksm64

                    Using java.rmi.server.RemoteServer.getClientHost() is not gaureenteed to work as this requires that the RMI
                    thread handling the remote call is also the thread which dispatches the call to the EJB container. This
                    happens to be the case now, but may not be in the future.