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:com.hangum.tadpole.commons.util.RequestInfoUtils.java

/**
 * user request ip/*from w  w  w. j  av a2  s .  com*/
 * 
 * @return
 */
public static String getRequestIP() {
    HttpServletRequest request = RWT.getRequest();

    String strIP = request.getHeader("X-Forwarded-For");
    //      if(logger.isDebugEnabled()) logger.debug("X-Forwarded-For: " + strIP);

    if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) {
        strIP = request.getHeader("Proxy-Client-IP");
        //          if(logger.isDebugEnabled()) logger.debug("Proxy-Client-IP[ip]" + strIP);
    }
    if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) {
        strIP = request.getHeader("WL-Proxy-Client-IP");
        //          if(logger.isDebugEnabled()) logger.debug("WL-Proxy-Client-IP[ip]" + strIP);
    }
    if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) {
        strIP = request.getHeader("HTTP_CLIENT_IP");
        //          if(logger.isDebugEnabled()) logger.debug("HTTP_CLIENT_IP[ip]" + strIP);
    }
    if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) {
        strIP = request.getHeader("HTTP_X_FORWARDED_FOR");
        //          if(logger.isDebugEnabled()) logger.debug("HTTP_X_FORWARDED_FOR[ip]" + strIP);
    }
    if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) {
        strIP = request.getRemoteAddr();
        //          if(logger.isDebugEnabled()) logger.debug("[ip]" + strIP);
    }

    return strIP;
}

From source file:psiprobe.controllers.apps.AjaxToggleContextController.java

@Override
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    if (!request.getContextPath().equals(contextName) && context != null) {
        try {/*from  ww  w. j  ava2 s  . c  o  m*/
            // Logging action
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            String name = auth.getName(); // get username logger
            if (context.getState().isAvailable()) {
                logger.info("{} requested STOP of {}", request.getRemoteAddr(), contextName);
                getContainerWrapper().getTomcatContainer().stop(contextName);
                logger.info(getMessageSourceAccessor().getMessage("probe.src.log.stop"), name, contextName);
            } else {
                logger.info("{} requested START of {}", request.getRemoteAddr(), contextName);
                getContainerWrapper().getTomcatContainer().start(contextName);
                logger.info(getMessageSourceAccessor().getMessage("probe.src.log.start"), name, contextName);
            }
        } catch (Exception e) {
            logger.error("Error during ajax request to START/STOP of '{}'", contextName, e);
        }
    }
    return new ModelAndView(getViewName(), "available",
            context != null && getContainerWrapper().getTomcatContainer().getAvailable(context));
}

From source file:com.phone.cn.web.action.BaseAppController.java

public String getRemoteHost(javax.servlet.http.HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }/*www .jav a  2s.c  o  m*/
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;
}

From source file:com.qualogy.qafe.web.upload.DatagridUploadServlet.java

@SuppressWarnings("unchecked")
private void writeUploadInfo(HttpServletRequest request) {
    writeLog("Document Upload!");

    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        Object name = headerNames.nextElement();
        if (name != null) {
            writeLog("Header - " + name + " : " + request.getHeader((String) name));
        }/*from   w w  w.  j av a 2s  . com*/
    }

    writeLog("ServletRemoteAddr: " + request.getRemoteAddr());
    writeLog("Remote Host: " + request.getRemoteHost());
    writeLog("Remote User: " + request.getRemoteUser());
    writeLog("Protocol: " + request.getProtocol());
    writeLog("Server Name: " + request.getServerName());
    writeLog("Server Port: " + request.getServerPort());
    writeLog("Request URL: " + request.getRequestURL());

}

From source file:com.formkiq.core.service.entry.WorkflowEntryFlowEventProcessor.java

/**
 * Add Signature Metadata./*from   w  w  w .j a  va2 s.c  o  m*/
 *
 * @param flow {@link WebFlow}
 * @param request {@link HttpServletRequest}
 */
