List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:com.npower.wall.TagUtil.java
/** * Figure out if the request is coming in through an UP.Link (AKA MAG) WAP * Gateway from Openwave (this info is necessary to undestand if certain WML * extensions (useful for usability) can be utilized. */// w ww. j a v a 2 s . c o m public static boolean isUplink(HttpServletRequest request) { String UA = ""; if (request.getParameter("UA") != null) { UA = "" + request.getParameter("UA"); } else { UA = "" + request.getHeader("User-Agent"); } if (UA.indexOf("UP.Link") != -1) { return true; } else { return false; } }
From source file:net.firejack.platform.web.security.oauth.provider.OAuthProcessor.java
/** * @param httpRequest//w w w . jav a 2 s. c o m * @return */ public static boolean isOAuthRequest(HttpServletRequest httpRequest) { String oAuthHeader = httpRequest.getHeader("authorization"); return StringUtils.isNotBlank(oAuthHeader) && oAuthHeader.contains("oauth_nonce"); }
From source file:de.arago.portlet.util.UserContainer.java
private static User getUserFromAuthHeader(HttpServletRequest request) throws Exception { String auth = request.getHeader("Authorization"); if (auth == null) return null; auth = new String(Base64.decodeBase64(auth.replaceAll("^Basic\\ +", ""))); return lookupUserFromCache(auth.substring(0, auth.indexOf(":")), auth.substring(auth.indexOf(":") + 1), true);//from ww w. j a v a 2s .c o m }
From source file:com.cnksi.core.web.utils.Servlets.java
/** * ?? If-None-Match Header, Etag?./* w w w . j a v a2 s . com*/ * * Etag, checkIfNoneMatchfalse, 304 not modify status. * * @param etag ETag. */ public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) { String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader(HttpHeaders.ETAG, etag); return false; } } return true; }
From source file:com.zlfun.framework.misc.UploadUtils.java
private static String getBrowser(HttpServletRequest request) { String agent = request.getHeader("USER-AGENT"); if (agent == null) { return null; }/*from w w w. j a v a 2s . c o m*/ String userAgent = agent.toLowerCase(); if (userAgent.indexOf("msie") >= 0) { return "IE"; } else if (userAgent.indexOf("mozilla") >= 0) { return "FF"; } else if (userAgent.indexOf("applewebkit") >= 0) { return "CH"; } else if (userAgent.indexOf("safari") >= 0) { return "SF"; } else if (userAgent.indexOf("opera") >= 0) { return "OP"; } return null; }
From source file:com.eastcom.baseframe.web.common.utils.Servlets.java
/** * ?/*w w w .jav a 2 s .c o m*/ * * @param request * @return */ public static String getRemoteAddr(HttpServletRequest request) { String remoteAddr = request.getHeader("X-Real-IP"); if (StringUtils.isNotBlank(remoteAddr)) { remoteAddr = request.getHeader("X-Forwarded-For"); } else if (StringUtils.isNotBlank(remoteAddr)) { remoteAddr = request.getHeader("Proxy-Client-IP"); } else if (StringUtils.isNotBlank(remoteAddr)) { remoteAddr = request.getHeader("WL-Proxy-Client-IP"); } return remoteAddr != null ? remoteAddr : request.getRemoteAddr(); }
From source file:me.xhh.utils.Util.java
/** * @return the client IP address found from the given request. would find the IP data set by proxy first *///from w w w . ja v a2 s . com public static String getClientIP(HttpServletRequest request) { if (request == null) return null; final String UNKNOWN_TOKEN = "unknown"; String ip = request.getHeader("x-forwarded-for"); if (StringUtils.isBlank(ip) || UNKNOWN_TOKEN.equalsIgnoreCase(ip)) ip = request.getHeader("Proxy-Client-IP"); if (StringUtils.isBlank(ip) || UNKNOWN_TOKEN.equalsIgnoreCase(ip)) ip = request.getHeader("WL-Proxy-Client-IP"); if (StringUtils.isBlank(ip) || UNKNOWN_TOKEN.equalsIgnoreCase(ip)) ip = request.getRemoteAddr(); return ip; }
From source file:de.qucosa.servlet.MetsDisseminatorServlet.java
private static String extractBasicAuthCredentials(HttpServletRequest request) throws AuthenticationException { String credentials = ""; final String authHeader = request.getHeader("Authorization"); if (authHeader != null && authHeader.startsWith("Basic")) { try {//from w ww . java 2s.c om final String base64credentials = authHeader.substring("Basic".length()).trim(); credentials = new String(Base64.decode(base64credentials)); } catch (Base64DecodingException e) { throw new AuthenticationException("Provided credentials are invalid."); } } return credentials; }
From source file:com.soolr.core.web.Servlets.java
public static String getIp(HttpServletRequest request) { String xforward = request.getHeader("x-forwarded-for"); // TODO shall we use a more reliable solution? // compare xforward with haproxy ip if (StringUtils.isNotEmpty(xforward)) { String[] split = StringUtils.split(xforward, "."); if (split.length == 4) { return xforward; }/*w w w . jav a 2 s .c o m*/ } return request.getRemoteAddr(); }
From source file:com.binarybirchtree.filters.IpFilter.java
public static String getForwardedIp(HttpServletRequest request) { String ip = null;//w w w . j ava 2s.c o m // Believe the Cloudflare header only if the last IP was from Cloudflare. if (ipIsInList(getForwardedIp(request, 1), cloudflareIps)) ip = request.getHeader("CF-Connecting-IP"); // If there is no Cloudflare header, return the last known reliable IP. if (ip == null) ip = getForwardedIp(request, 1); return ip; }