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.robusta.rra.controller.SpringController.java

@Override
public String[] getBasicAuthentication(HttpServletRequest req, HttpServletResponse resp) {
    String authorization = req.getHeader("Authorization");
    String[] values = new String[2];
    if (authorization != null && authorization.startsWith("Basic")) {
        if (req.isSecure()) {
            String base64Credentials = authorization.substring("Basic".length()).trim();
            CodecImpl codecimpl = new CodecImpl();
            try {
                values[0] = codecimpl.getUsername(base64Credentials);
                values[1] = codecimpl.getPassword(base64Credentials);
            } catch (CodecException e) {
                e.printStackTrace();/*from www.  ja v a 2 s.c  o  m*/
            }
        } else {
            try {
                resp.getWriter().println(
                        "<a href='http://docs.oracle.com/javaee/5/tutorial/doc/bnbxw.html'>Establishing a Secure Connection Using SSL</a>");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return values;
}

From source file:org.broadleafcommerce.common.RequestDTOImpl.java

public RequestDTOImpl(HttpServletRequest request) {
    requestURI = request.getRequestURI();
    fullUrlWithQueryString = request.getRequestURL().toString();
    if (StringUtils.isNotEmpty(request.getQueryString())) {
        fullUrlWithQueryString += "?" + request.getQueryString();
    }/*from w ww.j a  va  2  s.co  m*/
    secure = ("HTTPS".equalsIgnoreCase(request.getScheme()) || request.isSecure());
}

From source file:au.gov.dto.springframework.security.web.context.CookieSecurityContextRepository.java

private Cookie createExpireAuthenticationCookie(HttpServletRequest request) {
    Cookie removeSessionCookie = new Cookie(authenticationCookieName, "");
    removeSessionCookie.setPath(authenticationCookiePath);
    removeSessionCookie.setMaxAge(0);/*from w  ww  . j  a  va 2s .co  m*/
    removeSessionCookie.setHttpOnly(true);
    removeSessionCookie.setSecure(request.isSecure());
    return removeSessionCookie;
}

From source file:org.dataconservancy.dcs.lineage.http.support.RequestUtil.java

/**
 * Build the original request url in the form http://hostname/request/uri.
 * <p/>/*from  ww  w  .  j a  v a  2s.com*/
 * If you include a 'Host' HTTP header (which is the form hostname:port), that is what will be used to re-construct
 * the requested URL. If you don't include a 'Host' header, the the behavior is to use
 * HttpServletRequest.getRemoteHost() to determine the hostname, and HttpServletRequest.getRemotePort() to determine
 * the port number.  The logic is influenced by three member variables of RequestUtil: considerHostHeader,
 * considerRemotePort, and considerLocalPort.  The summary above is the default behavior (by default all three flags
 * are true).
 *
 * @param request the request
 * @return the request url
 */
public String buildRequestUrl(HttpServletRequest request) {
    StringBuilder url = new StringBuilder("http");
    if (request.isSecure()) {
        url.append("s");
    }
    url.append("://");

    url.append(determineHostName(request));

    int port = determinePort(request);

    if (port == 80) {
        if (request.isSecure()) {
            url.append(":80");
        }
    } else if (port == 443) {
        if (!request.isSecure()) {
            url.append(":443");
        }
    } else {
        url.append(":").append(port);
    }

    url.append(request.getRequestURI());

    return url.toString();
}

From source file:org.josso.gateway.protocol.handler.NtlmProtocolHandler.java

private boolean isOfferBasic(HttpServletRequest req) {
    return enableBasic && (insecureBasic || req.isSecure());
}

From source file:org.tdmx.server.sx.Servlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");

    PrintWriter writer = response.getWriter();
    writer.println("<html>");
    writer.println("<head><title>Hello World Servlet</title></head>");
    writer.println("<body>");
    writer.println("Hello World! How are you doing? secure=" + request.isSecure());
    // writer.println(" AccountId=" + accountService.getActivePartitionId());

    writer.println("</body>");
    writer.println("</html>");
    writer.close();/*w w w . j a  v a  2  s .com*/

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.OntologyController.java

private void doRedirect(HttpServletRequest req, HttpServletResponse res, String redirectURL)
        throws IOException {
    //It seems like there must be a more standard way to do a redirect in tomcat.
    String hn = req.getHeader("Host");
    if (req.isSecure()) {
        res.setHeader("Location", res.encodeURL("https://" + hn + req.getContextPath() + redirectURL));
        log.info("doRedirect by using HTTPS");
    } else {/*from  ww w  .j av a2  s  . c o m*/
        res.setHeader("Location", res.encodeURL("http://" + hn + req.getContextPath() + redirectURL));
        log.info("doRedirect by using HTTP");
    }
    res.setStatus(res.SC_SEE_OTHER);
}

From source file:org.entando.entando.aps.system.services.oauth.OAuthConsumerManager.java

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 .  j  a  v  a2  s  . c o  m
    OAuthServlet.handleException(response, e, realm, sendBody);
}

From source file:com.atlassian.jira.security.xsrf.SimpleXsrfTokenGenerator.java

private void addNewCookie(HttpServletRequest httpServletRequest, String token,
        HttpServletResponse httpServletResponse) {
    final Cookie cookie = new Cookie(TOKEN_HTTP_SESSION_KEY, token);
    cookie.setPath(getRequestContext(httpServletRequest));
    cookie.setMaxAge(-1); // expire with the browser exit
    cookie.setSecure(httpServletRequest.isSecure());
    httpServletResponse.addCookie(cookie);
    httpServletRequest.setAttribute(SET_COOKIE_PENDING, token);
}

From source file:ru.org.linux.comment.AddCommentController.java

/**
 *   ?  ? ?.//from ww  w .j a v  a2s . c o m
 *
 * @param add      WEB-, ?? 
 * @param request   ?  web-
 * @return  web-
 * @throws Exception
 */
@RequestMapping("/comment-message.jsp")
public ModelAndView showFormTopic(@ModelAttribute("add") @Valid CommentRequest add,
        HttpServletRequest request) {
    Template tmpl = Template.getTemplate(request);

    if (add.getMode() == null) {
        add.setMode(tmpl.getFormatMode());
    }

    ModelAndView modelAndView = new ModelAndView("comment-message", "preparedMessage",
            messagePrepareService.prepareTopic(add.getTopic(), request.isSecure(), tmpl.getCurrentUser()));

    return modelAndView;
}