public void eventIdsignaturemetadata(final WebFlow flow, final HttpServletRequest request) {

    FormJSON form = flow.getCurrentState().getData();

    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    params.put("inserteddate", new String[] { this.jsonService.dateToString(this.dateservice.now()) });
    params.put("ipaddress", new String[] { request.getRemoteAddr() });
    params.put("xforwardedfor",
            new String[] { StringUtils.defaultString(request.getHeader("X-FORWARDED-FOR"), "") });

    for (Map.Entry<String, String[]> e : params.entrySet()) {

        Optional<FormJSONField> field = findValueByKey(form, e.getKey());
        if (field.isPresent()) {

            if (isEmpty(field.get().getValue())) {
                field.get().setValue(Arrays.first(e.getValue()));
            }
        }
    }
}

From source file:com.konakart.actions.gateways.BaseGatewayAction.java

/**
 * /*from  w  ww  . j a  v  a2s  .co  m*/
 * @param request
 * @return Returns the IP address
 */
protected String getCustomerIPAddress(HttpServletRequest request) {
    return request.getRemoteAddr();
}

From source file:org.apache.cxf.fediz.service.idp.protocols.TrustedIdpSAMLProtocolHandler.java

/**
 * Validate the received SAML Response as per the Web SSO profile
 *///from w  w  w . j  av a  2 s. co m
private SSOValidatorResponse validateSamlSSOResponse(org.opensaml.saml2.core.Response samlResponse, Idp idp,
        TrustedIdp trustedIdp, RequestContext requestContext) {
    try {
        SAMLSSOResponseValidator ssoResponseValidator = new SAMLSSOResponseValidator();
        ssoResponseValidator.setAssertionConsumerURL(idp.getIdpUrl().toString());

        HttpServletRequest servletRequest = WebUtils.getHttpServletRequest(requestContext);
        ssoResponseValidator.setClientAddress(servletRequest.getRemoteAddr());

        ssoResponseValidator.setIssuerIDP(trustedIdp.getUrl());

        // Get the stored request ID
        String requestId = (String) WebUtils.getAttributeFromExternalContext(requestContext,
                SAML_SSO_REQUEST_ID);
        ssoResponseValidator.setRequestId(requestId);
        ssoResponseValidator.setSpIdentifier(idp.getRealm());
        ssoResponseValidator
                .setEnforceAssertionsSigned(isPropertyConfigured(trustedIdp, REQUIRE_SIGNED_ASSERTIONS, true));
        ssoResponseValidator
                .setEnforceKnownIssuer(isPropertyConfigured(trustedIdp, REQUIRE_KNOWN_ISSUER, true));

        return ssoResponseValidator.validateSamlResponse(samlResponse, false);
    } catch (WSSecurityException ex) {
        LOG.debug(ex.getMessage(), ex);
        throw ExceptionUtils.toBadRequestException(ex, null);
    }
}

From source file:eu.eidas.node.AbstractSpecificServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!StringUtils.isEmpty(request.getRemoteHost())) {
        MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
    }//from www . ja v a 2  s. co m
    MDC.put(MDC_SESSIONID, request.getSession().getId());
    getLogger().info(WEB_EVENT,
            "**** CALL to servlet " + this.getClass().getName() + "FROM " + request.getRemoteAddr() + "HTTP "
                    + request.getMethod() + " SESSIONID " + request.getSession().getId() + "****");

    super.service(request, response);
}

From source file:com.esd.vs.interceptor.LoginInterceptor.java

public String getRemoteAddress(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("Proxy-Client-IP");
    }//from   w  ww.  j  a va 2  s.c  o m
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getRemoteAddr();
    }
    return ip;
}

From source file:org.slc.sli.dashboard.security.SLIAuthenticationEntryPoint.java

private void initiatingAuthentication(HttpServletRequest request, HttpServletResponse response,
        HttpSession session, OAuthService service) throws IOException {

    LOG.info(LOG_MESSAGE_AUTH_INITIATING, new Object[] { request.getRemoteAddr() });

    session.setAttribute(ENTRY_URL, request.getRequestURL());

    // The request token doesn't matter for OAuth 2.0 which is why it's null
    String authUrl = service.getAuthorizationUrl(null);
    response.sendRedirect(authUrl);//from w  ww  . j a  v  a2s. c  om
}