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:org.rhq.enterprise.server.rest.reporting.InventorySummaryHandler.java

private String getDetailsURL(Resource resource, HttpServletRequest request) {
    String protocol;//from  ww w . jav a 2  s  .  c o m
    if (request.isSecure()) {
        protocol = "https";
    } else {
        protocol = "http";
    }

    return protocol + "://" + request.getServerName() + ":" + request.getServerPort() + "/coregui/#Resource/"
            + resource.getId();
}

From source file:com.mondospider.spiderlocationapi.SetSpiderLocation.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    if (!req.isSecure()) {
        resp.getWriter()//from   ww w  . j a va 2 s. co m
                .println("{\"result:error\", \"reason\":\"SSL secured connection required for updates.\"}");
        return;
    }

    if (req.getParameter("lat") == null || req.getParameter("lng") == null || req.getParameter("pwd") == null) {
        //Display Error&Help
        try {
            req.getRequestDispatcher("/index.html").forward(req, resp);
        } catch (ServletException e) {
            resp.getWriter().println("{\"result:error\", \"reason\":\"Forward failed\"}");
            e.printStackTrace();
            return;
        }
    }

    // Permission Check
    String key = req.getParameter("pwd");
    if (!isSecretKeyTrue(key)) {
        // accessDenied
        resp.getWriter().println("{\"result:error\", \"reason\":\"Wrong Key\"}");
        return;
    }

    try {

        // Get lat/lng Parameters and validate
        double lat = 0;
        double lng = 0;

        try {
            lat = Double.parseDouble(req.getParameter("lat"));
            lng = Double.parseDouble(req.getParameter("lng"));
        } catch (NumberFormatException e) {
            responseResp.put("result", "error");
            responseResp.put("reason", "Parameter lat or log missing or invalid");

            resp.getWriter().println(responseResp.toString(2));

            return;
        }

        String status = req.getParameter("status");

        // Update Position
        updatePosition("spider", lat, lng, status);

        responseResp.put("result", "success");
        responseResp.put("updated_on", new Date());

        resp.setContentType("text/plain");

        resp.getWriter().println(responseResp.toString(2));
        return;

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    resp.sendRedirect("/index.html");

}

From source file:ru.org.linux.edithistory.EditHistoryController.java

@RequestMapping({ "/news/{group}/{id}/history", "/forum/{group}/{id}/history", "/gallery/{group}/{id}/history",
        "/polls/{group}/{id}/history" })
public ModelAndView showEditInfo(HttpServletRequest request, @PathVariable("id") int msgid) throws Exception {
    Topic message = messageDao.getById(msgid);

    List<PreparedEditHistory> editHistories = editHistoryService.prepareEditInfo(message, request.isSecure());

    ModelAndView modelAndView = new ModelAndView("history");

    modelAndView.getModel().put("message", message);
    modelAndView.getModel().put("editHistories", editHistories);

    return modelAndView;
}

From source file:org.apache.roller.weblogger.webservices.oauth.AccessTokenServlet.java

public void handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        boolean sendBody) throws IOException, ServletException {
    log.debug("ERROR authorizing token", e);
    String realm = (request.isSecure()) ? "https://" : "http://";
    realm += request.getLocalName();//w  ww.  j a  va 2  s. com
    OAuthServlet.handleException(response, e, realm, sendBody);
}

From source file:cn.edu.zjnu.acm.judge.user.ResetPasswordController.java

private String getPath(HttpServletRequest request, String... params) {
    int serverPort = request.getServerPort();
    int defaultPort = request.isSecure() ? 443 : 80;
    StringBuilder sb = new StringBuilder(80);

    sb.append(request.getScheme()).append("://").append(request.getServerName());
    if (serverPort != defaultPort) {
        sb.append(":").append(serverPort);
    }/*  w  w  w  . java 2  s  . c  o  m*/
    sb.append(request.getContextPath());
    for (String param : params) {
        sb.append(param);
    }
    return sb.toString();
}

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

