List of usage examples for javax.servlet.http HttpServletRequest isSecure
public boolean isSecure();
From source file:org.silverpeas.core.web.http.HttpRequest.java
/** * Decorates the specified HTTP servlet request with an HttpRequest instance. If the request is * already an HttpRequest instance, then it is simply returned. * * @param request the Http servlet request to decorate. * @return an HttpRequest instance decorating the specified request. *//*from ww w. ja v a 2s . c om*/ public static HttpRequest decorate(final HttpServletRequest request) { CacheServiceProvider.getRequestCacheService().getCache().put(SECURE_PROPERTY, request.isSecure()); return request instanceof HttpRequest ? (HttpRequest) request : new HttpRequest(request); }
From source file:org.openlaszlo.utils.LZHttpUtils.java
/** * If a URL contains <code>/@WEBAPP@</code>, replaces that string with * context path. If context path is <code>/</code>, the function just * removes the <code>/@WEBAPP@</code> string. * * @param url URL to check if <code>/@WEBAPP@</code> token exists. * @return if <code>/@WEBAPP@</code> exists, new modified URL else old URL. *//*from w w w . j a va2s . c o m*/ public static String modifyWEBAPP(HttpServletRequest req, String url) { mLogger.debug("modifyWEBAPP"); if (url.startsWith(WEBAPP)) { mLogger.debug(" Old URL: " + url); String protocol = (req.isSecure() ? "https" : "http"); String host = req.getServerName(); int port = req.getServerPort(); String cp = req.getContextPath(); url = protocol + "://" + host + ":" + port + cp + url.substring(WEBAPP.length() - 1); mLogger.debug(" New URL: " + url); } return url; }
From source file:org.opensubsystems.core.util.servlet.WebUtils.java
/** * Adjust the secure and nonsecure port numbers the web application is * currently running on. /*w w w.j a v a 2 s . c o m*/ * * @param hsrqRequest - the servlet request. */ public static void adjustPorts(HttpServletRequest hsrqRequest) { if (hsrqRequest.isSecure()) { s_iWebPortSecure = hsrqRequest.getServerPort(); } else { s_iWebPort = hsrqRequest.getServerPort(); } }
From source file:org.ednovo.gooru.core.application.util.BaseUtil.java
public static boolean isSecure(HttpServletRequest request) { boolean isSecure = false; if (request != null) { String requestProtocol = request.getAttribute("requestProtocol") != null ? (String) request.getAttribute("requestProtocol") : null;//from w w w . ja v a 2 s . c o m if (requestProtocol != null && requestProtocol.trim().length() > 0) { if (requestProtocol.equalsIgnoreCase("https")) { isSecure = true; } else { isSecure = false; } } else { isSecure = request.isSecure(); if (!isSecure) { requestProtocol = request.getHeader("X-FORWARDED-PROTO"); if (requestProtocol != null && requestProtocol.equalsIgnoreCase("https")) { isSecure = true; } } } } return isSecure; }
From source file:org.jasig.cas.util.CommonUtils.java
/** * Constructs a service url from the HttpServletRequest or from the given * serviceUrl. Prefers the serviceUrl provided if both a serviceUrl and a * serviceName./*w w w .j a va2 s . c om*/ * * @param request the HttpServletRequest * @param response the HttpServletResponse * @param service the configured service url (this will be used if not null) * @param serverName the server name to use to constuct the service url if the service param is empty * @param artifactParameterName the artifact parameter name to remove (i.e. ticket) * @param encode whether to encode the url or not (i.e. Jsession). * @return the service url to use. */ public static String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final String service, final String serverName, final String artifactParameterName, final boolean encode) { if (CommonUtils.isNotBlank(service)) { return encode ? response.encodeURL(service) : service; } final StringBuilder buffer = new StringBuilder(); if (!serverName.startsWith("https://") && !serverName.startsWith("http://")) { buffer.append(request.isSecure() ? "https://" : "http://"); } buffer.append(serverName); buffer.append(request.getRequestURI()); if (CommonUtils.isNotBlank(request.getQueryString())) { final int location = request.getQueryString().indexOf(artifactParameterName + "="); if (location == 0) { final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; } buffer.append("?"); if (location == -1) { buffer.append(request.getQueryString()); } else if (location > 0) { final int actualLocation = request.getQueryString().indexOf("&" + artifactParameterName + "="); if (actualLocation == -1) { buffer.append(request.getQueryString()); } else if (actualLocation > 0) { buffer.append(request.getQueryString().substring(0, actualLocation)); } } } final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; }
From source file:org.jasig.cas.client.util.CommonUtils.java
/** * Constructs a service url from the HttpServletRequest or from the given * serviceUrl. Prefers the serviceUrl provided if both a serviceUrl and a * serviceName.//w w w .j a va2 s .c o m * * @param request the HttpServletRequest * @param response the HttpServletResponse * @param service the configured service url (this will be used if not null) * @param serverName the server name to use to constuct the service url if the service param is empty * @param artifactParameterName the artifact parameter name to remove (i.e. ticket) * @param encode whether to encode the url or not (i.e. Jsession). * @return the service url to use. */ public static String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final String service, final String serverName, final String artifactParameterName, final boolean encode) { if (CommonUtils.isNotBlank(service)) { return encode ? response.encodeURL(service) : service; } final StringBuffer buffer = new StringBuffer(); synchronized (buffer) { if (!serverName.startsWith("https://") && !serverName.startsWith("http://")) { buffer.append(request.isSecure() ? "https://" : "http://"); } buffer.append(serverName); buffer.append(request.getRequestURI()); if (CommonUtils.isNotBlank(request.getQueryString())) { final int location = request.getQueryString().indexOf(artifactParameterName + "="); if (location == 0) { final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; } buffer.append("?"); if (location == -1) { buffer.append(request.getQueryString()); } else if (location > 0) { final int actualLocation = request.getQueryString().indexOf("&" + artifactParameterName + "="); if (actualLocation == -1) { buffer.append(request.getQueryString()); } else if (actualLocation > 0) { buffer.append(request.getQueryString().substring(0, actualLocation)); } } } } final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; }
From source file:org.carewebframework.ui.FrameworkWebSupport.java
/** * Sets a cookie into the response. Cookies are URLEncoded for consistency (Version 0+ of * Cookies)//from w ww . j a va 2s . co m * * @param cookieName Name of cookie. * @param value Value of cookie. If null, the cookie is removed from the client if it exists. * @param httpResponse Response object. * @param httpRequest Request object. * @return Newly created cookie. * @throws IllegalArgumentException if cookieName, httpResponse, or httpRequest arguments are * null */ public static Cookie setCookie(final String cookieName, String value, final HttpServletResponse httpResponse, final HttpServletRequest httpRequest) { Validate.notNull(httpResponse, "The httpResponse must not be null"); Cookie cookie = getCookie(cookieName, httpRequest); if (value != null) { value = encodeCookieValue(value); } if (cookie == null) { if (value == null) { return null; } cookie = new Cookie(cookieName, value); } else if (value == null) { cookie.setMaxAge(0); } else { cookie.setValue(value); } if (httpRequest.isSecure()) { cookie.setSecure(true); } httpResponse.addCookie(cookie); return cookie; }
From source file:nanshen.service.impl.SpringSecureChannelProcessor.java
@Override public void decide(FilterInvocation invocation, Collection<ConfigAttribute> config) throws IOException, ServletException { Assert.isTrue((invocation != null) && (config != null), "Nulls cannot be provided"); for (ConfigAttribute attribute : config) { if (supports(attribute)) { HttpServletRequest httpRequest = invocation.getHttpRequest(); if (!httpRequest.isSecure() && StringUtils.isBlank(httpRequest.getHeader("HTTPS"))) { getEntryPoint().commence(invocation.getRequest(), invocation.getResponse()); }/*from w w w . j a va 2 s . c om*/ } } }
From source file:org.apache.nifi.web.security.jwt.JwtAuthenticationFilter.java
@Override public Authentication attemptAuthentication(final HttpServletRequest request) { // only support jwt login when running securely if (!request.isSecure()) { return null; }// w ww . ja va 2 s. com // TODO: Refactor request header extraction logic to shared utility as it is duplicated in AccessResource // get the principal out of the user token final String authorization = request.getHeader(AUTHORIZATION); // if there is no authorization header, we don't know the user if (authorization == null || !StringUtils.startsWith(authorization, BEARER)) { return null; } else { // Extract the Base64 encoded token from the Authorization header final String token = StringUtils.substringAfterLast(authorization, " "); return new JwtAuthenticationRequestToken(token, request.getRemoteAddr()); } }
From source file:com.acc.storefront.filters.StorefrontFilter.java
protected boolean isRequestSecure(final HttpServletRequest httpRequest) { return httpRequest.isSecure(); }