List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr
public String getRemoteAddr();
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.FriendController.java
private void writeWarningToTheLog(HttpServletRequest req) { log.warn("LOGGING IN VIA FRIEND FROM ADDR=" + req.getRemoteAddr() + ", PORT=" + req.getRemotePort() + ", HOST=" + req.getRemoteHost() + ", USER=" + req.getRemoteUser()); }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.IpAddressFilter.java
private boolean isAllowed(final HttpServletRequest request) { String ip = request.getRemoteAddr(); if (IPV4_LOOPBACK.equals(ip) || IPV6_LOOPBACK.equals(ip)) { // always allow localhost return true; }/*from w w w. j a v a2s . co m*/ String uri = (String) request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE); if (!StringUtils.hasLength(uri)) { uri = request.getRequestURI(); if (!request.getContextPath().equals("/") && uri.startsWith(request.getContextPath())) { uri = uri.substring(request.getContextPath().length()); } } Collection<Map.Entry<String, List<String>>> matching = findMatchingRules(uri); if (matching.isEmpty()) { return true; } for (Map.Entry<String, List<String>> entry : matching) { for (String ipPattern : entry.getValue()) { if (new IpAddressMatcher(ipPattern).matches(request)) { return true; } } } _log.warn("disallowed request " + uri + " from " + ip); return false; }
From source file:business.security.CustomLoggingInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { log.trace(String.format("%s\t%s\t%s\t%s\t%s", new Date(), request.getRemoteAddr(), request.getUserPrincipal() == null ? " - " : request.getUserPrincipal().getName(), request.getMethod(), request.getRequestURI())); return super.preHandle(request, response, handler); }
From source file:grails.plugin.springsecurity.web.filter.IpAddressFilter.java
protected boolean isAllowed(final HttpServletRequest request) { String ip = request.getRemoteAddr(); if (allowLocalhost && (IPV4_LOOPBACK.equals(ip) || IPV6_LOOPBACK.equals(ip))) { return true; }//w ww . jav a 2 s .c o m String uri = (String) request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE); if (!StringUtils.hasLength(uri)) { uri = request.getRequestURI(); if (!request.getContextPath().equals("/") && uri.startsWith(request.getContextPath())) { uri = uri.substring(request.getContextPath().length()); } } List<InterceptedUrl> matching = findMatchingRules(uri); if (matching.isEmpty()) { return true; } for (InterceptedUrl iu : matching) { for (ConfigAttribute ipPattern : iu.getConfigAttributes()) { if (new IpAddressMatcher(ipPattern.getAttribute()).matches(request)) { return true; } } } log.warn("disallowed request {} from {}", new Object[] { uri, ip }); return false; }
From source file:com.iaito.atsws.controller.TagEntryController.java
@RequestMapping(value = "/getreaders", method = RequestMethod.GET) public @ResponseBody List<Reader> getReaders(HttpServletRequest request) { try {// w w w. j a va2s. c o m System.out.println("Ip address :" + request.getRemoteAddr()); List<Reader> readerList = clientService.getReaderList(); if (readerList == null) { readerList = new ArrayList(); } return readerList; } catch (Exception e) { System.out.println("Exception--in TagEntryController.java---getReaders()---" + e.getMessage()); return new ArrayList(); } }
From source file:modelo.AutenticacionManager.Autenticacion.java
public void doLogIn(String login, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String rol = ""; String ip = request.getRemoteAddr(); HttpSession sesion = request.getSession(); variablesSession(sesion, response, login, rol, ip); //Tiempo en que expira la sesion sesion.setMaxInactiveInterval(Integer.parseInt(ActiveDirectory.getString("sesionTimeOut"))); }
From source file:de.egore911.opengate.services.GameserverService.java
@GET @Path("/remove") @Produces("application/json") @Documentation("This method removes a gameserver from the list. It is recommend to call this " + "method on shutdown of the gameserver. The remote IP will be obtained from the packet " + "sent to the server so server behind a NAT will not work. The method will answer using " + "a JSON object like {status: 'ok', detail: '...'}.") public Response removeGameserver(@Context HttpServletRequest req) { String remoteAddr = req.getRemoteAddr(); EntityManager em = EntityManagerFilter.getEntityManager(); Gameserver gameserver;/*w w w. ja v a2 s. co m*/ try { JSONObject retval = new JSONObject(); StatusHelper.ok(retval); try { gameserver = (Gameserver) em .createQuery("select gameserver from Gameserver gameserver where address = :address") .setParameter("address", remoteAddr).getSingleResult(); em.remove(gameserver); retval.put("detail", "Successfully removed"); } catch (NoResultException e) { // Nothing to do retval.put("detail", "Already removed"); } return Response.ok(retval.toString()).build(); } catch (JSONException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:com.googlecode.psiprobe.controllers.logs.DownloadLogController.java
protected ModelAndView handleLogFile(HttpServletRequest request, HttpServletResponse response, LogDestination logDest) throws Exception { File file = logDest.getFile(); logger.info("Sending " + file + " to " + request.getRemoteAddr() + "(" + request.getRemoteUser() + ")"); Utils.sendFile(request, response, file); return null;// w w w .j av a 2 s .co m }
From source file:de.egore911.opengate.services.GameserverService.java
@GET @Path("/add") @Produces("application/json") @Documentation("Add or update a gameserver to the list of available game servers. " + "The remote IP will be obtained from the packet sent to the server so server " + "behind a NAT will not work. The method will answer using a JSON object like " + "{status: 'ok', detail: '...'}.") public Response addGameserver(@Context HttpServletRequest req) { String remoteAddr = req.getRemoteAddr(); EntityManager em = EntityManagerFilter.getEntityManager(); Gameserver gameserver;//from w w w . j a va 2s . co m try { JSONObject retval = new JSONObject(); StatusHelper.ok(retval); try { gameserver = (Gameserver) em .createQuery("select gameserver from Gameserver gameserver where address = :address") .setParameter("address", remoteAddr).getSingleResult(); retval.put("detail", "Gameserver updated"); } catch (NoResultException e) { gameserver = new Gameserver(); gameserver.setAddress(remoteAddr); retval.put("detail", "Gameserver added"); } gameserver.setLastSeen(new Date()); em.persist(gameserver); return Response.ok(retval.toString()).build(); } catch (JSONException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:cz.incad.kramerius.security.impl.http.IsActionAllowedFromRequest.java
boolean matchConfigurationAddress(HttpServletRequest httpReq, Configuration conf) { String remoteAddr = httpReq.getRemoteAddr(); List<String> forwaredEnabled = conf.getList("x_ip_forwared_enabled_for", Arrays.asList(LOCALHOSTS)); if (!forwaredEnabled.isEmpty()) { for (String pattern : forwaredEnabled) { if (remoteAddr.matches(pattern)) return true; }/*w w w .j a v a 2 s.c om*/ } return false; }