Example usage for javax.servlet.http HttpServletRequest getScheme

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

Introduction

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

Prototype

public String getScheme();

Source Link

Document

Returns the name of the scheme used to make this request, for example, <code>http</code>, <code>https</code>, or <code>ftp</code>.

Usage

From source file:com.ucap.uccc.cmis.impl.webservices.CmisWebServicesServlet.java

private UrlBuilder compileBaseUrl(HttpServletRequest request, HttpServletResponse response) {
    UrlBuilder result;/*from   w ww  .  ja v a2s .  c  om*/

    String baseUrl = (String) request.getAttribute(Dispatcher.BASE_URL_ATTRIBUTE);
    if (baseUrl != null) {
        result = new UrlBuilder(baseUrl);
    } else {
        result = new UrlBuilder(request.getScheme(), request.getServerName(), request.getServerPort(), null);
        result.addPath(request.getContextPath());
        result.addPath(request.getServletPath());
    }

    return result;
}

From source file:org.gluu.oxtrust.action.SsoLoginAction.java

public String logout() {
    boolean isShib2Authentication = OxTrustConstants.APPLICATION_AUTHORIZATION_NAME_SHIBBOLETH2
            .equals(Contexts.getSessionContext().get(OxTrustConstants.APPLICATION_AUTHORIZATION_TYPE));

    if (isShib2Authentication) {
        // After this redirect we should invalidate this session
        try {//from  ww w  . java 2s .  c om
            HttpServletResponse userResponse = (HttpServletResponse) facesContext.getExternalContext()
                    .getResponse();
            HttpServletRequest userRequest = (HttpServletRequest) facesContext.getExternalContext()
                    .getRequest();

            String redirectUrl = String.format("%s%s", applicationConfiguration.getIdpUrl(), "/idp/logout.jsp");
            String url = String.format("%s://%s/Shibboleth.sso/Logout?return=%s", userRequest.getScheme(),
                    userRequest.getServerName(), redirectUrl);

            userResponse.sendRedirect(url);
            facesContext.responseComplete();
        } catch (IOException ex) {
            log.error("Failed to redirect to SSO logout page", ex);
        }
    }

    return isShib2Authentication ? OxTrustConstants.RESULT_LOGOUT_SSO : OxTrustConstants.RESULT_LOGOUT;
}

From source file:org.energy_home.jemma.ah.webui.energyathome.ekitchen.EnergyAtHome.java

public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // we need http scheme!
    if (enableHttps && !request.getScheme().equals("https")) {
        try {/*from ww w.j av  a  2  s . co m*/
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } catch (IOException e) {
            // do nothing
        }
        return false;
    }

    String queryString = request.getRequestURI();

    if (queryString.equals(applicationWebAlias + "/conf")
            || (queryString.equals(applicationWebAlias + "/conf/"))) {
        response.sendRedirect(applicationWebAlias + "/conf/index.html");
        return true;
    } else if (queryString.equals(applicationWebAlias) || (queryString.equals(applicationWebAlias + "/"))) {
        response.sendRedirect(applicationWebAlias + "/index.html");
        return true;
    }

    if (enableSecurity) {
        if (useBasic) {
            String auth = request.getHeader("Authorization");

            if (auth == null)
                return failAuthorization(request, response);

            StringTokenizer tokens = new StringTokenizer(auth);
            String authscheme = tokens.nextToken();

            if (!authscheme.equals("Basic"))
                return failAuthorization(request, response);

            String base64credentials = tokens.nextToken();
            String credentials = new String(Base64.decode(base64credentials.getBytes()));
            int colon = credentials.indexOf(':');
            String userid = credentials.substring(0, colon);
            String password = credentials.substring(colon + 1);
            Authorization subject = null;

            try {
                subject = login(request, userid, password);
            } catch (LoginException e) {
                return failAuthorization(request, response);
            }

            request.setAttribute(HttpContext.REMOTE_USER, userid);
            request.setAttribute(HttpContext.AUTHENTICATION_TYPE, authscheme);
            request.setAttribute(HttpContext.AUTHORIZATION, subject);
        } else {
            HttpSession session = request.getSession(true);
            if (queryString.startsWith(applicationWebAlias + "/conf")) {
                // this is a restricted area so performs login

                String a = request.getMethod();
                String submit = request.getParameter("submit");
                if (submit != null) {
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");
                    if (!allowUser(username, password)) {
                        return redirectToLoginPage(request, response);
                    } else {
                        session.putValue("logon.isDone", username);
                        try {
                            String target = (String) session.getValue("login.target");
                            if (target != null)
                                response.sendRedirect(target);
                            else {
                                response.sendRedirect(applicationWebAlias + "/conf/index.html");
                            }
                        } catch (Exception ignored) {
                            return false;
                        }
                    }
                } else {
                    if (queryString.equals(applicationWebAlias + "/conf/login.html")) {
                        return true;
                    } else {
                        //                     session.putValue("login.target", HttpUtils.getRequestURL(request).toString());
                        session.putValue("login.target", applicationWebAlias + "/conf/index.html");
                        Object done = session.getValue("logon.isDone");
                        if (done == null) {
                            if (request.getMethod().equals("GET")) {
                                return redirectToLoginPage(request, response);
                            } else {
                                response.sendError(HttpServletResponse.SC_FORBIDDEN);
                                return false;
                            }
                        }

                    }
                }
            }
        }
    }

    if (request.getRequestURI().endsWith(".png")) {
        response.setHeader("Cache-Control", "public, max-age=10000");
    }

    /*if (request.getRequestURI().endsWith(".js")) {
       response.setHeader("Pragma", "no-cache");
       response.setHeader("Cache-Control", "no-store");
       response.setHeader("Cache-Control", "public, max-age=0");
    }*/

    // response.addHeader(HttpServletResponse, arg1)

    return true;
}

