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.cfitzarl.cfjwed.controller.AccountController.java

/**
 * This API provides account-specific information to the UI after a page refresh.
 *
 * @param request//from   w  w w. j  a v a2 s  .  c  o  m
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/data", method = RequestMethod.GET)
public AuthenticationDTO getAuthenticationDetails(HttpServletRequest request) throws Exception {
    String authToken = request.getHeader(SessionConstant.AUTH_TOKEN_HEADER);

    if (authToken != null) {
        String serializedAuthData = redisService.get(authToken);

        if (serializedAuthData != null) {
            return new ObjectMapper().readValue(serializedAuthData, AuthenticationDTO.class);
        }
    }

    throw new UnauthorizedException("Could not find token");
}

From source file:cn.vlabs.clb.api.io.impl.ServletOutputStream.java

public ServletOutputStream(HttpServletRequest request, HttpServletResponse response) {
    this.agent = request.getHeader("user-agent");
    String range = request.getHeader("range");
    if (range != null) {
        try {/*  w  ww  .  j  a  va 2 s .co m*/
            this.startPos = Long.parseLong(range.substring(6, range.length() - 1));
        } catch (NumberFormatException e) {

        }
    }
    this.response = response;
    response.setHeader("Pragma", "");
    response.setHeader("Cache-Control", "");
}

From source file:com.jevontech.wabl.security.AuthenticationTokenFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    //log.debug("doFilter");

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String authToken = httpRequest.getHeader(this.tokenHeader);
    String username = this.tokenUtils.getUsernameFromToken(authToken);

    log.debug("doFilter: this.tokenHeader=" + this.tokenHeader);

    log.debug("doFilter: authToken=" + authToken + " , username=" + username);

    if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
        UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);

        log.debug("doFilter: userDetails=" + userDetails.toString());
        if (this.tokenUtils.validateToken(authToken, userDetails)) {
            UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
                    userDetails, null, userDetails.getAuthorities());
            authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpRequest));
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }//from w  ww  .j  a  v a 2 s  . c o  m
    }

    chain.doFilter(request, response);
}

From source file:org.esigate.servlet.impl.HttpServletRequestEntity.java

HttpServletRequestEntity(HttpServletRequest request) {
    this.request = request;
    String contentLengthHeader = request.getHeader(HttpHeaders.CONTENT_LENGTH);
    if (contentLengthHeader != null) {
        length = Long.parseLong(contentLengthHeader);
    } else {/*from www .ja v a2 s .c  om*/
        length = -1;
    }
    String contentTypeHeader = request.getContentType();
    if (contentTypeHeader != null) {
        this.setContentType(contentTypeHeader);
    }
    String contentEncodingHeader = request.getCharacterEncoding();
    if (contentEncodingHeader != null) {
        this.setContentEncoding(contentEncodingHeader);
    }

}

From source file:de.mpg.imeji.logic.auth.authentication.HttpAuthentication.java

/**
 * Utility method to read the username and password in the {@link HttpServletRequest} (separated by a colon).
 * //from w  w w  . j  ava  2s . co  m
 * @param request
 * @return The username and password combination
 */
private String getUsernamePassword(HttpServletRequest request) {
    String authHeader = request.getHeader("Authorization");
    if (authHeader != null) {
        String userPass = new String(Base64.decodeBase64(authHeader.getBytes()));
        return userPass;
    }
    return null;
}

From source file:com.poscoict.license.web.controller.DownloadView.java

private String getBrowser(HttpServletRequest request) {

    String header = request.getHeader("User-Agent");

    if (header.contains("MSIE")) {

        return "MSIE";

    } else if (header.contains("Chrome")) {

        return "Chrome";

    } else if (header.contains("Opera")) {

        return "Opera";

    }/*  www.  jav a  2  s.c  om*/

    return "Firefox";

}

From source file:org.commonjava.indy.bind.jaxrs.MDCManager.java

public void putExtraHeaders(HttpServletRequest request) {
    mdcHeadersList.forEach((header) -> MDC.put(header, request.getHeader(header)));
}

From source file:cf.spring.HttpBasicAuthenticator.java

public boolean authenticate(HttpServletRequest request, HttpServletResponse response) {
    final String authorization = request.getHeader("Authorization");
    if (authorization == null) {
        setUnathorizedResponse(response);
        return false;
    }//w w w .ja va  2  s  .c om
    final String[] split = authorization.trim().split("\\s+");

    if (!split[0].equalsIgnoreCase("Basic") || split.length != 2) {
        setUnathorizedResponse(response);
        return false;
    }

    final String[] credentials = parseCredentials(split[1]);

    if (!user.equals(credentials[0]) || !password.equals(credentials[1])) {
        setUnathorizedResponse(response);
        return false;
    }

    return true;
}

From source file:com.github.alinvasile.jsla.web.authority.AuthorizationHeaderAuthorityProvider.java

public Authority retrieveAuthority(ServletRequest request) {

    String user = null;//  ww  w.j a v  a2  s.  co m

    if (request instanceof HttpServletRequest) {

        if (logger.isDebugEnabled()) {
            logger.debug("retrieveAuthority");
        }

        HttpServletRequest httpServletRequest = (HttpServletRequest) request;

        String authHeader = httpServletRequest.getHeader("authorization");
        if (authHeader != null) {
            String encodedValue = authHeader.split(" ")[1];
            byte[] decodedValue = Base64.decodeBase64(encodedValue.getBytes());

            user = new String(decodedValue);

            user = user.split(":")[0];

            if (logger.isDebugEnabled()) {
                logger.debug("Found user: " + user);
            }

            return DefaultAuthorityUser.createUsernameOnlyUser(user);
        }

    }

    return DefaultAuthorityUser.createAnonymousUser();
}

From source file:net.prasenjit.auth.config.CustomAjaxAwareHandler.java

private boolean checkIfAjaxRequest(HttpServletRequest request) {
    String requestedWith = request.getHeader("X-Requested-With");
    return StringUtils.hasText(requestedWith);
}