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.fluidops.iwb.api.RequestMapperImpl.java

private String hostUrl(HttpServletRequest request) {
    return String.format("%s://%s:%s", request.getScheme(), request.getServerName(), request.getServerPort());
}

From source file:org.cloudfoundry.identity.uaa.security.web.CorsFilter.java

public String getRequestInfo(HttpServletRequest request) {
    return String.format("URI: %s; Scheme: %s; Host: %s; Port: %s; Origin: %s; Method: %s",
            request.getRequestURI(), request.getScheme(), request.getServerName(), request.getServerPort(),
            request.getHeader("Origin"), request.getMethod());
}

From source file:org.xine.marketplace.frontend.views.security.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Performs the redirect (or forward) to the login form URL.
 *//* w  ww  .  ja  v a  2 s  .co  m*/
@Override
public void commence(final HttpServletRequest request, final HttpServletResponse response,
        final AuthenticationException authException) throws IOException, ServletException {

    String redirectUrl = null;

    if (this.useForward) {

        if (this.forceHttps && "http".equals(request.getScheme())) {
            // First redirect the current request to HTTPS.
            // When that request is received, the forward to the login page will be used.
            redirectUrl = buildHttpsRedirectUrlForRequest(request);
        }

        if (redirectUrl == null) {
            final String loginForm = determineUrlToUseForThisRequest(request, response, authException);

            if (logger.isDebugEnabled()) {
                logger.debug("Server side forward to: " + loginForm);
            }

            final RequestDispatcher dispatcher = request.getRequestDispatcher(loginForm);

            dispatcher.forward(request, response);

            return;
        }
    } else {
        // redirect to login page. Use https if forceHttps true

        redirectUrl = buildRedirectUrlToLoginPage(request, response, authException);

    }

    this.redirectStrategy.sendRedirect(request, response, redirectUrl);
}

From source file:org.acegisecurity.captcha.CaptchaEntryPoint.java

private void buildInternalRedirect(StringBuffer redirectUrl, HttpServletRequest req) {
    // construct it
    StringBuffer simpleRedirect = new StringBuffer();

    String scheme = req.getScheme();
    String serverName = req.getServerName();
    int serverPort = portResolver.getServerPort(req);
    String contextPath = req.getContextPath();
    boolean includePort = true;

    if ("http".equals(scheme.toLowerCase()) && (serverPort == 80)) {
        includePort = false;/*from   w  w  w  .  j  a v  a2 s.c  om*/
    }

    if ("https".equals(scheme.toLowerCase()) && (serverPort == 443)) {
        includePort = false;
    }

    simpleRedirect.append(scheme);
    simpleRedirect.append("://");
    simpleRedirect.append(serverName);

    if (includePort) {
        simpleRedirect.append(":");
        simpleRedirect.append(serverPort);
    }

    simpleRedirect.append(contextPath);
    simpleRedirect.append(captchaFormUrl);

    if (forceHttps && req.getScheme().equals("http")) {
        Integer httpPort = new Integer(portResolver.getServerPort(req));
        Integer httpsPort = (Integer) portMapper.lookupHttpsPort(httpPort);

        if (httpsPort != null) {
            if (httpsPort.intValue() == 443) {
                includePort = false;
            } else {
                includePort = true;
            }

            redirectUrl.append("https://");
            redirectUrl.append(serverName);

            if (includePort) {
                redirectUrl.append(":");
                redirectUrl.append(httpsPort);
            }

            redirectUrl.append(contextPath);
            redirectUrl.append(captchaFormUrl);
        } else {
            redirectUrl.append(simpleRedirect);
        }
    } else {
        redirectUrl.append(simpleRedirect);
    }
}

