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:org.tsm.concharto.web.util.SessionHelper.java

private User makeAnonymousUser(HttpServletRequest request) {
    User user = new User();
    user.setUsername(request.getRemoteAddr());
    List<Role> roles = new ArrayList<Role>();
    roles.add(Role.ROLE_EDIT);//from   w ww  .ja  v a2 s. c  o m
    roles.add(Role.ROLE_ANONYMOUS);
    user.setRoles(roles);
    return user;
}

From source file:org.jasig.cas.adaptors.ldap.remote.RemoteAddressNonInteractiveCredentialsAction.java

protected Credentials constructCredentialsFromRequest(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final String remoteAddress = request.getRemoteAddr();

    if (StringUtils.hasText(remoteAddress)) {
        return new RemoteAddressCredentials(remoteAddress);
    }/*ww w .  j  a v a2 s  .  com*/

    logger.debug("No remote address found.");
    return null;
}

From source file:fr.univrouen.poste.web.ExceptionController.java

@RequestMapping("/denied")
public ModelAndView deniedHandler(HttpServletRequest request, HttpServletResponse response) {
    String ip = request.getRemoteAddr();
    log.warn("Access Denied for " + ip);
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    return new ModelAndView("accessDeniedException");
}

From source file:com.telefonica.iot.perseo.Utils.java

/**
 * Capture correlator and generate//from  ww w .j  a  va 2s.  c o  m
 *
 * @param req HttpServletRequest incomming request
 *
 */
public static void putCorrelatorAndTrans(HttpServletRequest req) {
    String correlatorId = req.getHeader(Constants.CORRELATOR_HEADER);
    String transId = UUID.randomUUID().toString();
    if (correlatorId == null) {
        correlatorId = transId;
    }
    MDC.put(Constants.TRANSACTION_ID, transId);
    MDC.put(Constants.CORRELATOR_ID, correlatorId);
    String service = req.getHeader(Constants.SERVICE_HEADER);
    if (service == null) {
        service = "?";
    }
    MDC.put(Constants.SERVICE_FIELD, service);

    String subservice = req.getHeader(Constants.SUBSERVICE_HEADER);
    if (subservice == null) {
        subservice = "?";
    }
    MDC.put(Constants.SUBSERVICE_FIELD, subservice);

    {
        String realIP = req.getHeader(Constants.REALIP_HEADER);

        if (realIP == null) {
            realIP = req.getRemoteAddr();
        }
        MDC.put(Constants.REALIP_FIELD, realIP);
    }

}

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

/**
 * Log message from client.//from w w  w .  j  a va 2 s  . 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:cn.bc.web.util.WebUtils.java

/**
 * ?IP??/* w w w . ja v a2  s . c o  m*/
 * 
 * @param request
 * @return
 */
public static String getClientIP(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");// apache?
    logger.debug("get clientIP by request.getHeader(\"x-forwarded-for\")");
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("Proxy-Client-IP");// ?
        logger.debug("get clientIP by request.getHeader(\"Proxy-Client-IP\")");
    }
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("WL-Proxy-Client-IP");// weblogic
        logger.debug("get clientIP by request.getHeader(\"WL-Proxy-Client-IP\")");
    }
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getRemoteAddr();// 
        logger.debug("get clientIP by request.getRemoteAddr()");
    }
    return ip;
}

From source file:eu.eidas.node.utils.EidasNodeErrorUtil.java

private static void prepareSamlResponseFailConnector(final HttpServletRequest request,
        AbstractEIDASException exc, IEIDASSession eidasSession) {
    ICONNECTORSAMLService connectorSamlService = ApplicationContextProvider.getApplicationContext()
            .getBean(ICONNECTORSAMLService.class);
    if (connectorSamlService == null) {
        return;/* ww  w .  j  a  va  2s  . c  om*/
    }
    String spUrl = getErrorReportingUrl(request, eidasSession);
    if (spUrl == null || !isErrorCodeAllowedForSamlGeneration(exc)) {
        LOG.info("ERROR : " + getEidasErrorMessage(exc, null));
        return;
    }
    byte[] samlToken = connectorSamlService.generateErrorAuthenticationResponse(getInResponseTo(request),
            getIssuer(request), spUrl.toString(), request.getRemoteAddr(), getSamlStatusCode(request),
            getSamlSubStatusCode(exc), exc.getErrorMessage());
    exc.setSamlTokenFail(EIDASUtil.encodeSAMLToken(samlToken));
    if (eidasSession != null) {
        eidasSession.put(EIDASParameters.ERROR_REDIRECT_URL.toString(), spUrl);
    }

}

From source file:org.dspace.app.cris.ws.WSTokenAuthService.java

@Override
protected Element invokeInternal(Element arg0) throws Exception {

    TransportContext context = TransportContextHolder.getTransportContext();
    HttpServletConnection connection = (HttpServletConnection) context.getConnection();
    HttpServletRequest request = connection.getHttpServletRequest();
    String ipAddress = request.getRemoteAddr();

    String token = tokenExpression.valueOf(arg0);
    String type = typeExpression.valueOf(arg0);
    type = type.trim();/*from w  w w .  j a  va  2  s .  c  o m*/
    User userWS = null;
    try {
        userWS = authenticationWS.authenticateToken(ipAddress, token);
    } catch (RuntimeException e) {
        throw new SOAPException(e.getMessage());
    }
    if (userWS == null) {
        throw new RuntimeException("User not found!");
    }

    if (!userWS.isEnabled()) {
        throw new RuntimeException("User disabled! Please Contact Admnistrator");
    }

    if (!AuthorizationWS.authorize(userWS, type)) {
        throw new SOAPException("User not allowed to retrieve those informations. Contact Administrator");
    }
    return buildResult(userWS, arg0, "TokenAuthQueryResponse");

}

From source file:io.fourfinanceit.homework.util.IpAddressDefiner.java

public String getIpAddress(HttpServletRequest request) {

    final String ipAddress = request.getHeader("X-FORWARDED-FOR");

    if (ipAddress == null) {
        return request.getRemoteAddr();
    }/* www.  j av a  2 s.c om*/

    return ipAddress;
}

From source file:it.jugpadova.controllers.ServiceController.java

@RequestMapping
public ModelAndView kml(HttpServletRequest req, HttpServletResponse res) throws Exception {
    logger.info("Requested kml from " + req.getRemoteAddr());
    Document doc = jugBo.buildKml();
    res.setHeader("Cache-Control", "no-store");
    res.setHeader("Pragma", "no-cache");
    res.setDateHeader("Expires", 0);
    res.setContentType("text/xml");
    ServletOutputStream resOutputStream = res.getOutputStream();
    Serializer serializer = new Serializer(resOutputStream);
    serializer.setIndent(4);//www.j  av a2  s  . c  om
    serializer.setMaxLength(64);
    serializer.setLineSeparator("\n");
    serializer.write(doc);
    resOutputStream.flush();
    resOutputStream.close();
    return null;
}