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.ksa.myanmarlottery.controller.ResultController.java

private String getRemoteAddress(HttpServletRequest request) {
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    }// w  w  w.j a  v  a  2 s . c om
    log.debug("Remote Address " + request.getRemoteAddr());
    return ipAddress;
}

From source file:com.epam.reportportal.auth.event.UiAuthenticationFailureEventHandler.java

private String getClientIP(HttpServletRequest request) {
    String xfHeader = request.getHeader(HttpHeaders.X_FORWARDED_FOR);
    if (xfHeader == null) {
        return request.getRemoteAddr();
    }/*w ww .  j a  v a 2  s.  co m*/
    return xfHeader.split(",")[0];
}

From source file:ch.ge.ve.protopoc.controller.impl.AuthenticationController.java

@Override
public ResponseEntity<?> renewAuthenticationToken(HttpServletRequest request) {
    String token = request.getHeader(tokenHeader);

    if (jwtTokenUtil.canTokenBeRefreshed(token)) {
        String refreshedToken = jwtTokenUtil.refreshToken(token);
        return ResponseEntity.ok(new JwtAuthenticationResponse(refreshedToken));
    } else {/* w w w .j  a  va2 s  .c  o m*/
        return ResponseEntity.badRequest().body(null);
    }
}

From source file:org.cloudfoundry.identity.uaa.web.ForwardAwareInternalResourceViewResolver.java

private MediaType getMediaTypes(HttpServletRequest request) {
    String acceptHeader = request.getHeader(ACCEPT_HEADER);
    if (StringUtils.hasText(acceptHeader)) {
        try {/* w  ww . ja  va  2  s .  co  m*/
            List<MediaType> acceptableMediaTypes = MediaType.parseMediaTypes(acceptHeader);
            return acceptableMediaTypes.isEmpty() ? null : acceptableMediaTypes.get(0);
        } catch (IllegalArgumentException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not parse accept header [" + acceptHeader + "]: " + ex.getMessage());
            }
            return null;
        }
    }
    return null;
}

From source file:com.todo.backend.security.JWTFilter.java

private Optional<String> extractToken(HttpServletRequest request) {
    final String bearerToken = request.getHeader(AUTHORIZATION);
    if (StringUtils.hasText(bearerToken) && bearerToken.startsWith(BEARER)) {
        final String jwtToken = bearerToken.substring(BEARER.length(), bearerToken.length());
        return Optional.of(jwtToken);
    }//  w w w .j  av a2 s.c  o  m
    return Optional.empty();
}

From source file:com.phone.cn.web.action.BaseAppController.java

public String getRemoteHost(javax.servlet.http.HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }/*from   ww  w  .j  a v a2s.co  m*/
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;
}

From source file:jp.co.opentone.bsol.framework.web.filter.GZipFilter.java

private boolean isCompressionSupported(HttpServletRequest request) {
    String acceptEncoding = request.getHeader("accept-encoding");
    return StringUtils.isNotEmpty(acceptEncoding) && acceptEncoding.contains("gzip");
}

From source file:org.esupportail.cas.audit.support.ServiceAuditTrailManager.java

public void record(final AuditActionContext auditActionContext) {

    if (("SERVICE_TICKET_CREATED").equals(auditActionContext.getActionPerformed())) {

        String resourceOperatedUpon = auditActionContext.getResourceOperatedUpon();
        if (resourceOperatedUpon.contains(" for ")) {
            String parts[] = auditActionContext.getResourceOperatedUpon().split(" for ");

            String ticket = parts[0];
            String service = parts[1];

            ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder
                    .getRequestAttributes();
            HttpServletRequest req = sra.getRequest();
            String useragent = req.getHeader("User-Agent");

            LOG.info("[" + auditActionContext.getWhenActionWasPerformed() + "] " + "[IP:"
                    + auditActionContext.getClientIpAddress() + "] " + "[ID:"
                    + auditActionContext.getPrincipal() + "] " + "[TICKET:" + ticket + "] " + "[SERVICE:"
                    + service + "] " + "[USER-AGENT:" + useragent + "]");
        }//w  w  w.  ja v a2 s .  com

    }

}

From source file:at.ac.univie.isc.asio.security.DelegationDetailsSource.java

private Identity findDelegatedCredentials(final HttpServletRequest request) {
    try {/*from  w  w  w .  j  a va 2s  .c o m*/
        final String header = request.getHeader(delegatedCredentialsHeader);
        return Objects.firstNonNull(parser.convert(header), Identity.undefined());
    } catch (final InvalidUsage malformedCredentials) {
        throw new BadCredentialsException(
                "illegal delegated credentials in '" + delegatedCredentialsHeader + "' header",
                malformedCredentials);
    }
}

From source file:com.javaps.springboot.LicenseController.java

@RequestMapping(value = "/public/license", produces = "text/plain", method = RequestMethod.POST)
public String licenseValidate(HttpServletRequest req, @RequestBody String license) throws Exception {
    String clientIp = req.getHeader("X-Forwarded-For"); //nginx???IP
    if (clientIp == null)
        clientIp = req.getRemoteAddr(); //?????
    //System.out.println("clientIp="+clientIp);
    SecretKeySpec signingKey = new SecretKeySpec(licenseSecretKey.getBytes(), "HmacSHA1");
    Mac mac = Mac.getInstance("HmacSHA1");
    mac.init(signingKey);//from   w  ww  .  j  av a2  s .  c o m

    byte[] rawHmac = mac.doFinal(clientIp.getBytes());
    //System.out.println("license should be:"+Base64.encodeBase64String(rawHmac));
    if (!license.equals(Base64.encodeBase64String(rawHmac)))
        throw new Exception();

    return "OK";
}