Example usage for javax.servlet.http HttpServletRequest isSecure

List of usage examples for javax.servlet.http HttpServletRequest isSecure

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest isSecure.

Prototype

public boolean isSecure();

Source Link

Document

Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Usage

From source file:io.lavagna.web.security.HSTSFilter.java

private static boolean isOverHttps(HttpServletRequest req) {
    return req.isSecure() || req.getRequestURL().toString().startsWith("https://")
            || StringUtils.equals("https", req.getHeader("X-Forwarded-Proto"));
}

From source file:com.gopivotal.cla.web.RepositoriesController.java

private static String getScheme(HttpServletRequest httpServletRequest) {
    return httpServletRequest.isSecure() ? SECURE_SCHEME : DEFAULT_SCHEME;
}

From source file:com.liferay.portal.util.CookieKeys.java

public static void addCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie) {

    addCookie(request, response, cookie, request.isSecure());
}

From source file:de.adorsys.oauth.authdispatcher.FixedServletUtils.java

/**
 * Reconstructs the request URL string for the specified servlet
 * request. The host part is always the local IP address. The query
 * string and fragment is always omitted.
 *
 * @param request The servlet request. Must not be {@code null}.
 *
 * @return The reconstructed request URL string.
 *///w w  w.  ja va  2s.  com
private static String reconstructRequestURLString(final HttpServletRequest request) {

    StringBuilder sb = new StringBuilder("http");

    if (request.isSecure())
        sb.append('s');

    sb.append("://");

    String localAddress = request.getLocalAddr();

    if (localAddress.contains(".")) {
        // IPv3 address
        sb.append(localAddress);
    } else if (localAddress.contains(":")) {
        // IPv6 address, see RFC 2732
        sb.append('[');
        sb.append(localAddress);
        sb.append(']');
    } else {
        // Don't know what to do
    }

    if (!request.isSecure() && request.getLocalPort() != 80) {
        // HTTP plain at port other than 80
        sb.append(':');
        sb.append(request.getLocalPort());
    }

    if (request.isSecure() && request.getLocalPort() != 443) {
        // HTTPS at port other than 443 (default TLS)
        sb.append(':');
        sb.append(request.getLocalPort());
    }

    String path = request.getRequestURI();

    if (path != null)
        sb.append(path);

    return sb.toString();
}

From source file:com.zimbra.cs.account.oauth.utils.OAuthServiceProvider.java

public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        boolean sendBody) throws IOException, ServletException {
    String realm = (request.isSecure()) ? "https://" : "http://";
    realm += request.getLocalName();/*from  w  w  w  .  ja  v a  2  s . c o  m*/
    OAuthServlet.handleException(response, e, realm, sendBody);
}

From source file:org.j2free.jsp.el.StandardExtensions.java

/**
 *
 * @param request//from   w ww. j  a  va  2 s .  c om
 * @return
 */
public static boolean isSecureRequest(HttpServletRequest request) {
    return request.isSecure();
}

From source file:org.biomart.oauth.provider.core.SimpleOAuthProvider.java

public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        boolean sendBody) throws IOException, ServletException {
    String realm = (request.isSecure()) ? "https://" : "http://";
    OutputStream out = response.getOutputStream();
    realm += request.getLocalName();// ww  w.ja  va 2s. com
    OAuthServlet.handleException(response, e, realm, sendBody);
    out.close();
}

From source file:com.liferay.util.Http.java

public static String getProtocol(HttpServletRequest req) {
    return getProtocol(req.isSecure());
}

From source file:net.firejack.platform.web.security.oauth.provider.OAuthProcessor.java

/**
 * @param e//from ww  w  .  j a  v a 2s.  c  o  m
 * @param request
 * @param response
 * @param sendBody
 * @throws javax.servlet.ServletException
 * @throws java.io.IOException
 */
public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        boolean sendBody) throws IOException, ServletException {
    String realm = (request.isSecure()) ? "https://" : "http://";
    realm += request.getLocalName();
    OAuthServlet.handleException(response, e, realm, sendBody);
}

From source file:com.alfaariss.oa.util.saml2.binding.AbstractDecodingFactory.java

/**
 * Resolve and retrieve a decoding factory based on the request.
 * //from www . ja  va 2s.  co m
 * The factory is resolved and its message context is created based on the 
 * request.
 * 
 * @param request The request.
 * @param response The response.
 * @param prop The bindings configuration properties.
 * @return The resolved factory, or <code>null</code> if no appropriate 
 *  binding factory can be resolved.
 */
public static AbstractDecodingFactory resolveInstance(HttpServletRequest request, HttpServletResponse response,
        BindingProperties prop) {
    AbstractDecodingFactory factory = null;
    HTTPInTransport inTransport = new HttpServletRequestAdapter(request);

    HTTPOutTransport outTransport = new HttpServletResponseAdapter(response, request.isSecure());

    // First check for artifact
    if (!DatatypeHelper.isEmpty(inTransport.getParameterValue("SAMLart"))) {
        factory = new HTTPArtifactDecodingFactory(prop);
    } else {
        if (inTransport.getHTTPMethod().equalsIgnoreCase(SAMLConstants.GET_METHOD)) {
            if (!DatatypeHelper.isEmpty(inTransport.getParameterValue("SAMLRequest"))
                    || !DatatypeHelper.isEmpty(inTransport.getParameterValue("SAMLResponse"))) {
                factory = new HTTPRedirectDecodingFactory(prop);
            } else
                _logger.debug("No SAML request or response found in GET request");
        } else if (inTransport.getHTTPMethod().equalsIgnoreCase(SAMLConstants.POST_METHOD)) {
            String sContextType = inTransport.getHeaderValue("Content-Type");

            if (!DatatypeHelper.isEmpty(inTransport.getParameterValue("SAMLRequest"))
                    || !DatatypeHelper.isEmpty(inTransport.getParameterValue("SAMLResponse"))) {
                factory = new HTTPPostDecodingFactory(prop);
            } else if (sContextType == null) {
                _logger.debug("No Content-Type found");
            } else if (sContextType.contains("text/xml")) {
                factory = new SOAP11DecodingFactory(prop);
            } else
                _logger.debug(
                        "No SAML request or response found and unsupported Content-Type: " + sContextType);
        } else
            _logger.debug("Unsupported HTTP Method: " + inTransport.getHTTPMethod());
    }

    if (factory != null) {
        factory._context = new BasicSAMLMessageContext<SignableSAMLObject, SignableSAMLObject, SAMLObject>();
        factory._context.setInboundMessageTransport(inTransport);
        factory._context.setOutboundMessageTransport(outTransport);
    } else
        _logger.debug("No factory created, possible invalid request");

    return factory;
}