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.rockagen.gnext.Filter.AccessFilter.java

/**
 * Get remote ip/* w ww.  j  a va 2  s. com*/
 * @param request {@link HttpServletRequest}
 * @return real ip address
 */
private String getIp(HttpServletRequest request) {

    String customerIp;
    // If proxies by nginx apache ...
    String temp1 = request.getHeader("X-Real-IP");

    if (!CommUtil.isBlank(temp1)) {
        customerIp = temp1;
    } else {
        // use default
        customerIp = request.getRemoteAddr();
    }
    return customerIp;

}

From source file:gumga.framework.security.GumgaRequestFilter.java

public void saveLog(AuthorizatonResponse ar, HttpServletRequest request, String operationKey, String endPoint,
        String method, boolean allowed, String token) {
    if (gumgaValues.isLogActive()) {
        GumgaLog gl = new GumgaLog(ar.getLogin(), request.getRemoteAddr(), ar.getOrganizationCode(),
                ar.getOrganization(), softwareId, operationKey, endPoint, method, allowed);
        gls.save(gl);//from   w w  w.ja  va 2  s . c om
    }
    if (gumgaValues.isLogRequestOnConsole()) {
        String contextRoot = request.getContextPath();
        String pathInfo = request.getRequestURI().substring(request.getRequestURI().indexOf(contextRoot));
        if (!gumgaValues.getUrlsToNotLog().contains(pathInfo)) {
            logGumga.info(String.format(
                    "Request anymarket from[%s] - login[%s] [%s][%s] [%s]- software[%s][%s] - destino[%s - %s - %s]",
                    request.getRemoteAddr(), ar.getLogin(), ar.getOrganizationCode(), ar.getOrganization(),
                    token, softwareId, operationKey, method, pathInfo, allowed));
        }
    }
}

From source file:ContextAccessor.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //get a servlet context attribute
    ContextObject contextObj = (ContextObject) getServletContext().getAttribute("com.java2s.ContextObject");

    if (contextObj != null)
        contextObj.put(request.getRemoteAddr(), "" + new java.util.Date());

    //display/* w  w w .  j a v  a  2s  . co m*/
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head><title>Servlet Context Attribute</title></head><body>");
    if (contextObj != null) {
        out.println("<h2>Servlet Context Attribute Values</h2>");
        out.println(contextObj.getValues());
    } else {
        out.println("<h2>Servlet Context Attribute is Null</h2>");
    }
    out.println("</body></html>");

}

From source file:it.greenvulcano.gvesb.api.security.JaxWsIdentityInfo.java

public JaxWsIdentityInfo(WebServiceContext securityContext) {
    super();/*from w w  w. j a  va 2 s .  c o m*/

    HttpServletRequest request = (HttpServletRequest) securityContext.getMessageContext()
            .get(MessageContext.SERVLET_REQUEST);

    this.securityContext = (SecurityContext) securityContext.getMessageContext()
            .get(SecurityContext.class.getName());
    this.remoteAddress = request != null ? request.getRemoteAddr() : null;
}

From source file:gr.cti.android.experimentation.controller.PluginController.java

/**
 * Register a new plugin to the backend.
 *
 * @param response the HTTP response object.
 * @param plugin   the plugin object to register.
 */// w  w  w  .ja  v  a2 s.  c  o  m
