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:com.hobba.hobaserver.services.security.ChallengeUtil.java

private String getKID(HttpServletRequest request) {
    String header = request.getHeader("Authorized");
    String[] headerParams = header.split("[.]");
    String kid = headerParams[0];
    return kid;//w w w. ja  v  a 2 s .c om

}

From source file:org.ameba.http.RequestIDFilter.java

/**
 * {@inheritDoc}/*w w w .  j  a v a  2  s . c  om*/
 */
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    if (request.getHeader(Constants.HEADER_VALUE_X_REQUESTID) == null) {
        RequestIDHolder.setRequestID(generator.generate());
    } else {
        RequestIDHolder.setRequestID(request.getHeader(Constants.HEADER_VALUE_X_REQUESTID));
    }
    try {
        filterChain.doFilter(request, response);
    } finally {
        RequestIDHolder.destroy();
    }
}

From source file:net.sourceforge.vulcan.web.ContentTypeFilter.java

private String detectContentType(HttpServletRequest request) {
    final String userAgent = request.getHeader(HEADER_USER_AGENT);

    if (!StringUtils.isBlank(userAgent)) {
        final Matcher matcher = userAgentRegex.matcher(userAgent);

        if (matcher.matches()) {
            request.setAttribute(Keys.BROWSER_IE, Boolean.TRUE);
            return legacyContentType;
        }/*from   www .  j a v a  2  s. c  o  m*/
    }

    return defaultContentType;
}

From source file:com.hobba.hobaserver.services.security.ChallengeUtil.java

private String getSignature(HttpServletRequest request) {
    String header = request.getHeader("Authorized");
    String[] headerParams = header.split("[.]");
    String signBase64 = headerParams[3];

    byte[] decodedToken = Base64.decodeBase64(signBase64.getBytes());
    String decodedSign = new String(decodedToken);
    return decodedSign;
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String referer = request.getHeader("Referer");
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old)) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old, "/" + current);
    }//  ww  w  .  j  av a  2s  .  c  om
    return REDIRECT_PREFIX + '/';
}

From source file:com.github.wxiaoqi.gate.ratelimit.filters.RateLimitFilter.java

private String getRemoteAddr(final HttpServletRequest request) {
    if (properties.isBehindProxy() && request.getHeader(HttpHeaders.X_FORWARDED_FOR) != null) {
        return request.getHeader(HttpHeaders.X_FORWARDED_FOR);
    }/*from  w  ww.j  a  v a2 s  .  co  m*/
    return request.getRemoteAddr();
}

From source file:com.naver.timetable.controller.CommentController.java

@RequestMapping(value = "delete")
public ModelAndView deleteComment(HttpServletRequest request, Comment comment) {
    commentBO.deleteComment(comment);//from   w  w  w  . j a  v a 2 s . co m

    return new ModelAndView("redirect:" + request.getHeader("Referer"));
}

From source file:org.owasp.webgoat.plugin.HttpBasicsInterceptRequest.java

@RequestMapping(method = RequestMethod.GET)
public @ResponseBody AttackResult completed(HttpServletRequest request) throws IOException {
    String header = null;//from   w ww.  j a  va  2 s. co  m
    String param = null;
    if (request != null && (header = request.getHeader("x-request-intercepted")) != null
            && header.toLowerCase().equals("true") && (param = request.getParameter("changeMe")) != null
            && param.equals("Requests are tampered easily")) {
        return trackProgress(success().feedback("http-proxies.intercept.success").build());
    } else {
        return trackProgress(failed().feedback("http-proxies.intercept.failure").build());
    }
}

From source file:com.ixortalk.aws.cognito.boot.filter.AwsCognitoIdTokenProcessor.java

public Authentication getAuthentication(HttpServletRequest request) throws Exception {

    String idToken = request.getHeader(jwtConfiguration.getHttpHeader());
    if (idToken != null) {

        JWTClaimsSet claimsSet = null;/* w  w w .  j  av a2 s.c o m*/

        claimsSet = configurableJWTProcessor.process(stripBearerToken(idToken), null);

        if (!isIssuedCorrectly(claimsSet)) {
            throw new Exception(String.format("Issuer %s in JWT token doesn't match cognito idp %s",
                    claimsSet.getIssuer(), jwtConfiguration.getCognitoIdentityPoolUrl()));
        }

        if (!isIdToken(claimsSet)) {
            throw new Exception("JWT Token doesn't seem to be an ID Token");
        }

        String username = claimsSet.getClaims().get(jwtConfiguration.getUserNameField()).toString();

        if (username != null) {

            List<String> groups = (List<String>) claimsSet.getClaims().get(jwtConfiguration.getGroupsField());
            List<GrantedAuthority> grantedAuthorities = convertList(groups,
                    group -> new SimpleGrantedAuthority(ROLE_PREFIX + group.toUpperCase()));
            User user = new User(username, EMPTY_PWD, grantedAuthorities);

            jwtIdTokenCredentialsHolder.setIdToken(stripBearerToken(idToken));
            return new JwtAuthentication(user, claimsSet, grantedAuthorities);
        }

    }

    logger.trace("No idToken found in HTTP Header");
    return null;
}

From source file:ch.entwine.weblounge.common.impl.language.LanguageUtils.java

/**
 * Returns the preferred one out of of those languages that are requested by
 * the client through the <code>Accept-Language</code> header and are
 * supported by both the resource in that there is resource content in that
 * language and the site.//from   w  w w  .  j a  v a2 s . c  o m
 * <p>
 * The preferred one is defined by the following priorities:
 * <ul>
 * <li>Requested by the client</li>
 * <li>The resource's original language</li>
 * <li>The site default language</li>
 * <li>The first language of what is supported by both the resource and the
 * site</li>
 * </ul>
 * 
 * @param resource
 *          the resource
 * @param request
 *          the http request
 * @param site
 *          the site
 */
public static Language getPreferredContentLanguage(Resource<?> resource, HttpServletRequest request,
        Site site) {

    if (resource == null)
        throw new IllegalArgumentException("Resource must not be null");

    // Path
    String[] pathElements = StringUtils.split(request.getRequestURI(), "/");
    for (String element : pathElements) {
        for (Language l : resource.contentLanguages()) {
            if (l.getIdentifier().equals(element)) {
                return l;
            }
        }
    }

    // Accept-Language header
    if (request.getHeader("Accept-Language") != null) {
        Enumeration<?> locales = request.getLocales();
        while (locales.hasMoreElements()) {
            try {
                Language l = getLanguage((Locale) locales.nextElement());
                if (l == null)
                    continue;
                if (!resource.supportsContentLanguage(l))
                    continue;
                if (!site.supportsLanguage(l))
                    continue;
                return l;
            } catch (UnknownLanguageException e) {
                // never mind, some clients will send stuff like "*" as the locale
            }
        }
    }

    // Original content
    if (resource.getOriginalContent() != null) {
        if (site.supportsLanguage(resource.getOriginalContent().getLanguage()))
            return resource.getOriginalContent().getLanguage();
    }

    // Site default language
    if (resource.supportsContentLanguage(site.getDefaultLanguage())) {
        return site.getDefaultLanguage();
    }

    // Any match
    for (Language l : site.getLanguages()) {
        if (resource.supportsContentLanguage(l)) {
            return l;
        }
    }

    return null;
}