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.epam.dlab.auth.azure.AzureAuthenticationResource.java

/**
 * Returns user info that is mapped with <code>accessToken</code>
 *
 * @param accessToken input access token
 * @param request     http request/*from  w ww.  java2  s  .  c o m*/
 * @return user info
 */
@Override
@Path(SecurityAPI.GET_USER_INFO)
@POST
public UserInfo getUserInfo(String accessToken, @Context HttpServletRequest request) {
    String remoteIp = request.getRemoteAddr();

    UserInfo ui = userInfoDao.getUserInfoByAccessToken(accessToken);

    if (ui != null) {
        ui = ui.withToken(accessToken);
        userInfoDao.updateUserInfoTTL(accessToken, ui);
        log.debug("restored UserInfo from DB {}", ui);
    }

    log.debug("Authorized {} {} {}", accessToken, ui, remoteIp);
    return ui;
}

From source file:mp.platform.cyclone.webservices.AuthInterceptor.java

/**
 * Find a matching {@link ServiceClient} for the given request
 *//*  w  w  w.  j a  v a2s. co  m*/
private ServiceClient resolveClient(final HttpServletRequest request) {
    final String address = request.getRemoteAddr();
    String[] credentials = RequestHelper.getCredentials(request);
    if (credentials == null) {
        credentials = BLANK_CREDENTIALS;
    }
    try {
        return serviceClientService.findByAddressAndCredentials(address, credentials[0], credentials[1]);
    } catch (final EntityNotFoundException e) {

        return null;
    }
}

From source file:simplestorage.controllers.HashtableController.java

@RequestMapping(value = "/hashtable/{key}/{value}")
public ModelAndView put(HttpServletRequest request, HttpServletResponse response, @PathVariable String key,
        @PathVariable String value) throws IOException {
    String userInfo = request.getRemoteAddr();
    hashtableSvc.put(key, value, userInfo);
    return constructModelAndView(gson.toJson(Boolean.TRUE));
}

From source file:org.dspace.google.GoogleRecorderEventListener.java

private String getIPAddress(HttpServletRequest request) {
    String clientIP = request.getRemoteAddr();
    if (ConfigurationManager.getBooleanProperty("useProxies", false)
            && request.getHeader("X-Forwarded-For") != null) {
        /* This header is a comma delimited list */
        for (String xfip : request.getHeader("X-Forwarded-For").split(",")) {
            /* proxy itself will sometime populate this header with the same value in
            remote address. ordering in spec is vague, we'll just take the last
            not equal to the proxy/*from  www  .  ja  va 2 s  .  c o m*/
            */
            if (!request.getHeader("X-Forwarded-For").contains(clientIP)) {
                clientIP = xfip.trim();
            }
        }
    }

    return clientIP;
}

From source file:com.googlecode.psiprobe.controllers.apps.AjaxReloadContextController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    if (!request.getContextPath().equals(contextName) && context != null) {
        try {/*from  w  w  w .  j  a  v a 2 s. co m*/
            logger.info(request.getRemoteAddr() + " requested RELOAD of " + contextName);
            context.reload();
        } catch (Throwable e) {
            logger.error(e);
            //
            // make sure we always re-throw ThreadDeath
            //
            if (e instanceof ThreadDeath) {
                throw (ThreadDeath) e;
            }
        }
    }
    return new ModelAndView(getViewName(), "available", Boolean
            .valueOf(context != null && getContainerWrapper().getTomcatContainer().getAvailable(context)));
}

From source file:com.livgrhm.kansas.resources.UserResource.java

