Example usage for javax.servlet.http HttpServletRequest getRemoteHost

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

Introduction

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

Prototype

public String getRemoteHost();

Source Link

Document

Returns the fully qualified name of the client or the last proxy that sent the request.

Usage

From source file:com.github.matthesrieke.simplebroker.SimpleBrokerServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (verifyRemoteHost(req.getRemoteHost())) {
        final String content;
        final ContentType type;
        final String remoteHost;
        try {/*from   ww  w. j  a  va 2  s.  co  m*/
            content = readContent(req);
            type = ContentType.parse(req.getContentType());
            remoteHost = req.getRemoteHost();
        } catch (IOException e) {
            logger.warn(e.getMessage());
            return;
        }

        this.executor.submit(new Runnable() {

            public void run() {
                for (Consumer c : consumers)
                    try {
                        c.consume(content, type, remoteHost);
                    } catch (RuntimeException e) {
                        logger.warn(e.getMessage());
                    } catch (IOException e) {
                        logger.warn(e.getMessage());
                    }
            }
        });
    } else {
        logger.info("Host {} is not whitelisted. Ignoring request.", req.getRemoteHost());
    }

    resp.setStatus(HttpStatus.SC_NO_CONTENT);
}

From source file:org.apache.wookie.proxy.ProxyServlet.java

/**
 * Checks that the request is from the same domain as this service
 * @param request/*w w w . j  a v  a2  s  . co  m*/
 * @param checkDomain
 * @return
 */
private boolean isSameDomain(HttpServletRequest request) {
    String remoteHost = request.getRemoteHost();
    String serverHost = request.getServerName();
    if (remoteHost.equals(serverHost)) {
        return true;
    }
    return false;
}

From source file:net.sourceforge.vulcan.web.struts.actions.FlushBuildQueueAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    stateManager.flushBuildQueue();/*from   www.j  av a  2s .c o  m*/

    final AuditEvent event = new AuditEvent(this, "audit.build.queue.flush",
            BaseDispatchAction.getUsername(request), request.getRemoteHost(), "flush", "build queue");

    eventHandler.reportEvent(event);
    auditLog.info(messageSource.getMessage(event.getKey(), event.getArgs(), Locale.getDefault()));

    return mapping.findForward("dashboard");
}

From source file:com.github.terma.m.server.NodeServlet.java

@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    final List<Event> newEvents = GSON.fromJson(IOUtils.toString(request.getInputStream()), EVENTS_TYPE);
    EventsHolder.get().add(newEvents);//  w  w w .  j ava 2 s  .  c  o m
    NodeManager.INSTANCE.responseFromNode(request.getRemoteHost());
}

From source file:com.nesscomputing.jmx.jolokia.JolokiaServlet.java

private void handle(final ServletRequestHandler reqHandler, final HttpServletRequest req,
        final HttpServletResponse resp) throws IOException {
    JSONAware json = null;//from  w  w w .  jav a 2 s.c o m
    try {
        // Check access policy
        requestHandler.checkClientIPAccess(req.getRemoteHost(), req.getRemoteAddr());

        // Dispatch for the proper HTTP request method
        json = reqHandler.handleRequest(req, resp);

        if (backendManager.isDebug()) {
            backendManager.debug("Response: " + json);
        }
    } catch (RuntimeMBeanException rme) {
        json = requestHandler.handleThrowable(rme.getTargetException());
    } catch (Throwable exp) {
        json = requestHandler.handleThrowable(exp);
    } finally {
        final String callback = req.getParameter(ConfigKey.CALLBACK.getKeyValue());
        if (callback != null) {
            // Send a JSONP response
            sendResponse(resp, "text/javascript", callback + "(" + json.toJSONString() + ");");
        } else {
            sendResponse(resp, "application/json", json.toJSONString());
        }
    }
}

From source file:LogFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, ServletException {

    HttpServletRequest req = null;
    String id = config.getInitParameter("log-id");

    if (id == null)
        id = "unknown";

    if (log != null && (request instanceof HttpServletRequest)) {

        req = (HttpServletRequest) request;
        log.info("Log id:" + id + ": Request received from: " + req.getRemoteHost() + " for "
                + req.getRequestURL());//from w ww.j a  v a  2s  . com
    }

    chain.doFilter(request, response);
}

