tags:

views:

105

answers:

2

How can I get the IP of the Client (request) in a JSR168 Portlet?

I'm on Liferay 5.2.3

I can get the IP with Liferay internal functionality:

String ip = com.liferay.portal.util.PortalUtil.getHttpServletRequest(renderRequest).getRemoteAddr();

Is there any portal neutral way to do this?

+1  A: 

Well, one way...if in your Portlet you use Spring MVC, you would have access to the same servlet request and could get the client IP. I don't have the code handy, but if you tack on to your controller class the use of the ActionRequest or the HTTPservlet request. That should get it for you in a non-Liferay fashion.

Steven Dorfmeister
A: 

Sorry, I'm not going to answer your question here, but add some reasons why you might not want to get that IP-Address. For some setups it's common, that requests from one client come through multiple IP-addresses: Either they might be behind a loadbalancer, bundling some connections that have different external IP-addresses, or they might hide behind a proxy farm, where each proxy comes with different addresses.

Also, with a proxy or with NAT involved, you might get multiple clients from the same IP-address.

Therefor: Please take extreme care if you use the client address for authentication purposes: You might need multiple addresses for one client or have multiple clients from one address. Also, you can have multiple clients from (the same) multiple addresses. I've seen many dangerous assumptions regarding the client addresses.

Take care!

Olaf