/**
 * Create the binding factory for the given binding type. 
 * //w  ww .  j ava2 s .  c om
 * The following binding types are supported:
 * <ul>
 *  <li>{@link SAMLConstants#SAML2_ARTIFACT_BINDING_URI}</li>
 *  <li>{@link SAMLConstants#SAML2_POST_BINDING_URI}</li>
 *  <li>{@link SAMLConstants#SAML2_REDIRECT_BINDING_URI}</li>
 *  <li>{@link SAMLConstants#SAML2_SOAP11_BINDING_URI}</li>
 * </ul>
 * 
 * @param request The request.
 * @param response The response.
 * @param sBindingType The type of binding to be used.
 * @param prop The bindings configuration properties.
 * @return The created binding factory.
 * @throws OAException If an invalid binding type is supplied.
 */
public static AbstractDecodingFactory createInstance(HttpServletRequest request, HttpServletResponse response,
        String sBindingType, BindingProperties prop) throws OAException {
    AbstractDecodingFactory factory = null;

    if (sBindingType.equalsIgnoreCase(SAMLConstants.SAML2_ARTIFACT_BINDING_URI)) {
        factory = new HTTPArtifactDecodingFactory(prop);
    } else if (sBindingType.equalsIgnoreCase(SAMLConstants.SAML2_POST_BINDING_URI)) {
        factory = new HTTPPostDecodingFactory(prop);
    } else if (sBindingType.equalsIgnoreCase(SAMLConstants.SAML2_REDIRECT_BINDING_URI)) {
        factory = new HTTPRedirectDecodingFactory(prop);
    } else if (sBindingType.equalsIgnoreCase(SAMLConstants.SAML2_SOAP11_BINDING_URI)) {
        factory = new SOAP11DecodingFactory(prop);
    } else {
        _logger.warn("Invalid binding type supplied: " + sBindingType);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }

    HTTPInTransport inTransport = new HttpServletRequestAdapter(request);

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

    factory._context = new BasicSAMLMessageContext<SignableSAMLObject, SignableSAMLObject, SAMLObject>();
    factory._context.setInboundMessageTransport(inTransport);
    factory._context.setOutboundMessageTransport(outTransport);

    return factory;
}

From source file:uk.ac.ebi.atlas.web.ApplicationProperties.java

public String buildServerURL(HttpServletRequest request) throws MalformedURLException {
    String spec = request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
    if (request.isSecure()) {
        spec = "https://" + spec;
    } else {/*from w ww .j a  v a2  s . c o m*/
        spec = "http://" + spec;
    }

    URL url = new URL(spec);
    return url.toExternalForm();
}

From source file:com.epam.training.storefront.interceptors.beforecontroller.SecureRequestCookieCheckBeforeControllerHandler.java

@Override
public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception //NOPMD
{
    final String path = getUrlPathHelper().getServletPath(request);
    if (request.isSecure() && !getExcludeUrls().contains(path)) {
        boolean redirect = true;
        final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);
        if (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);
                        }/*  www .  j a  v  a 2 s.  c  o m*/
                    }
                }
            }
        }
        if (redirect) {
            LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie")
                    + ", redirecting");
            getRedirectStrategy().sendRedirect(request, response, getLoginUrl());
            return false;
        }
    }

    return true;
}

From source file:com.epam.cme.storefront.interceptors.beforecontroller.SecureRequestCookieCheckBeforeControllerHandler.java

@Override
public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception // NOPMD
{
    final String path = getUrlPathHelper().getServletPath(request);
    if (request.isSecure() && !getExcludeUrls().contains(path)) {
        boolean redirect = true;
        final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);
        if (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);
                        }/*from  w w  w  .  j a v  a  2  s  .com*/
                    }
                }
            }
        }
        if (redirect) {
            LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie")
                    + ", redirecting");
            getRedirectStrategy().sendRedirect(request, response, getLoginUrl());
            return false;
        }
    }

    return true;
}