Example usage for javax.servlet.http HttpServletRequest getRemoteAddr

List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRemoteAddr.

Prototype

public String getRemoteAddr();

Source Link

Document

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.

Usage

From source file:fi.helsinki.opintoni.audit.AuditEventConverterTest.java

@Test
public void thatDataIsConvertedToStrings() {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");

    HttpSession session = mock(HttpSession.class);
    when(request.getSession(false)).thenReturn(session);
    when(session.getId()).thenReturn("ABCDEFGHIJK");

    Map<String, Object> data = Maps.newHashMap();
    data.put("key", "value");
    data.put("authenticationDetails", new WebAuthenticationDetails(request));

    Map<String, String> stringsByKey = auditEventConverter.convertDataToStrings(data);

    assertThat(stringsByKey).hasSize(3);
    assertThat(stringsByKey.get("key")).isEqualTo("value");
    assertThat(stringsByKey.get("remoteAddress")).isEqualTo("127.0.0.1");
    assertThat(stringsByKey.get("sessionId")).isEqualTo("ABCDEFGHIJK");
}

From source file:org.esupportail.papercut.web.PayBoxCallbackController.java

/** 
 * Manage callback response from paybox - url like :  
 * /*  www  .  j a  va 2 s .  co m*/
 * /payboxcallback?montant=200&reference=bonamvin@univrouen@200-2013-08-23-17-08-18-394&auto=XXXXXX&erreur=00000&idtrans=3608021&signature=CPqq18Un24NL0llB3E3G9kbKI4ztlkoL%2BSRTnMMrWlPBTVNTsn%2B%2FxA0YMSQOGGnU0wm45HYh%2F2RHoZGG3THzj7xKSY6upNJcnKrfFmzfTgA5FTFA3dyM27RgKmLcCeH48FRNoZPjVsKk0G2npvaP%2FY5pkSvn%2BQUl34DkmJkTejs%3D
 *
 * @param uiModel
 * @return empty page
 */
@RequestMapping("/payboxcallback")
@ResponseBody
public ResponseEntity<String> index(@RequestParam String montant, @RequestParam String reference,
        @RequestParam(required = false) String auto, @RequestParam String erreur, @RequestParam String idtrans,
        @RequestParam String signature, HttpServletRequest request) {

    String paperCutContext = reference.split("@")[1];
    String ip = request.getRemoteAddr();
    String queryString = request.getQueryString();

    if (esupPaperCutServices.get(paperCutContext).payboxCallback(montant, reference, auto, erreur, idtrans,
            signature, queryString, ip, null)) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "text/html; charset=utf-8");
        return new ResponseEntity<String>("", headers, HttpStatus.OK);
    } else {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "text/html; charset=utf-8");
        return new ResponseEntity<String>("", headers, HttpStatus.FORBIDDEN);
    }
}

From source file:org.openmrs.module.kenyaemr.SystemMonitorController.java

/**
 * Checks if incoming request for system monitoring data should be allowed
 * @param request the request/*from   www  . ja v  a2 s . c  o m*/
 * @return true if request should be allowed
 */
protected boolean checkAccess(HttpServletRequest request) {
    // For now just check that request is local
    return OpenmrsUtil.nullSafeEquals(request.getRemoteAddr(), request.getLocalAddr());
}

From source file:io.kamax.mxisd.controller.identity.v1.MappingController.java

private void setRequesterInfo(ALookupRequest lookupReq, HttpServletRequest req) {
    lookupReq.setRequester(req.getRemoteAddr());
    String xff = req.getHeader("X-FORWARDED-FOR");
    log.debug("XFF header: {}", xff);
    lookupReq.setRecursive(StringUtils.isBlank(xff));
    if (!lookupReq.isRecursive()) {
        lookupReq.setRecurseHosts(Arrays.asList(xff.split(",")));
        lookupReq.setRequester(lookupReq.getRecurseHosts().get(lookupReq.getRecurseHosts().size() - 1));
    }/*  w ww.j  av  a 2 s. c  om*/

    lookupReq.setUserAgent(req.getHeader("USER-AGENT"));
}

