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:com.parallax.server.blocklyprop.servlets.ConfirmRequestServlet.java

public void showTextilePage(HttpServletRequest req, HttpServletResponse resp, ConfirmPage confirmPage)
        throws ServletException, IOException {
    String html = textileFileReader.readFile("confirm/" + confirmPage.getPage(), ServletUtils.getLocale(req),
            req.isSecure());
    req.setAttribute("html", html);
    req.getRequestDispatcher("/WEB-INF/servlet/html.jsp").forward(req, resp);
}

From source file:net.duckling.ddl.service.oauth.impl.OAuthServiceImpl.java

@Override
public 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 a2 s. c  om*/
    OAuthServlet.handleException(response, e, realm, sendBody);
}

From source file:org.apache.rave.portal.service.impl.ReCaptchaService.java

@Override
public String createHtml(HttpServletRequest request) {
    if (captchaEnabled) {
        if (StringUtils.isBlank(privateKey) || StringUtils.isBlank(publicKey)) {
            return invalidConfigurationMessage;
        }/*from   ww  w.  j a  v  a 2 s.com*/
        boolean secure = request.isSecure();

        ReCaptcha captcha;
        if (secure) {
            captcha = ReCaptchaFactory.newSecureReCaptcha(publicKey, privateKey, createNoScript);
        } else {
            captcha = ReCaptchaFactory.newReCaptcha(publicKey, privateKey, createNoScript);
        }

        return captcha.createRecaptchaHtml(null, null);
    }
    return "";
}

From source file:org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet.java

private void checkSaslAuthEnabled(HttpServletRequest request) {
    boolean saslAuthEnabled;
    HttpManagement management = getManagement();
    if (request.isSecure()) {
        saslAuthEnabled = management.isHttpsSaslAuthenticationEnabled();
    } else {/*from   ww w.j av  a2s . c  o m*/
        saslAuthEnabled = management.isHttpSaslAuthenticationEnabled();
    }

    if (!saslAuthEnabled) {
        throw new RuntimeException("Sasl authentication disabled.");
    }
}

From source file:com.parallax.server.blocklyprop.servlets.PasswordResetRequestServlet.java

public void showTextilePage(HttpServletRequest req, HttpServletResponse resp,
        PasswordResetPage passwordResetPage) throws ServletException, IOException {
    String html = textileFileReader.readFile("password-reset/" + passwordResetPage.getPage(),
            ServletUtils.getLocale(req), req.isSecure());
    req.setAttribute("html", html);
    req.getRequestDispatcher("/WEB-INF/servlet/html.jsp").forward(req, resp);
}

From source file:com.exxonmobile.ace.hybris.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java

@Override
public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response,
        final HandlerMethod handler) throws Exception {
    // We only care if the request is secure
    if (request.isSecure()) {
        // Check if the handler has our annotation
        final RequireHardLogIn annotation = findAnnotation(handler, RequireHardLogIn.class);
        if (annotation != null) {
            boolean redirect = true;
            final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);
            final boolean anonymousUser = getUserService().isAnonymousUser(getUserService().getCurrentUser());
            if (!anonymousUser && guid != null && request.getCookies() != null) {
                final String guidCookieName = getCookieGenerator().getCookieName();
                if (guidCookieName != null) {
                    for (final Cookie cookie : request.getCookies()) {
                        if (guidCookieName.equals(cookie.getName())) {
                            if (guid.equals(cookie.getValue())) {
                                redirect = false;
                                break;
                            } else {
                                LOG.info("Found secure cookie with invalid value. expected [" + guid
                                        + "] actual [" + cookie.getValue() + "]. removing.");
                                getCookieGenerator().removeCookie(response);
                            }/*w  ww  . j  a v  a  2 s.  co m*/
                        }
                    }
                }
            }

            if (redirect) {
                LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie")
                        + ", redirecting");
                getRedirectStrategy().sendRedirect(request, response, getRedirectUrl(request));
                return false;
            }
        }
    }

    return true;
}

