If this is for security purpose you can use JAAS programmatically to get users info
also if the request is coming through a servlet, HttpServletRequest.getRemoteAddr can be helpful.SessionContext.getCallerIdentity could be useful but its deprecated. not sure about alternative