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:cz.incad.kramerius.security.impl.http.IsActionAllowedFromRequest.java

private String getRemoteHost() {
    HttpServletRequest httpReq = this.provider.get();
    return httpReq.getRemoteHost();
}

From source file:net.ljcomputing.core.controler.ClientLoggingController.java

/**
 * Log message from client.//w w w  . j ava 2s  .c  o  m
 *
 * @param request
 *            the request
 * @param logMessage
 *            the log message
 */
@LogEvent(level = Level.WARN, message = "Received logging message from client")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void logError(HttpServletRequest request, @RequestBody(required = true) LogMessage logMessage) {
    String ipAddress = request.getRemoteAddr();
    String hostname = request.getRemoteHost();
    logger.warn("Client-side log message ({}/{}) - using [{}] to request [{}]: {}", ipAddress, hostname,
            logMessage.getBrowser(), logMessage.getLocation(), logMessage.getPrintableMessage());
}

From source file:org.hidetake.opensocial.filter.extension.ValidationLogger.java

public void skipped(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    logger.info("Validation skipped: from=" + request.getRemoteHost() + " [" + request.getRemoteAddr() + "]");
}

From source file:com.sastix.cms.common.services.web.ExceptionHandlingController.java

@ExceptionHandler({ CommonException.class })
public void handleBadRequests(HttpServletRequest request, HttpServletResponse response, Exception e)
        throws IOException {
    LOG.error("Bad request: {} from {}, Exception: {} {}", request.getRequestURI(), request.getRemoteHost(),
            e.getStackTrace()[0].toString(), e.getLocalizedMessage());

    response.sendError(HttpStatus.BAD_REQUEST.value(), e.getLocalizedMessage());
}

From source file:org.apache.atlas.web.filters.AuditFilter.java

private void recordAudit(HttpServletRequest httpRequest, String whenISO9601, String who) {
    final String fromHost = httpRequest.getRemoteHost();
    final String fromAddress = httpRequest.getRemoteAddr();
    final String whatRequest = httpRequest.getMethod();
    final String whatURL = Servlets.getRequestURL(httpRequest);
    final String whatAddrs = httpRequest.getLocalAddr();

    final String whatUrlPath = httpRequest.getRequestURL().toString();//url path without query string

    if (!isOperationExcludedFromAudit(whatRequest, whatUrlPath.toLowerCase(), null)) {
        audit(who, fromAddress, whatRequest, fromHost, whatURL, whatAddrs, whenISO9601);
    } else {//from  ww w  .  java 2  s.c o  m
        if (LOG.isDebugEnabled()) {
            LOG.debug(" Skipping Audit for {} ", whatURL);
        }
    }
}

From source file:org.sakaiproject.webservices.interceptor.RemoteHostMatcher.java

/**
 * Is this HTTP request allowed based on the remote host and the configured allows/denied properties.
 * @param request The HTTP request./*from   w ww .  ja  v  a  2 s.c  om*/
 * @return <code>true</code> if we should allow access.
 */
public boolean isAllowed(HttpServletRequest request) {

    String host = request.getRemoteHost();
    String addr = request.getRemoteAddr();

    // Check requests that are always allowed ...
    String uri = request.getRequestURI();
    for (String allowedUri : allowRequests) {
        if (StringUtils.startsWith(uri, allowedUri)) {
            if (logAllowed)
                log.info("Access granted for request ({}): {}/{}", uri, host, addr);
            return true;
        }
    }

    // Check if explicit denied ...
    for (Pattern pattern : denyPattern) {
        if (pattern.matcher(host).matches() || pattern.matcher(addr).matches()) {
            if (logDenied)
                log.info("Access denied ({}): {}/{}", pattern.pattern(), host, addr);
            return false;
        }
    }

    // Check if explicitly allowed ...
    for (Pattern pattern : allowPattern) {
        if (pattern.matcher(host).matches() || pattern.matcher(addr).matches()) {
            if (logAllowed)
                log.info("Access granted ({}): {}/{}", pattern.pattern(), host, addr);
            return true;
        }
    }

    // Allow if allows is null, but denied is not
    if ((!denyPattern.isEmpty()) && (allowPattern.isEmpty())) {
        if (logAllowed)
            log.info("Access granted (implicit): {}/{}", host, addr);
        return true;
    }

    // Deny this request
    if (logDenied)
        log.info("Access denied (implicit): {}/{}", host, addr);
    return false;
}