From source file:org.daxplore.presenter.server.servlets.PresenterBrowserServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
    try {//from w  ww. j  av a2  s .  co  m
        if (welcomeTemplate == null) {
            try {
                welcomeTemplate = IOUtils
                        .toString(getServletContext().getResourceAsStream("/templates/welcome.html"));
            } catch (IOException e) {
                throw new InternalServerException("Failed to load the welcome template", e);
            }
        }

        String baseurl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();

        String[] arguments = { baseurl };

        String responseHTML = MessageFormat.format(welcomeTemplate, (Object[]) arguments);

        response.setContentType("text/html; charset=UTF-8");
        try (Writer writer = response.getWriter()) {
            writer.write(responseHTML);
        } catch (IOException e) {
            throw new InternalServerException("Failed to display presenter servlet", e);
        }
    } catch (InternalServerException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Unexpected exception: " + e.getMessage(), e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

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

/**
 * Contruct handler for one request, using specified file storage directory.
 * @param req       Request to be handled.
 * @param uploaddir File storage upload dir.
 *//*ww w .  ja  v a 2  s.c om*/
public FileBasedAtomHandler(HttpServletRequest req, 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 (Throwable t) {
        throw new RuntimeException("ERROR creating FileBasedAtomService", t);
    }
}

From source file:br.com.sg.security.SgLoginUrlAuthenticationEntryPoint.java

protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) {

    String loginForm = determineUrlToUseForThisRequest(request, response, authException);
    Integer serverPort = portResolver.getServerPort(request);
    String scheme = request.getScheme();

    RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();

    urlBuilder.setScheme(scheme);/*w  w  w  . j a  v  a2s . co  m*/
    urlBuilder.setServerName(request.getServerName());
    urlBuilder.setPort(serverPort);
    urlBuilder.setContextPath(request.getContextPath());
    urlBuilder.setPathInfo(loginForm);

    if (forceHttps && "http".equals(scheme)) {
        Integer httpsPort = portMapper.lookupHttpsPort(new Integer(serverPort));

        if (httpsPort != null) {
            // Overwrite scheme and port in the redirect URL
            urlBuilder.setScheme("https");
            urlBuilder.setPort(httpsPort.intValue());
        } else {
            logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort);
        }

    }

    return urlBuilder.getUrl();
}

From source file:com.music.web.AuthenticationController.java

@RequestMapping("/persona/auth")
@ResponseBody//from   w w  w .  java  2  s .c o m
public String authenticateWithPersona(@RequestParam String assertion,
        @RequestParam boolean userRequestedAuthentication, HttpServletRequest request,
        HttpServletResponse httpResponse, Model model) throws IOException {
    if (context.getUser() != null) {
        return "";
    }
    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("assertion", assertion);
    params.add("audience", request.getScheme() + "://" + request.getServerName() + ":"
            + (request.getServerPort() == 80 ? "" : request.getServerPort()));
    PersonaVerificationResponse response = restTemplate.postForObject(
            "https://verifier.login.persona.org/verify", params, PersonaVerificationResponse.class);
    if (response.getStatus().equals("okay")) {
        User user = userService.getUserByEmail(response.getEmail());
        if (user == null && userRequestedAuthentication) {
            return "/socialSignUp?email=" + response.getEmail();
        } else if (user != null) {
            if (userRequestedAuthentication || user.isLoginAutomatically()) {
                signInAdapter.signIn(user, httpResponse, true);
                return "/";
            } else {
                return "";
            }
        } else {
            return ""; //in case this is not a user-requested operation, do nothing
        }
    } else {
        logger.warn("Persona authentication failed due to reason: " + response.getReason());
        throw new IllegalStateException("Authentication failed");
    }
}

From source file:com.baoqilai.core.sso.CasAuthenticationEntryPoint.java

public final void commence(final HttpServletRequest servletRequest, final HttpServletResponse response,
        final AuthenticationException authenticationException) throws IOException, ServletException {
    StringBuilder tempLoginUrl = new StringBuilder();
    StringBuilder serverUrl = new StringBuilder();
    StringBuilder clientUrl = new StringBuilder();
    System.out.println("???");
    tempLoginUrl.append(servletRequest.getScheme()).append("://");
    tempLoginUrl.append(servletRequest.getServerName());

    if (serverPort != null && !"".equals(serverPort)) {
        serverUrl.append(tempLoginUrl).append(":").append(serverPort);
    }//from   w ww .  j  a v a 2 s  .  c o  m
    serverUrl.append("/cas/login");
    loginUrl = serverUrl.toString();

    if (clientPort != null && !"".equals(clientPort)) {
        clientUrl.append(tempLoginUrl).append(":").append(servletRequest.getServerPort());
        clientUrl.append(servletRequest.getContextPath());
        clientUrl.append("/j_spring_cas_security_check");
        serviceProperties.setService(clientUrl.toString());
    }

    final String urlEncodedService = createServiceUrl(servletRequest, response);
    final String redirectUrl = createRedirectUrl(urlEncodedService);

    preCommence(servletRequest, response);
    response.sendRedirect(redirectUrl);
}

From source file:dk.itst.oiosaml.sp.configuration.ConfigurationHandler.java

private String getEntityId(HttpServletRequest request) {
    return request.getScheme() + "://saml." + request.getServerName();
}