From source file:net.longfalcon.web.LoginController.java

@RequestMapping(method = RequestMethod.POST)
public String loginPost(@ModelAttribute("loginVO") LoginVO loginVO, HttpServletRequest httpServletRequest,
        HttpSession httpSession, HttpServletResponse httpServletResponse, Model model) {
    String username = loginVO.getUsername();
    String password = loginVO.getPassword();
    String host = httpServletRequest.getRemoteHost();
    boolean rememberMe = loginVO.isRememberMe();
    loginVO.setPassword("");
    model.addAttribute("loginForm", loginVO);

    if (ValidatorUtil.isNull(username) || ValidatorUtil.isNull(password)) {
        model.addAttribute("error", "Please enter your username and password.");
        return "login";
    }//from   w w  w  . ja v  a  2  s  .  c  om

    User user = userDAO.findByUsername(username);

    if (user == null) {
        model.addAttribute("error", "Incorrect username or password.");
        return "login";
    }

    if (user.getRole() == UserService.ROLE_DISABLED) {
        model.addAttribute("error", "Your account has been disabled.");
        return "login";
    }

    String correctHash = user.getPassword();
    try {
        if (PasswordHash.validatePassword(password, correctHash)) {
            login(httpSession, httpServletResponse, host, rememberMe, user);
            String redirect = loginVO.getRedirect();
            if (ValidatorUtil.isNotNull(redirect)) {
                _log.error("I dont know if redirects work yet, redirect: " + redirect);
                // return "redirect:"+redirect;
            }
            model.asMap().clear();
            return "redirect:/";
        } else {
            model.addAttribute("error", "Incorrect username or password.");
        }
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        _log.error(e, e);
        model.addAttribute("error", "An Unexpected error has occurred.");

    }

    return "login";
}

From source file:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java

protected Boolean logRequest(HttpServletRequest request, Event event, Identifier pid) {
    request.getRemoteHost();
    LogEntry logEntry = new LogEntry();
    logEntry.setIpAddress(request.getRemoteAddr());

    logEntry.setUserAgent(request.getHeader("User-Agent"));

    logEntry.getNodeIdentifier();/* w w w. j  av  a 2  s. c  o  m*/
    Subject subject = new Subject();
    subject.setValue(org.dataone.service.util.Constants.SUBJECT_PUBLIC);
    logEntry.setSubject(subject);
    logEntry.setDateLogged(new Date());

    logEntry.setIdentifier(pid);

    getDataoneLogger().add(logEntry);
    return Boolean.TRUE;
}

From source file:org.dspace.statistics.util.SpiderDetectorServiceImpl.java

/**
 * Service Method for testing spiders against existing spider files.
 *
 * @param request//from   w w w  .  j  a va2s . c  o m
 * @return true|false if the request was detected to be from a spider.
 */
public boolean isSpider(HttpServletRequest request) {
    return isSpider(request.getRemoteAddr(), request.getHeader("X-Forwarded-For"), request.getRemoteHost(),
            request.getHeader("User-Agent"));
}

From source file:org.paxle.gui.impl.HttpAuthManager.java

public User autoLogin(final HttpServletRequest request) {
    User user = null;/*from  w  w  w.j  av  a2  s  . co  m*/

    final String[] autoLoginProperties = new String[] { "org.paxle.gui.autologin.user",
            "org.paxle.gui.autologin.user." + request.getRemoteHost(),
            "org.paxle.gui.autologin.user." + request.getRemoteAddr() };

    for (String autoLoginProperty : autoLoginProperties) {
        String autoLoginUser = System.getProperty(autoLoginProperty);
        if (autoLoginUser != null && autoLoginUser.length() > 0) {
            user = userAdmin.getUser(USER_HTTP_LOGIN, System.getProperty(autoLoginProperty));
            if (user != null)
                break;
        }
    }

    return user;
}