From source file:com.wisemapping.mail.NotificationService.java

private void sendNotification(@NotNull Map<String, String> model, @Nullable User user,
        @NotNull HttpServletRequest request) {
    model.put("fullName", (user != null ? user.getFullName() : "'anonymous'"));
    final String userEmail = user != null ? user.getEmail() : "'anonymous'";

    model.put("email", userEmail);
    model.put("userAgent", request.getHeader(SupportedUserAgent.USER_AGENT_HEADER));
    model.put("server", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort());
    model.put("requestURI", request.getRequestURI());
    model.put("method", request.getMethod());
    model.put("remoteAddress", request.getRemoteAddr());

    try {// w w w.  j a v a2  s  .c  o m
        final String errorReporterEmail = mailer.getErrorReporterEmail();
        if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {

            if (!notificationFilter.hasBeenSend(userEmail, model)) {
                mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail,
                        "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"),
                        model, "errorNotification.vm");
            }
        }
    } catch (Exception e) {
        handleException(e);
    }
}

From source file:org.jahia.services.applications.pluto.JahiaPortalURLParserImpl.java

/**
 * Parse a servlet request to a portal URL.
 *
 * @return the portal URL.//from w  w  w  .  j a v  a  2s. com
 */
public PortalURL parse(HttpServletRequest request) {
    final String urlBase = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort();
    final String contextPath = request.getContextPath();
    final String servletName = request.getServletPath();
    final String pathInfo = request.getPathInfo();
    return parse(urlBase, contextPath, servletName, pathInfo, request.getParameter(PORTLET_INFO));
}

From source file:com.rometools.propono.atom.server.impl.FileBasedAtomHandler.java

/**
 * Contruct handler for one request, using specified file storage directory.
 *
 * @param req Request to be handled.//from   ww w . ja va 2  s . c  o  m
 * @param uploaddir File storage upload dir.
 */
public FileBasedAtomHandler(final HttpServletRequest req, final String uploaddir) {
    LOG.debug("ctor");

    userName = authenticateBASIC(req);

    atomProtocolURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            + req.getContextPath() + req.getServletPath();

    contextURI = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            + req.getContextPath();

    try {
        service = new FileBasedAtomService(userName, uploaddir, contextURI, req.getContextPath(),
                req.getServletPath());
    } catch (final Throwable t) {
        throw new RuntimeException("ERROR creating FileBasedAtomService", t);
    }
}

From source file:org.apache.beehive.netui.pageflow.scoping.internal.ScopedRequestImpl.java

public StringBuffer getRequestURL() {
    HttpServletRequest outerRequest = getOuterRequest();
    StringBuffer url = new StringBuffer(outerRequest.getScheme());
    url.append("://").append(outerRequest.getServerName());
    url.append(':').append(outerRequest.getServerPort());
    url.append(getRequestURI());/*from www .  j av  a  2s .  c  o m*/
    return url;
}

From source file:com.jaspersoft.jasperserver.war.util.StandardRequestMatcher.java

public boolean matches(HttpServletRequest request) {
    if (log.isDebugEnabled()) {
        log.debug("Matching request " + request + " against " + this);
    }//w  ww.  j  av  a  2  s  .com

    if (method != null && !matchesValue(request.getMethod(), method)) {
        if (log.isDebugEnabled()) {
            log.debug("Request method " + request.getMethod() + " does not match method " + method);
        }
        return false;
    }

    if (scheme != null && !matchesValue(request.getScheme(), scheme)) {
        if (log.isDebugEnabled()) {
            log.debug("Request scheme " + request.getScheme() + " does not match scheme " + scheme);
        }
        return false;
    }

    if (headers != null && !headers.isEmpty()) {
        for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
            String header = headerEntry.getKey();
            String headerPattern = headerEntry.getValue();
            String value = request.getHeader(header);
            if (!matchesValue(value, headerPattern)) {
                if (log.isDebugEnabled()) {
                    log.debug("Request header " + header + ": " + value + " does not match " + headerPattern);
                }
                return false;
            }
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("Request " + request + " matches " + this);
    }

    return true;
}

From source file:org.apache.ofbiz.base.util.UtilHttp.java

private static StringBuilder prepareServerRootUrl(HttpServletRequest request) {
    StringBuilder requestUrl = new StringBuilder();
    requestUrl.append(request.getScheme());
    requestUrl.append("://" + request.getServerName());
    if (request.getServerPort() != 80 && request.getServerPort() != 443)
        requestUrl.append(":" + request.getServerPort());
    return requestUrl;
}

From source file:org.apache.jetspeed.portlets.spaces.PageNavigator.java

public String getAbsoluteUrl(String relativePath, RenderResponse renderResponse, RequestContext rc) {
    // only rewrite a non-absolute url
    if (relativePath != null && relativePath.indexOf("://") == -1 && relativePath.indexOf("mailto:") == -1) {
        HttpServletRequest request = rc.getRequest();
        StringBuffer path = new StringBuffer();

        if (!rc.getPortalURL().isRelativeOnly()) {
            if (this.baseUrlAccess == null) {
                path.append(request.getScheme()).append("://").append(request.getServerName()).append(":")
                        .append(request.getServerPort());
            } else {
                path.append(baseUrlAccess.getServerScheme()).append("://").append(baseUrlAccess.getServerName())
                        .append(":").append(baseUrlAccess.getServerPort());
            }//from w ww . j  ava2  s  .  c om
        }

        return renderResponse.encodeURL(path.append(request.getContextPath()).append(request.getServletPath())
                .append(relativePath).toString());
    } else {
        return relativePath;
    }
}