@ResponseBody
@RequestMapping(value = "/plugin", method = RequestMethod.POST, produces = "application/json")
public Object addPlugin(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute final Plugin plugin) throws IOException {
    LOGGER.info(request.getRemoteAddr());

    final ApiResponse apiResponse = new ApiResponse();
    final String contextType = plugin.getContextType();
    if (contextType == null || plugin.getName() == null || plugin.getImageUrl() == null
            || plugin.getFilename() == null || plugin.getInstallUrl() == null || plugin.getDescription() == null
            || plugin.getRuntimeFactoryClass() == null || plugin.getUserId() == null) {
        LOGGER.info("wrong data: " + plugin);
        String errorMessage = "error";
        if (contextType == null) {
            errorMessage = "contextType cannot be null";
        } else if (plugin.getName() == null) {
            errorMessage = "name cannot be null";
        } else if (plugin.getImageUrl() == null) {
            errorMessage = "imageUrl cannot be null";
        } else if (plugin.getFilename() == null) {
            errorMessage = "filename cannot be null";
        } else if (plugin.getInstallUrl() == null) {
            errorMessage = "url cannot be null";
        } else if (plugin.getDescription() == null) {
            errorMessage = "description cannot be null";
        } else if (plugin.getRuntimeFactoryClass() == null) {
            errorMessage = "runtimeFactoryClass cannot be null";
        } else if (plugin.getUserId() == null) {
            errorMessage = "userId cannot be null";
        }
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMessage);
    } else {
        final Set<Plugin> existingPlugins = pluginRepository.findByContextType(contextType);
        if (existingPlugins.isEmpty()) {
            LOGGER.info("addPlugin: " + plugin);
            pluginRepository.save(plugin);
            apiResponse.setStatus(HttpServletResponse.SC_OK);
            apiResponse.setMessage("ok");
            apiResponse.setValue(plugin);
            return apiResponse;
        } else {
            LOGGER.info("plugin exists: " + plugin);
            response.sendError(HttpServletResponse.SC_CONFLICT,
                    "a plugin with this contextType already exists");
        }
    }
    return null;
}

From source file:com.music.web.util.ExceptionResolver.java

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {/*from w  w w. j a  v a 2s . c o  m*/

    // the stacktrace will be printed by spring's DispatcherServlet
    // we are only logging the request url and headeres here
    logger.warn("An exception occurred when invoking the following URL: " + request.getRequestURL()
            + " . Requester IP is " + request.getRemoteAddr() + ", User-Agent: "
            + request.getHeader("User-Agent") + "; Message=" + ex.getMessage() + ": "
            + ex.getStackTrace()[0].getMethodName());

    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    return null;
}

From source file:com.qut.middleware.spep.authn.bindings.impl.AuthnPostBindingImpl.java

private void handleAuthnRequest(HttpServletRequest request, HttpServletResponse response,
        AuthnProcessorData data, SPEP spep) throws AuthenticationException {
    try {//w  w  w  .j a  v  a  2 s  .c  o  m
        String remoteAddress = request.getRemoteAddr();

        this.logger.info("[Authn for {}] Initiating HTTP POST binding. Creating AuthnRequest", remoteAddress);
        String document = buildAuthnRequestDocument(request.getParameter("redirectURL"), request, response,
                data, spep);
        PrintStream out = new PrintStream(response.getOutputStream());

        /* Set cookie to allow javascript enabled browsers to autosubmit, ensures navigation with the back button is not broken because auto submit is active for only a very short period */
        Cookie autoSubmit = new Cookie("spepAutoSubmit", "enabled");
        autoSubmit.setMaxAge(172800); //set expiry to be 48 hours just to make sure we still work with badly configured clocks skewed from GMT
        autoSubmit.setPath("/");
        response.addCookie(autoSubmit);

        response.setStatus(HttpServletResponse.SC_OK);
        response.setHeader("Content-Type", "text/html");

        out.print(document);

        out.close();

        this.logger.info("[Authn for {}] Sent AuthnRequest successfully", remoteAddress);
    } catch (IOException e) {
        throw new AuthenticationException("Unable to send response due to an I/O error.", e);
    }
}

From source file:cz.incad.kramerius.security.impl.http.IsActionAllowedFromRequest.java

String getRemoteAddress(Configuration conf) {
    HttpServletRequest httpReq = this.provider.get();
    String headerFowraded = httpReq.getHeader(X_IP_FORWARD);
    if (StringUtils.isAnyString(headerFowraded) && matchConfigurationAddress(httpReq, conf)) {
        return headerFowraded;
    } else {/*from  ww w  . j  av  a 2 s  . co  m*/
        return httpReq.getRemoteAddr();
    }
}

From source file:de.yaio.services.metaextract.server.controller.MetaExtractController.java

protected String createRequestLogMessage(HttpServletRequest request) {
    return new StringBuilder("REST Request - ").append("[HTTP METHOD:").append(request.getMethod())
            .append("] [URL:").append(request.getRequestURL()).append("] [REQUEST PARAMETERS:")
            .append(getRequestMap(request)).append("] [REMOTE ADDRESS:").append(request.getRemoteAddr())
            .append("]").toString();
}