List of usage examples for org.springframework.security.web.util RedirectUrlBuilder setQuery
public void setQuery(String query)
From source file:br.com.flucianofeijao.security.JsfLoginUrlAuthenticationEntryPoint.java
/** * Builds a URL to redirect the supplied request to HTTPS. Used to redirect the current request * to HTTPS, before doing a forward to the login page. *//*from w w w .jav a 2 s . co m*/ protected String buildHttpsRedirectUrlForRequest(HttpServletRequest request) throws IOException, ServletException { int serverPort = portResolver.getServerPort(request); Integer httpsPort = portMapper.lookupHttpsPort(Integer.valueOf(serverPort)); if (httpsPort != null) { RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme("https"); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(httpsPort.intValue()); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setServletPath(request.getServletPath()); urlBuilder.setPathInfo(request.getPathInfo()); urlBuilder.setQuery(request.getQueryString()); return urlBuilder.getUrl(); } // Fall through to server-side forward with warning message logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); return null; }
From source file:br.com.gerenciapessoal.security.JsfLoginUrlAuthenticationEntryPoint.java
/** * Builds a URL to redirect the supplied request to HTTPS. Used to redirect * the current request to HTTPS, before doing a forward to the login page. * * @param request//from w ww . ja va 2 s . c om * @return * @throws java.io.IOException * @throws javax.servlet.ServletException */ protected String buildHttpsRedirectUrlForRequest(HttpServletRequest request) throws IOException, ServletException { int serverPort = portResolver.getServerPort(request); Integer httpsPort = portMapper.lookupHttpsPort(serverPort); if (httpsPort != null) { RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme("https"); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(httpsPort); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setServletPath(request.getServletPath()); urlBuilder.setPathInfo(request.getPathInfo()); urlBuilder.setQuery(request.getQueryString()); return urlBuilder.getUrl(); } // Fall through to server-side forward with warning message logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); return null; }
From source file:org.xine.marketplace.frontend.views.security.JsfLoginUrlAuthenticationEntryPoint.java
/** * Builds a URL to redirect the supplied request to HTTPS. Used to redirect the current request * to HTTPS, before doing a forward to the login page. *//* ww w . j a v a2 s. c o m*/ protected String buildHttpsRedirectUrlForRequest(final HttpServletRequest request) throws IOException, ServletException { final int serverPort = this.portResolver.getServerPort(request); final Integer httpsPort = this.portMapper.lookupHttpsPort(Integer.valueOf(serverPort)); if (httpsPort != null) { final RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme("https"); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(httpsPort.intValue()); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setServletPath(request.getServletPath()); urlBuilder.setPathInfo(request.getPathInfo()); urlBuilder.setQuery(request.getQueryString()); return urlBuilder.getUrl(); } // Fall through to server-side forward with warning message logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); return null; }
From source file:br.com.sg.security.SgLoginUrlAuthenticationEntryPoint.java
/** * Builds a URL to redirect the supplied request to HTTPS. Used to redirect * the current request to HTTPS, before doing a forward to the login page. *///w w w .j ava2 s .c om protected String buildHttpsRedirectUrlForRequest(HttpServletRequest request) throws IOException, ServletException { Integer serverPort = portResolver.getServerPort(request); Integer httpsPort = portMapper.lookupHttpsPort(new Integer(serverPort)); if (httpsPort != null) { RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme("https"); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(httpsPort.intValue()); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setServletPath(request.getServletPath()); urlBuilder.setPathInfo(request.getPathInfo()); urlBuilder.setQuery(request.getQueryString()); return urlBuilder.getUrl(); } // Fall through to server-side forward with warning message logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); return null; }
From source file:org.opendatakit.common.security.spring.RedirectingLoginUrlAuthenticationEntryPoint.java
protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (UrlUtils.isAbsoluteUrl(loginForm)) { return loginForm; }/*from ww w. j a v a 2s . c o m*/ int serverPort = getPortResolver().getServerPort(request); String scheme = request.getScheme(); RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme(scheme); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(serverPort); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setPathInfo(loginForm); try { String fullRequest = request.getRequestURL().toString(); if (request.getQueryString() != null) { fullRequest += "?" + request.getQueryString(); } String redirectParam = "redirect=" + URLEncoder.encode(fullRequest, "UTF-8"); urlBuilder.setQuery(redirectParam); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (isForceHttps() && "http".equals(scheme)) { Integer httpsPort = getPortMapper().lookupHttpsPort(Integer.valueOf(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(); }