List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:org.mashupmedia.controller.remote.RemoteLibraryController.java
private Library getRemoteLibrary(String connectingUniqueName, HttpServletRequest request, boolean isIncreaseAccessedMediaItems) { Library remoteLibrary = libraryManager.getRemoteLibrary(connectingUniqueName); String remoteHost = request.getRemoteHost(); if (isValidRemoteLibrary(remoteLibrary, connectingUniqueName, remoteHost, isIncreaseAccessedMediaItems)) { return remoteLibrary; }/*from ww w .j av a 2 s. co m*/ return null; }
From source file:org.sakaiproject.util.RemoteHostFilter.java
public void doFilter(ServletRequest sreq, ServletResponse sres, FilterChain chain) throws IOException, ServletException { // we are expecting HTTP if (!((sreq instanceof HttpServletRequest) && (sres instanceof HttpServletResponse))) { // if not, just pass it through chain.doFilter(sreq, sres);//w ww . j a va 2 s .c om return; } HttpServletRequest request = (HttpServletRequest) sreq; HttpServletResponse response = (HttpServletResponse) sres; String host = request.getRemoteHost(); String addr = request.getRemoteAddr(); // Check if explicit denied ... for (int i = 0; i < deny.length; i++) { if (deny[i].matcher(host).matches() || deny[i].matcher(addr).matches()) { if (logDenied && M_log.isInfoEnabled()) M_log.info("Access denied (" + deny[i].pattern() + "): " + host + "/" + addr); response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } // Check if explicitly allowed ... for (int i = 0; i < allow.length; i++) { if (allow[i].matcher(host).matches() || allow[i].matcher(addr).matches()) { if (logAllowed && M_log.isInfoEnabled()) M_log.info("Access granted (" + allow[i].pattern() + "): " + host + "/" + addr); chain.doFilter(sreq, sres); return; } } // Allow if allows is null, but denied is not if ((deny.length > 0) && (allow.length == 0)) { if (logAllowed && M_log.isInfoEnabled()) M_log.info("Access granted (implicit): " + host + "/" + addr); chain.doFilter(sreq, sres); return; } // Deny this request if (logDenied && M_log.isInfoEnabled()) M_log.info("Access denied (implicit): " + host + "/" + addr); response.sendError(HttpServletResponse.SC_FORBIDDEN); }
From source file:de.is24.aws.instancemetadataserver.SecurityCredentialsController.java
@RequestMapping("/{requestedRoleName}") public ResponseEntity<Map<String, String>> credential(HttpServletRequest request, @PathVariable String requestedRoleName) { return allowedRoleName(request).filter(requestedRoleName::equals).flatMap(this::getAwsRole) .map(this::assumeRole).map((r) -> { LOG.info("Assumed role {} for {} valid till {}", requestedRoleName, request.getRemoteHost(), df.format(r.getExpiration())); return r; }).map(this::asJson).map(ResponseEntity::ok).orElse(HTTP_NOT_FOUND); }
From source file:org.apache.servicemix.http.processors.ConsumerProcessor.java
private String getClientIp(HttpServletRequest request) { String clientName = request.getRemoteHost(); try {//w w w . j a v a2s . c om return InetAddress.getByName(clientName).getHostAddress(); } catch (UnknownHostException ex) { return clientName; } }
From source file:com.benfante.minimark.MinimarkExceptionResolver.java
@Override public ModelAndView resolveException(HttpServletRequest req, HttpServletResponse res, Object object, Exception e) {//from w ww. jav a 2 s . c o m try { if (!interceptedWithMinimalLogging(e)) { logger.error("Unexpected exception", e); } logger.info("Exception requesting URL: " + req.getRequestURL().toString()); logger.info(" request from " + req.getRemoteHost() + "(" + req.getRemoteAddr() + ")"); return super.resolveException(req, res, object, e); } catch (Exception ex) { logger.error("Error resolving exception", ex); } return new ModelAndView("redirect:/home/500page.html"); }
From source file:de.mpg.escidoc.services.pidcache.web.MainServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("PID cache GET request"); try {// w w w . ja v a 2s.c o m if (!authenticate(req, resp)) { logger.warn("Unauthorized request from " + req.getRemoteHost()); return; } PidCacheService pidCacheService = new PidCacheService(); if (GwdgPidService.GWDG_PIDSERVICE_VIEW.equals(req.getPathInfo()) || GwdgPidService.GWDG_PIDSERVICE_VIEW.concat("/").equals(req.getPathInfo())) { if (req.getParameter("pid") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed."); } resp.getWriter().append(pidCacheService.retrieve(req.getParameter("pid"))); } else if ("/cache/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getCacheSize() + " PID stored in cache"); } else if ("/queue/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getQueueSize() + " PID actually in queue"); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo()); } } catch (Exception e) { throw new ServletException("Error processing request", e); } }
From source file:org.energy_home.jemma.internal.ah.eh.esp.ESPServlet.java
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { String queryString = servletRequest.getRequestURI(); if (queryString.startsWith(userRegistrationUri)) { if (servletRequest.getRemoteHost().equals(remoteHostAddr)) { log.warn("service: registration uri is not accessible through vpn proxy"); servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); } else {// w w w . j a v a2 s . com HttpResponse response = null; try { response = restClient.get(userRegistrationGetUri); String responseUri = EntityUtils.toString(response.getEntity()); servletResponse.sendRedirect(responseUri); } catch (Exception e) { log.error("service: error while connecting to userRegistrationGetUri", e); servletResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } finally { releaseRequestResources(response); } } } else if (queryString.startsWith(authTokenUriStr)) { HttpResponse response = null; PrintWriter pw = null; try { response = restClient.get(remoteAuthTokenUri); String token = EntityUtils.toString(response.getEntity()); pw = servletResponse.getWriter(); pw.println(token); } catch (Exception e) { log.error("service: error while connecting to remoteAuthTokenUri", e); servletResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } finally { releaseRequestResources(response); if (pw != null) try { pw.close(); } catch (Exception e2) { log.error( "service: error while releasing printwriter used for connection to remoteAuthTokenUri", e2); } } } else { servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:eionet.cr.web.action.PingActionBean.java
/** * The default handler of this API's calls. * * @return//from www.ja v a2 s. c o m */ @DefaultHandler public Resolution defaultHandler() { // Get client host/IP, ensure that it's in the whitelist. HttpServletRequest request = getContext().getRequest(); String ip = request.getRemoteAddr(); String host = processClientHostName(request.getRemoteHost(), ip); if (!isTrustedRequester(host, ip)) { LOGGER.debug("Client denied: host = " + host + ", IP = " + ip); return new ErrorResolution(HttpURLConnection.HTTP_FORBIDDEN); } // The default result-message and error code that will be printed into XML response. int errorCode = 0; String message = ""; try { // Ensure that the pinged URI is not blank, is legal URI, does not have a fragment part and is not broken. if (StringUtils.isBlank(uri)) { errorCode = ERR_BLANK_URI; message = "No URI given, no action taken."; } else if (!URLUtil.isURL(uri)) { if (create) { errorCode = ERR_INVALID_URL; message = "Not a valid URL, source cannot be created."; } else { message = "URL not in catalogue of sources, no action taken."; } } else if (create && new URL(uri).getRef() != null) { errorCode = ERR_FRAGMENT_URL; message = "URL with a fragment part not allowed, source cannot be created."; } else if (create && URLUtil.isNotExisting(uri)) { errorCode = ERR_BROKEN_URL; message = "Could not make a connection to this URL, source cannot be created."; } else { // Helper flag that will be raised if a harvest is indeed needed. boolean doHarvest = false; // Check if a graph by this URI exists. boolean exists = DAOFactory.get().getDao(HelperDAO.class).isGraphExists(uri); if (exists) { doHarvest = true; } else if (create) { // Graph does not exist, but must be created as indicated in request parameters HarvestSourceDTO source = new HarvestSourceDTO(); source.setUrl(uri); source.setIntervalMinutes( GeneralConfig.getIntProperty(GeneralConfig.HARVESTER_REFERRALS_INTERVAL, 60480)); DAOFactory.get().getDao(HarvestSourceDAO.class).addSource(source); doHarvest = true; } else { message = "URL not in catalogue of sources, no action taken."; } if (doHarvest) { UrgentHarvestQueue.addPullHarvest(uri); message = "URL added to the urgent harvest queue: " + uri; } } } catch (Exception e) { LOGGER.error("PING request failed: " + e.toString(), e); return new ErrorResolution(HttpURLConnection.HTTP_INTERNAL_ERROR); } LOGGER.debug(message); String response = RESPONSE_XML.replace("@message@", message); response = response.replace("@errorCode@", String.valueOf(errorCode)); return new StreamingResolution("text/xml", response); }
From source file:com.haulmont.cuba.core.sys.remoting.RemotingServlet.java
@Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { checkConfiguration(request);/* w w w . j ava2s . c o m*/ RemoteClientInfo remoteClientInfo = new RemoteClientInfo(); remoteClientInfo.setAddress(request.getRemoteAddr()); remoteClientInfo.setHost(request.getRemoteHost()); remoteClientInfo.setPort(request.getRemotePort()); RemoteClientInfo.set(remoteClientInfo); try { super.doService(request, response); } finally { RemoteClientInfo.clear(); } }
From source file:com.greenline.hrs.admin.web.war.common.LoginController.java
@RequestMapping(value = "login", method = RequestMethod.POST) public String login(@ModelAttribute UserLoginInfo userLoginInfo, HttpServletRequest httpRequest) { if (userLoginInfo.getAccount() == null || userLoginInfo.getPassword() == null) { return CommonViewConst.LOGIN_VIEW; }/*from w w w . ja v a 2s .c om*/ LOG.debug("LogController.login:" + userLoginInfo.getAccount()); LoginStatus loginStatus = loginService.login(userLoginInfo.getAccount(), userLoginInfo.getPassword(), httpRequest.getRemoteHost()); switch (loginStatus) { case SUCCESS: return CommonViewConst.HOME_VIEW; case ILLEGAL_USER_PWD: default: //????? List<String> errorMessages = new ArrayList<String>(2); errorMessages.add(UserResponseConst.ILLEGAL_UID_OR_PWD); httpRequest.setAttribute(WebResponseConst.ERROR_MESSAGES, errorMessages); return CommonViewConst.LOGIN_VIEW; } }