Example usage for javax.servlet.http HttpServletRequest getHeader

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

Introduction

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

Prototype

public String getHeader(String name);

Source Link

Document

Returns the value of the specified request header as a String.

Usage

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 a2  s.  c  om*/

    return ipAddress;
}

From source file:com.surevine.alfresco.audit.listeners.PostAuditEventListener.java

/**
 * Assumes that the post content was a JSON string.
 *
 * @param postContent/*w  ww.  ja  v a 2  s  .c  o  m*/
 *            from the request
 * @return valid JSONObject, otherwise null
 */
public static JSONObject parseJSONFromPostContent(final HttpServletRequest request) {

    if (request.getAttribute(REQUEST_ATTRIBUTE_JSON) != null) {
        return (JSONObject) request.getAttribute(REQUEST_ATTRIBUTE_JSON);
    }

    JSONObject retVal = null;

    InputStream inStream;
    try {
        inStream = request.getInputStream();
    } catch (IOException eIO) {
        logger.error("Error encountered while reading from the request stream", eIO);
        return null;
    }

    InputStreamReader reader = new InputStreamReader(inStream);
    JSONTokener tokenizer = new JSONTokener(reader);

    try {
        retVal = new JSONObject(tokenizer);
    } catch (JSONException e) {
        // We will only warn in the logs if it was supposed to be JSON
        if ("application/json".equals(request.getHeader("Content-Type"))) {
            try {
                logger.warn("Invalid JSON string parsed from post content "
                        + IOUtils.toString(request.getInputStream()), e);
            } catch (IOException e1) {
                logger.error("IOException caught parsing request stream", e1);
            }
        }
    }

    request.setAttribute(REQUEST_ATTRIBUTE_JSON, retVal);

    return retVal;
}

From source file:de.metas.ui.web.login.LoginRestController.java

private static MSession createMSession(final Login loginService) {
    final HttpServletRequest httpRequest = ((ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes()).getRequest();
    final HttpSession httpSess = httpRequest.getSession();
    final String webSessionId = httpSess.getId();
    ///* ww w .j  a  v a 2s .  c  om*/
    // final WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    String remoteAddr = httpRequest.getRemoteAddr();
    String remoteHost = httpRequest.getRemoteHost();

    //
    // Check if we are behind proxy and if yes, get the actual client IP address
    // NOTE: when configuring apache, don't forget to activate reverse-proxy mode
    // see http://www.xinotes.org/notes/note/770/
    final String forwardedFor = httpRequest.getHeader("X-Forwarded-For");
    if (!Check.isEmpty(forwardedFor)) {
        remoteAddr = forwardedFor;
        remoteHost = forwardedFor;
    }

    final LoginContext ctx = loginService.getCtx();
    final MSession sessionPO = MSession.get(ctx.getSessionContext(), remoteAddr, remoteHost, webSessionId);

    // Set HostKey
    // FIXME: commented out because this one is not working when running over websockets (i.e. HttpServletResponse does not exists)
    // see https://dev.vaadin.com/ticket/11808
    // @formatter:off
    //      final I_AD_Session session = InterfaceWrapperHelper.create(sessionPO, I_AD_Session.class);
    //      HttpCookieHostKeyStorage.createUpdateHostKey();
    //      final String hostKey = hostKeyBL.getHostKey();
    //      session.setHostKey(hostKey);
    //      InterfaceWrapperHelper.save(session);
    // @formatter:on

    // Update Login helper
    loginService.setRemoteAddr(remoteAddr);
    loginService.setRemoteHost(remoteHost);
    loginService.setWebSession(webSessionId);

    return sessionPO;
}

From source file:eu.trentorise.smartcampus.ac.provider.filters.AcProviderFilter.java

@Override
protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) {
    String s = request.getHeader(principalRequestHeader);
    return s;/*from  w  w w  . jav a2  s.c  o m*/
}

From source file:eu.trentorise.smartcampus.ac.provider.filters.AcProviderFilter.java

@Override
protected Object getPreAuthenticatedCredentials(HttpServletRequest request) {
    String s = request.getHeader(principalRequestHeader);
    return s;// w ww  .  java  2s. c o m
}

From source file:com.github.achatain.nopasswordauthentication.utils.AuthorizedServlet.java

protected String extractApiToken(HttpServletRequest req) {
    String authorization = req.getHeader(HttpHeaders.AUTHORIZATION);
    Preconditions.checkArgument(authorization != null, "Missing authorization header");

    String apiToken = StringUtils.removeStartIgnoreCase(authorization, BEARER_PREFIX);
    Preconditions.checkArgument(StringUtils.isNotBlank(apiToken), "Missing api token");

    return StringUtils.trim(apiToken);
}

From source file:com.dub.skoolie.web.controller.system.schedule.events.SystemDistrictEventController.java

@RequestMapping(value = "/system/schedule/events/district", method = RequestMethod.POST)
public ModelAndView addDistrictEvent(@Valid DistrictEventBean districtEventBean, BindingResult result,
        Model model, HttpServletRequest request) {
    String referrer = request.getHeader("Referer");
    if (result.hasErrors()) {
        if (!referrer.equals("/system/schedule/events/district")) {
            return new ModelAndView("redirect:" + referrer);
        }/*from   w w w . jav  a  2  s . c  o m*/
        return new ModelAndView("system/schedule/events/index");
    }
    uiDistrictEventServiceImpl.addDistrictEvent(districtEventBean);
    return new ModelAndView("system/schedule/events/index");
}

From source file:com.dub.skoolie.web.controller.system.schedule.events.SystemUserEventController.java

@RequestMapping(value = "/system/schedule/events/user", method = RequestMethod.POST)
public ModelAndView addUserEvent(@Valid UserEventBean userEventBean, BindingResult result, Model model,
        HttpServletRequest request) {
    String referrer = request.getHeader("Referer");
    if (result.hasErrors()) {
        if (!referrer.equals("/system/schedule/events/user")) {
            return new ModelAndView("redirect:" + referrer);
        }/*from  w  ww  .j  av  a 2  s.  co  m*/
        return new ModelAndView("system/schedule/events/index");
    }
    uiUserEventServiceImpl.addUserEvent(userEventBean);
    return new ModelAndView("system/schedule/events/index");
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.Logout.java

private String getReferringPage(HttpServletRequest request) {
    String referrer = request.getHeader(HEADING_REFERRER);
    if (referrer == null) {
        referrer = "/.";
    }/*w  ww . ja v a2 s.co m*/
    log.debug("Referring page is '" + referrer + "'");
    return referrer;
}

From source file:eu.supersede.fe.security.AuthenticationSuccessListener.java

@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    DatabaseUser userDetails = (DatabaseUser) event.getAuthentication().getPrincipal();

    HttpServletRequest req = attr.getRequest();
    String multiTenantId = req.getHeader("TenantId");
    userDetails.setTenantId(multiTenantId);
}