From source file:cn.sel.wetty.interceptor.AccessLogger.java

private void i(HttpServletRequest request) {
    String msg = String.format("%s -> %s\t[%s]\tHeaders:%s\tParameters:%s", request.getRemoteAddr(),
            request.getRequestURI(), request.getMethod(), getHeaders(request), request.getParameterMap());
    LOGGER.info(msg);/* w  w  w  .j a va  2s.  c  o  m*/
}

From source file:gov.nih.nci.cabig.caaers.ws.AuditInfoPopulatorWSInterceptor.java

public void handleMessage(Message message) throws Fault {
    if (logger.isDebugEnabled())
        logger.debug("About to populate the auditing information");
    Authentication authz = SecurityUtils.getAuthentication();

    String userName = "SYSTEM";
    if (authz != null) {
        userName = SecurityUtils.getUserLoginName(authz);
    }//w  ww.  ja va2 s  . c  om
    String ipAddress = "127.0.0.1";
    String url = "webservice";
    HttpServletRequest request = (HttpServletRequest) message.get("HTTP.REQUEST");
    if (request != null) {
        ipAddress = request.getRemoteAddr();
        url = request.getServletPath();
    }
    DataAuditInfo newAuditInfo = AuditUtils.generateDataAuditInfo(userName, ipAddress, url);
    DataAuditInfo existing = (DataAuditInfo) DataAuditInfo.getLocal();
    DataAuditInfo.setLocal(newAuditInfo);
    if (logger.isDebugEnabled())
        logger.debug("Associated to thread AuditInfo  " + newAuditInfo.toString());
}

From source file:eu.scape_project.pw.idp.validator.ReCaptchaValidator.java

@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    String remoteAddr = request.getRemoteAddr();
    ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
    reCaptcha.setPrivateKey(config.getString("recaptcha.privatekey"));

    String challenge = request.getParameter("recaptcha_challenge_field");
    String uresponse = request.getParameter("recaptcha_response_field");
    if (challenge == null || uresponse == null) {
        throw new ValidatorException(new FacesMessage(
                "No ReCaptcha text. Maybe you have JavaScript disabled. Please enable and retry."));
    }/* w  w  w  .  j ava2s .c  o m*/
    ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);

    if (reCaptchaResponse.isValid()) {
        return;
    } else {
        throw new ValidatorException(new FacesMessage("Invalid ReCaptcha text. Please try again."));
    }
}

From source file:com.mycompany.wolf.Router.java

public void quitOne(HttpServletRequest req, String roomId) {
    String remoteAddr = req.getRemoteAddr();
    ServerInfo server = servers.stream().filter(s -> Objects.equals(s.getIntranetAddress(), remoteAddr))
            .findAny().orElse(null);//from  w w  w  . j  a  v a2  s  . c  o m
    if (server != null) {
        RoomInfo roomInfo = server.getRooms().stream().filter(r -> Objects.equals(r.roomId, roomId)).findAny()
                .orElse(null);
        synchronized (roomInfo.mutex) {
            roomInfo.playerCount--;
        }
    }
}

From source file:org.tsm.concharto.web.feedback.FeedbackController.java

@SuppressWarnings("unchecked")
private String getBrowserInfo(HttpServletRequest request) {
    StringBuffer userRequestInfo = new StringBuffer().append(request.getRemoteAddr()).append("\n")
            .append(request.getRemoteHost()).append("\n");

    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        //don't email cookies for security reasons
        if (!"cookie".equals(headerName)) {
            userRequestInfo.append(headerName).append(": ").append(request.getHeader(headerName)).append("\n");
        }//from w  w w  . jav a 2s  .  c om

    }
    return userRequestInfo.toString();
}

From source file:com.nkapps.billing.services.AuthServiceImpl.java

@Override
public String getClientIp(HttpServletRequest request) {
    String ip = request.getRemoteAddr();
    if (request.getHeader("X-Real-IP") != null && !"".equals(request.getHeader("X-Real-IP"))) {
        ip = request.getHeader("X-Real-IP");
    }//from  w  ww .ja  va  2 s.  c  o m
    return ip;
}