@GET
@Timed//from  w ww  .  j  av  a 2s.c  o  m
public Response getUsers(@QueryParam("auth") String auth, @Context HttpServletRequest req) {
    if (!authMap.isAuthorised(auth, req.getRemoteAddr())) {
        System.out.println("getUser Unauthorised " + auth);
        SimpleResponse resp = new SimpleResponse(401, "Unauthorized", "Authorization is required.");
        return Response.status(Response.Status.UNAUTHORIZED).entity(resp).build();
    }
    try {
        List<User> list = this.dao.getUsers();
        if (list.size() > 0) {
            return Response.ok(list).build();
        }
        return Response.status(Response.Status.NOT_FOUND).build();
    } catch (Exception e) {
        System.out.println("Exception getting all users: " + e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:net.testdriven.psiprobe.controllers.apps.AjaxReloadContextController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    if (!request.getContextPath().equals(contextName) && context != null) {
        try {//w w  w.  j av  a 2s  .c o  m
            logger.info(request.getRemoteAddr() + " requested RELOAD of " + contextName);
            context.reload();
        } catch (Throwable e) {
            logger.error(e);
            //
            // make sure we always re-throw ThreadDeath
            //
            if (e instanceof ThreadDeath) {
                throw (ThreadDeath) e;
            }
        }
    }
    return new ModelAndView(getViewName(), "available",
            Boolean.valueOf(context != null && context.getAvailable()));
}

From source file:com.livgrhm.kansas.resources.UserResource.java

@DELETE
@Path("/{userId}")
@Timed//w  w  w  .j a v  a2  s . c o m
public Response deleteUser(@PathParam("userId") int userId, @QueryParam("auth") String auth,
        @Context HttpServletRequest req) {
    if (!authMap.isAuthorised(auth, req.getRemoteAddr())) {
        System.out.println("deleteUser Unauthorised " + auth);
        SimpleResponse resp = new SimpleResponse(401, "Unauthorized", "Authorization is required.");
        return Response.status(Response.Status.UNAUTHORIZED).entity(resp).build();
    }
    try {
        this.dao.deleteUser(userId);
        // create an ok response object
        SimpleResponse resp = new SimpleResponse(200, "OK", "User successfully deleted.");
        return Response.status(Response.Status.OK).entity(resp).build();
    } catch (Exception e) {
        System.out.println("Exception deleting user: " + e.getMessage());
        return Response.status(Response.Status.NOT_IMPLEMENTED).build();
    }
}

From source file:com.livgrhm.kansas.resources.UserResource.java

@GET
@Path("email/{email}")
@Timed/*from ww w.j  a va2 s  .co m*/
public Response getUserByEmail(@PathParam("email") String email, @QueryParam("auth") String auth,
        @Context HttpServletRequest req) {
    if (!authMap.isAuthorised(auth, req.getRemoteAddr())) {
        System.out.println("getUserByEmail Unauthorised " + email + " " + auth);
        SimpleResponse resp = new SimpleResponse(401, "Unauthorized", "Authorization is required.");
        return Response.status(Response.Status.UNAUTHORIZED).entity(resp).build();
    }
    try {
        User u = this.dao.getUserByEmail(email);
        if (u != null) {
            return Response.ok(u).build();
        }
        return Response.status(Response.Status.NOT_FOUND).build();
    } catch (Exception e) {
        System.out.println("Exception getting user by email: " + e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:org.killbill.billing.plugin.analytics.http.BaseServlet.java

protected CallContext createCallContext(final HttpServletRequest req, final HttpServletResponse resp)
        throws IOException {
    final String createdBy = Objects.firstNonNull(req.getHeader(HDR_CREATED_BY), req.getRemoteAddr());
    final String reason = req.getHeader(HDR_REASON);
    final String comment = Objects.firstNonNull(req.getHeader(HDR_COMMENT), req.getRequestURI());

    // Set by the TenantFilter
    final Tenant tenant = (Tenant) req.getAttribute("killbill_tenant");

    UUID tenantId = null;//w w w.j  av a2 s .c  om
    if (tenant != null) {
        tenantId = tenant.getId();
    }
    return new AnalyticsApiCallContext(createdBy, reason, comment, tenantId);
}