From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java

public void testRequestPropertiesToMapWhenAccessingPropertyThrowsExceptionSuppressesException()
        throws Exception {
    HttpServletRequest mockRequest = EasyMock.createNiceMock(HttpServletRequest.class);
    expect(mockRequest.getRemoteHost()).andThrow(new IllegalStateException("I forgot"));
    EasyMock.replay(mockRequest);/*from   ww  w. j av  a 2s  .  c  o  m*/

    Map<String, Object> actual = WebTools.requestPropertiesToMap(mockRequest);
    assertTrue(actual.get("remoteHost") instanceof IllegalStateException);
}

From source file:org.geoserver.filters.LoggingFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    String message = "";
    String body = null;/*from www.  j a v  a2  s .c  om*/
    String path = "";

    if (enabled) {
        if (req instanceof HttpServletRequest) {
            HttpServletRequest hreq = (HttpServletRequest) req;

            path = hreq.getRemoteHost() + " \"" + hreq.getMethod() + " " + hreq.getRequestURI();
            if (hreq.getQueryString() != null) {
                path += "?" + hreq.getQueryString();
            }
            path += "\"";

            message = "" + path;
            message += " \"" + noNull(hreq.getHeader("User-Agent"));
            message += "\" \"" + noNull(hreq.getHeader("Referer")) + "\" ";
            message += "\" \"" + noNull(hreq.getHeader("Content-type")) + "\" ";

            if (logBodies && (hreq.getMethod().equals("PUT") || hreq.getMethod().equals("POST"))) {
                message += " request-size: " + hreq.getContentLength();
                message += " body: ";

                String encoding = hreq.getCharacterEncoding();
                if (encoding == null) {
                    // the default encoding for HTTP 1.1
                    encoding = "ISO-8859-1";
                }
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] bytes;
                try (InputStream is = hreq.getInputStream()) {
                    IOUtils.copy(is, bos);
                    bytes = bos.toByteArray();

                    body = new String(bytes, encoding);
                }

                req = new BufferedRequestWrapper(hreq, encoding, bytes);
            }
        } else {
            message = "" + req.getRemoteHost() + " made a non-HTTP request";
        }

        logger.info(message + (body == null ? "" : "\n" + body + "\n"));
        long startTime = System.currentTimeMillis();
        chain.doFilter(req, res);
        long requestTime = System.currentTimeMillis() - startTime;
        logger.info(path + " took " + requestTime + "ms");
    } else {
        chain.doFilter(req, res);
    }

}

From source file:br.com.munif.personalsecurity.aplicacao.autorizacao.Autorizador.java

protected void methodNotAllowed(HttpServletRequest request, HttpServletResponse response) throws IOException {
    System.out.println("---->methodNotAllowed from " + request.getRemoteHost());
    response.setStatus(HttpStatus.SC_METHOD_NOT_ALLOWED);
    response.setContentType("application/json;charset=UTF-8");
    mapper.writeValue(response.getOutputStream(), "Mtodo no permitido");
}

From source file:io.hops.hopsworks.common.dao.user.security.audit.AccountAuditFacade.java

/**
 * Register account related changes.//  w w w  .jav a  2 s.  c om
 *
 * @param init
 * @param action
 * @param outcome
 * @param message
 * @param target
 * @param req
 */
public void registerAccountChange(Users init, String action, String outcome, String message, Users target,
        HttpServletRequest req) {
    AccountAudit accountAudit = new AccountAudit(action, new Date(), message, outcome, req.getRemoteHost(),
            extractUserAgent(req), target, init);
    em.persist(accountAudit);
}