List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:org.hx.rainbow.common.web.session.RainbowSession.java
public static void web2Service(HttpServletRequest request) { if (request == null) { return;// w ww . ja va2s .com } setProperty(ThreadConstants.CONSTMER_IPADDRESS, request.getRemoteAddr()); setProperty(ThreadConstants.CONSTMER_HOST, request.getRemoteHost()); setProperty(ThreadConstants.CONSTMER_PORT, request.getRemotePort()); setProperty(ThreadConstants.SERVICE_IPADDRESS, request.getLocalAddr()); setProperty(ThreadConstants.SERVICE_HOST, request.getLocalName()); setProperty(ThreadConstants.RAINBOW_REQUEST, request); HttpSession session = request.getSession(); RainbowUser rainbowUser = (RainbowUser) session.getAttribute(ThreadConstants.RAINBOW_USER); if (rainbowUser != null) { setProperty(ThreadConstants.RAINBOW_SESSION, rainbowUser); setProperty(ThreadConstants.RAINBOW_LOGINID, rainbowUser.getUsername()); setProperty(ThreadConstants.RAINBOW_USERNAME, rainbowUser.getSessionData().get("name")); String sessionKeys = (String) PropertiesUtil.getInstance().read(THREAD_LOACL_FILE) .get(ThreadConstants.SESSION_KEYS); if (sessionKeys != null) { if (sessionKeys.equals("*")) { Enumeration<String> attrNames = session.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (SESSION_KEYS.contains(attrName)) { continue; } if (attrName != null) { Object session_attr = session.getAttribute(attrName); if (session_attr != null) { rainbowUser.getSessionData().put(attrName, session_attr); } } } } else { String[] s_sessionkey = StringUtils.split(sessionKeys, ","); for (int i = 0; i < s_sessionkey.length; i++) { if (s_sessionkey[i] != null) { Object session_attr = session.getAttribute(s_sessionkey[i]); if (session_attr != null) { rainbowUser.getSessionData().put(s_sessionkey[i], session_attr); } } } } } } // // // // // Map<String, Object> inCookie = new ConcurrentHashMap<String, Object>(); // String cookieKeys = (String)PropertiesUtil.get(ThreadConstants.resource_cookieKeys); // // if (cookieKeys != null) { // Cookie[] cookies = request.getCookies(); // if (cookies != null) { // if (cookieKeys.equals("*")) { // for (int i = 0; i < cookies.length; i++) { // Cookie cookie = cookies[i]; // String cookieName = cookie.getName(); // String cookieValue = cookie.getValue(); // if(cookieName != null && cookieValue != null){ // inCookie.put(cookieName, cookieValue); // } // } // } else { // cookieKeys = cookieKeys + ","; // for (int i = 0; i < cookies.length; i++) { // Cookie cookie = cookies[i]; // String cookieName = cookie.getName(); // if (cookieKeys.indexOf(cookieName + ",") > -1) { // String cookieValue = cookie.getValue(); // if(cookieName != null && cookieValue != null){ // inCookie.put(cookieName, cookieValue); // } // } // } // } // } // setProperty(ThreadConstants.IN_COOKIE, inCookie); // } }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractor.java
private static void handleInMessage(Map<String, String> auditInfo, Message message) { if (message == null) { LogUtils.info(LOGGER, "Input message is NULL."); return;// w w w . j a v a2 s .c om } try { auditInfo.put(AuditInfo.HTTP_METHOD.getKey(), safeToString(message.get(Message.HTTP_REQUEST_METHOD))); auditInfo.put(AuditInfo.PATH.getKey(), removeGeoStore((String) message.get(Message.PATH_INFO))); auditInfo.put(AuditInfo.BASE_PATH.getKey(), removeGeoStore((String) message.get(Message.BASE_PATH))); auditInfo.put(AuditInfo.QUERY_STRING.getKey(), safeToString(message.get(Message.QUERY_STRING))); HttpServletRequest httpServletRequest = (HttpServletRequest) message .get(AbstractHTTPDestination.HTTP_REQUEST); auditInfo.put(AuditInfo.REMOTE_ADDR.getKey(), safeToString(httpServletRequest.getRemoteAddr())); auditInfo.put(AuditInfo.REMOTE_HOST.getKey(), safeToString(httpServletRequest.getRemoteHost())); auditInfo.put(AuditInfo.REMOTE_USER.getKey(), safeToString(httpServletRequest.getRemoteUser())); auditInfo.put(AuditInfo.HOST.getKey(), safeToString(httpServletRequest.getServerName())); fillAuthInfo(auditInfo, httpServletRequest); auditInfo.put(AuditInfo.BODY_AS_STRING.getKey(), getPaylod(message)); } catch (Exception exception) { LogUtils.error(LOGGER, exception, "Error obtaining auditing information for input message."); } }
From source file:jp.go.nict.langrid.servicesupervisor.frontend.FrontEnd.java
/** * //w w w . j a va 2 s .c o m * */ public static LogInfo createLogInfo(HttpServletRequest request, InputStream responseBody, long responseMillis, int responseCode, int responseBytes, String protocolId) { String fromAddress = request.getRemoteAddr(); String fromHost = request.getRemoteHost(); if (fromAddress.equals("127.0.0.1")) { // localhost????HTTPHEADER_FROMADDRESS??? String fromAddressHeader = request.getHeader(LangridConstants.HTTPHEADER_FROMADDRESS); if (fromAddressHeader != null) { fromAddress = fromAddressHeader; fromHost = fromAddressHeader; } } int callNest = 0; String callNestString = request.getHeader(LangridConstants.HTTPHEADER_CALLNEST); if (callNestString != null && callNestString.length() > 0) { try { callNest = Integer.parseInt(callNestString); } catch (NumberFormatException e) { logger.warning("The value of call nest header is not a number: " + callNestString); } } String callTree = ""; try { callTree = getCallTree(protocolId, responseBody); } catch (IOException e) { } return new LogInfo(fromAddress, fromHost, Calendar.getInstance(), request.getRequestURI(), request.getContentLength(), responseMillis, responseCode, responseBytes, protocolId, request.getHeader("Referrer"), request.getHeader("User-Agent"), callNest, callTree); }
From source file:org.eclipse.kapua.app.console.server.KapuaRemoteServiceServlet.java
/** * * This method perform a XSRF validation on the given request and for the specific userToken. * This is a private method to support both, standard class validation or multipart Servlet validation. * * @param req//from w ww.j a va 2s . co m * @param userToken */ static private void performXSRFTokenValidation(HttpServletRequest req, GwtXSRFToken userToken) throws GwtKapuaException { HttpSession session = req.getSession(); if (!isValidXSRFToken(session, userToken)) { if (session != null) { s_logger.info("XSRF token is NOT VALID - Token={}", userToken.getToken()); s_logger.debug("\tSender IP: {}", req.getRemoteAddr()); s_logger.debug("\tSender Host: {}", req.getRemoteHost()); s_logger.debug("\tSender Port: {}", req.getRemotePort()); s_logger.debug("\tFull Request URL\n {}?{}\n\n", req.getRequestURL().toString(), req.getQueryString()); } // forcing the console log out session.invalidate(); s_logger.debug("Session invalidated."); throw new GwtKapuaException(GwtKapuaErrorCode.XSRF_INVALID_TOKEN, null, "Invalid XSRF token"); } }
From source file:org.eclipse.kura.web.server.KuraRemoteServiceServlet.java
/** * * This method perform a XSRF validation on the given request and for the specific userToken. * This is a private method to support both, standard class validation or multipart Servlet validation. * * @param req/* w w w. jav a2s. c o m*/ * @param userToken */ static private void performXSRFTokenValidation(HttpServletRequest req, GwtXSRFToken userToken) throws GwtKuraException { HttpSession session = req.getSession(); if (!isValidXSRFToken(session, userToken)) { if (session != null) { s_logger.info("XSRF token is NOT VALID - Token={}", userToken.getToken()); s_logger.debug("\tSender IP: {}", req.getRemoteAddr()); s_logger.debug("\tSender Host: {}", req.getRemoteHost()); s_logger.debug("\tSender Port: {}", req.getRemotePort()); s_logger.debug("\tFull Request URL\n {}?{}\n\n", req.getRequestURL().toString(), req.getQueryString()); } // forcing the console log out session.invalidate(); s_logger.debug("Session invalidated."); throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, null, "Invalid XSRF token"); } }
From source file:com.lm.lic.manager.util.GenUtil.java
/** * @param request/*from w w w. ja v a 2 s . c om*/ * @return */ public static String findDomain(HttpServletRequest request) { String domain = null; String remoteHost = request.getRemoteHost(); try { InetAddress inetAddress = Inet4Address.getByName(remoteHost); domain = inetAddress.getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } return domain; }
From source file:com.gtwm.pb.servlets.ServletUtilMethods.java
public static AppUserInfo getPublicUserForRequest(HttpServletRequest request, AuthenticatorInfo authenticator) throws MissingParametersException, ObjectNotFoundException { String internalCompanyName = request.getParameter("c"); if (internalCompanyName == null) { throw new MissingParametersException("c needed to identify company"); }/*w w w. j a v a 2 s .c o m*/ String userName = "public"; String forename = "Host " + request.getRemoteHost(); String surname = "Addr " + request.getRemoteAddr(); return new PublicUser(authenticator, internalCompanyName, userName, surname, forename); }
From source file:org.hippoecm.repository.FormAuth.java
public static Session login(HttpServletRequest request, SimpleCredentials credentials, HippoRepository repository) {//w w w . ja v a 2 s . c o m Session hippoSession; try { if (credentials.getUserID() == null || credentials.getUserID().length() == 0) { hippoSession = repository.login(); } else { hippoSession = repository.login(credentials); } if (((HippoSession) hippoSession).getUser().isSystemUser()) { final InetAddress address = InetAddress.getByName(request.getRemoteHost()); if (!address.isAnyLocalAddress() && !address.isLoopbackAddress()) { throw new LoginException(); } } return hippoSession; } catch (Exception e) { return null; } }
From source file:org.apache.openaz.xacml.rest.XACMLRest.java
/** * Helper routine to dump the HTTP servlet request being serviced. Primarily for debugging. * * @param request - Servlet request (from a POST/GET/PUT/etc.) *//*w w w.ja v a2 s . c o m*/ public static void dumpRequest(HttpServletRequest request) { if (logger.isDebugEnabled()) { // special-case for receiving heartbeat - don't need to repeatedly output all of the information // in multiple lines if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type"))) { logger.debug("GET type=hb : heartbeat received"); return; } logger.debug(request.getMethod() + ":" + request.getRemoteAddr() + " " + request.getRemoteHost() + " " + request.getRemotePort()); logger.debug(request.getLocalAddr() + " " + request.getLocalName() + " " + request.getLocalPort()); Enumeration<String> en = request.getHeaderNames(); logger.debug("Headers:"); while (en.hasMoreElements()) { String element = en.nextElement(); Enumeration<String> values = request.getHeaders(element); while (values.hasMoreElements()) { String value = values.nextElement(); logger.debug(element + ":" + value); } } logger.debug("Attributes:"); en = request.getAttributeNames(); while (en.hasMoreElements()) { String element = en.nextElement(); logger.debug(element + ":" + request.getAttribute(element)); } logger.debug("ContextPath: " + request.getContextPath()); if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) { // POST and PUT are allowed to have parameters in the content, but in our usage the parameters // are always in the Query string. // More importantly, there are cases where the POST and PUT content is NOT parameters (e.g. it // might contain a Policy file). // Unfortunately the request.getParameterMap method reads the content to see if there are any // parameters, // and once the content is read it cannot be read again. // Thus for PUT and POST we must avoid reading the content here so that the main code can read // it. logger.debug("Query String:" + request.getQueryString()); try { if (request.getInputStream() == null) { logger.debug("Content: No content inputStream"); } else { logger.debug("Content available: " + request.getInputStream().available()); } } catch (Exception e) { logger.debug("Content: inputStream exception: " + e.getMessage() + "; (May not be relevant)"); } } else { logger.debug("Parameters:"); Map<String, String[]> params = request.getParameterMap(); Set<String> keys = params.keySet(); for (String key : keys) { String[] values = params.get(key); logger.debug(key + "(" + values.length + "): " + (values.length > 0 ? values[0] : "")); } } logger.debug("Request URL:" + request.getRequestURL()); } }
From source file:de.metas.ui.web.login.LoginRestController.java
private static MSession createMSession(final Login loginService) { final HttpServletRequest httpRequest = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest(); final HttpSession httpSess = httpRequest.getSession(); final String webSessionId = httpSess.getId(); //// w w w .j a v a2 s . c o m // final WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); String remoteAddr = httpRequest.getRemoteAddr(); String remoteHost = httpRequest.getRemoteHost(); // // Check if we are behind proxy and if yes, get the actual client IP address // NOTE: when configuring apache, don't forget to activate reverse-proxy mode // see http://www.xinotes.org/notes/note/770/ final String forwardedFor = httpRequest.getHeader("X-Forwarded-For"); if (!Check.isEmpty(forwardedFor)) { remoteAddr = forwardedFor; remoteHost = forwardedFor; } final LoginContext ctx = loginService.getCtx(); final MSession sessionPO = MSession.get(ctx.getSessionContext(), remoteAddr, remoteHost, webSessionId); // Set HostKey // FIXME: commented out because this one is not working when running over websockets (i.e. HttpServletResponse does not exists) // see https://dev.vaadin.com/ticket/11808 // @formatter:off // final I_AD_Session session = InterfaceWrapperHelper.create(sessionPO, I_AD_Session.class); // HttpCookieHostKeyStorage.createUpdateHostKey(); // final String hostKey = hostKeyBL.getHostKey(); // session.setHostKey(hostKey); // InterfaceWrapperHelper.save(session); // @formatter:on // Update Login helper loginService.setRemoteAddr(remoteAddr); loginService.setRemoteHost(remoteHost); loginService.setWebSession(webSessionId); return sessionPO; }