From source file:com.erudika.para.utils.Utils.java

/**
 * Sets a cookie.//from   w w  w.  ja  va 2 s .co  m
 * @param name the name
 * @param value the value
 * @param req HTTP request
 * @param res HTTP response
 * @param httpOnly HTTP only flag
 * @param maxAge max age
 */
public static void setRawCookie(String name, String value, HttpServletRequest req, HttpServletResponse res,
        boolean httpOnly, int maxAge) {
    if (StringUtils.isBlank(name) || StringUtils.isBlank(value) || req == null || res == null) {
        return;
    }
    Cookie cookie = new Cookie(name, value);
    cookie.setHttpOnly(httpOnly);
    cookie.setMaxAge(maxAge < 0 ? Config.SESSION_TIMEOUT_SEC.intValue() : maxAge);
    cookie.setPath("/");
    cookie.setSecure(req.isSecure());
    res.addCookie(cookie);
}

From source file:com.acc.storefront.filters.RequestLoggerFilter.java

protected String buildRequestDetails(final HttpServletRequest request) {
    String queryString = request.getQueryString();
    if (queryString == null) {
        queryString = "";
    }/*from  w  w w .  j  av a 2s  . co  m*/

    final String requestUri = request.getRequestURI();

    final String securePrefix = request.isSecure() ? "s" : " ";
    final String methodPrefix = request.getMethod().substring(0, 1);

    return securePrefix + methodPrefix + " [" + requestUri + "] [" + queryString + "] ";
}

From source file:com.mitre.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java

@Override
public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response,
        final HandlerMethod handler) throws Exception {
    // We only care if the request is secure
    if (request.isSecure()) {
        // Check if the handler has our annotation
        final RequireHardLogIn annotation = findAnnotation(handler, RequireHardLogIn.class);
        if (annotation != null) {
            boolean redirect = true;
            final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);
            final boolean anonymousUser = getUserService().isAnonymousUser(getUserService().getCurrentUser());
            if (!anonymousUser && guid != null && request.getCookies() != null) {
                final String guidCookieName = getCookieGenerator().getCookieName();
                if (guidCookieName != null) {
                    for (final Cookie cookie : request.getCookies()) {
                        if (guidCookieName.equals(cookie.getName())) {
                            if (guid.equals(cookie.getValue())) {
                                redirect = false;
                                break;
                            } else {
                                LOG.info("Found secure cookie with invalid value. expected [" + guid
                                        + "] actual [" + cookie.getValue() + "]. removing.");
                                getCookieGenerator().removeCookie(response);
                            }// w w  w . j  a va  2  s. com
                        }
                    }
                }
            }

            if (redirect) {
                final String ajaxHeader = request.getHeader(ajaxRequestHeaderKey);
                LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie")
                        + ", redirecting");
                if (ajaxRequestHeaderValue.equals(ajaxHeader)) {
                    response.addHeader("redirectUrl", request.getContextPath() + getRedirectUrl(request));
                    response.sendError(Integer.parseInt(ajaxRedirectErrorCode));
                } else {
                    getRedirectStrategy().sendRedirect(request, response, getRedirectUrl(request));
                }
                return false;
            }
        }
    }

    return true;
}

From source file:ru.org.linux.gallery.DeleteImageController.java

@RequestMapping(method = RequestMethod.POST)
public RedirectView deleteImage(@RequestParam(required = true) int id, HttpServletRequest request)
        throws Exception {
    Template tmpl = Template.getTemplate(request);

    Image image = imageDao.getImage(id);
    Topic topic = topicDao.getById(image.getTopicId());
    PreparedTopic preparedTopic = prepareService.prepareTopic(topic, request.isSecure(), tmpl.getCurrentUser());

    checkDelete(preparedTopic, tmpl.getCurrentUser());

    imageService.deleteImage(tmpl.getCurrentUser(), image);

    return new RedirectView(TopicLinkBuilder.baseLink(topic).forceLastmod().build());
}