List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:org.apache.hadoop.hdfsproxy.LdapIpDirFilter.java
/** {@inheritDoc} */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String prevThreadName = Thread.currentThread().getName(); try {//from www. j a va 2 s. c o m Thread.currentThread().setName(contextPath); HttpServletRequest rqst = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; if (LOG.isDebugEnabled()) { StringBuilder b = new StringBuilder("Request from ").append(rqst.getRemoteHost()).append("/") .append(rqst.getRemoteAddr()).append(":").append(rqst.getRemotePort()); b.append("\n The Scheme is " + rqst.getScheme()); b.append("\n The Path Info is " + rqst.getPathInfo()); b.append("\n The Translated Path Info is " + rqst.getPathTranslated()); b.append("\n The Context Path is " + rqst.getContextPath()); b.append("\n The Query String is " + rqst.getQueryString()); b.append("\n The Request URI is " + rqst.getRequestURI()); b.append("\n The Request URL is " + rqst.getRequestURL()); b.append("\n The Servlet Path is " + rqst.getServletPath()); LOG.debug(b.toString()); } LdapRoleEntry ldapent = new LdapRoleEntry(); // check ip address String userIp = rqst.getRemoteAddr(); try { boolean isAuthorized = getLdapRoleEntryFromUserIp(userIp, ldapent); if (!isAuthorized) { rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "IP " + userIp + " is not authorized to access"); return; } } catch (NamingException ne) { throw new IOException("NamingException while searching ldap" + ne.toString()); } // since we cannot pass ugi object cross context as they are from // different classloaders in different war file, we have to use String attribute. rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.userID", ldapent.userId); rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.paths", ldapent.paths); LOG.info("User: " + ldapent.userId + " Request: " + rqst.getPathInfo() + " From: " + rqst.getRemoteAddr()); chain.doFilter(request, response); } finally { Thread.currentThread().setName(prevThreadName); } }
From source file:de.goldbachinteractive.gbi.redirecthandler.client.Error404HandlerServlet.java
/** * Requests the configured redirect processors randomly for redirect until a * redirect found. Uses the default 404 page if no redirect available. * /*from w w w.j a v a2s. c om*/ * @param request * The original request. * @param response * The processed response. * @throws UnsupportedEncodingException * Thrown, if encoding the request URL to UTF-8 failed. */ public void redirect(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { CloseableHttpClient httpClient = HttpClients.createDefault(); String path = (String) request.getAttribute("javax.servlet.error.request_uri"); String host = request.getHeader("host"); String scheme = request.getScheme(); // to use absolute url with scheme String requestUri = scheme + "://" + host + path; // the url must be encoded requestUri = URLEncoder.encode(requestUri, ENCODING_UTF8); // copy redirect dispatcher URLs, because we manipulate this list for // random access List<String> dispatcherUrls = new ArrayList<String>(redirectProcessorUrls); int urlCount = dispatcherUrls.size(); while (urlCount > 0) { // use a random redirect processor Random random = new Random(); int position = random.nextInt(urlCount); String processorUrl = dispatcherUrls.remove(position); // build the request url to the redirect processor String redirectRequestUrl = String.format("%s?r=%s", processorUrl, requestUri); // ask for redirect, returns with true on redirected, and false if // no redirect found if (redirectRequest(redirectRequestUrl, httpClient, request, response, timeout)) { logger.info("redirected"); return; } urlCount--; } // we did not found a redirect, so use the default 404 page, configured redirectDefault404Page(request, response); }
From source file:org.archive.wayback.proxy.ProxyReplayRequestParser.java
@Override public WaybackRequest parse(HttpServletRequest httpRequest, AccessPoint wbContext) throws BadQueryException { if (isLocalRequest(httpRequest)) { // local means query: let the following RequestParsers have a go // at it. return null; }/*w w w . j a v a2 s . c o m*/ WaybackRequest wbRequest = null; String requestServer = httpRequest.getServerName(); String requestPath = httpRequest.getRequestURI(); //int port = httpRequest.getServerPort(); String requestQuery = httpRequest.getQueryString(); String requestScheme = httpRequest.getScheme(); if (requestQuery != null) { requestPath = requestPath + "?" + requestQuery; } String requestUrl = requestScheme + "://" + requestServer + requestPath; wbRequest = new WaybackRequest(); try { wbRequest.setRequestUrl(requestUrl); } catch (URIException e) { e.printStackTrace(); return null; } wbRequest.put(WaybackConstants.REQUEST_TYPE, WaybackConstants.REQUEST_REPLAY_QUERY); return wbRequest; }
From source file:net.paulgray.mocklti2.tools.LtiToolController.java
@RequestMapping(value = "/api/profile", method = RequestMethod.GET) public ResponseEntity getConsumerProfile(HttpServletRequest request, HttpServletResponse response, @RequestParam String toolId) { response.setHeader("Content-type", "application/vnd.ims.lti.v2.ToolConsumerProfile+json"); ToolConsumer me = new ToolConsumer("guid", "version", "tcp", config); me.addCapabilites(Arrays.asList(LtiCapability.BASICLTI_LAUNCH, LtiCapability.USER_ID, LtiCapability.USER_IMAGE, LtiCapability.COURSE_SECTION_ID, LtiCapability.MEMBERSHIP_ROLE)); String endpoint = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/api/tool_proxy_registration?toolId=" + toolId; me.addServiceOffered(new ServiceOffered(endpoint, "tcp:ToolProxy.collection", "RestService", ToolProxy.CONTENT_TYPE, "POST")); return new ResponseEntity(me, HttpStatus.OK); }
From source file:org.fluxtream.core.auth.FlxLoginUrlAuthenticationEntryPoint.java
protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (UrlUtils.isAbsoluteUrl(loginForm)) { return loginForm; }/* www . j av a2 s .c om*/ int serverPort = portResolver.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); if (forceHttps && "http".equals(scheme)) { Integer httpsPort = portMapper.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(); }
From source file:eionet.util.SecurityUtil.java
/** * * @param request//from ww w .j a v a 2s.com * @return */ public static String getLoginURL(HttpServletRequest request) { // Legacy login mechanism. Used if the application is configured to not use Central Authentication Service (CAS). //String result = "javascript:login('" + request.getContextPath() + "')"; String result = request.getContextPath() + "/" + LoginServlet.LOGIN_JSP; boolean rememberAfterLoginUrl = false; if (Props.isUseCentralAuthenticationService()) { CASFilterConfig casFilterConfig = CASFilterConfig.getInstance(); if (casFilterConfig != null) { String casLoginUrl = casFilterConfig.getInitParameter(CASFilter.LOGIN_INIT_PARAM); if (casLoginUrl != null) { String casServerName = casFilterConfig.getInitParameter(CASFilter.SERVERNAME_INIT_PARAM); if (casServerName == null) { throw new DDRuntimeException("If " + CASFilter.LOGIN_INIT_PARAM + " context parameter has been specified, so must be " + CASFilter.SERVERNAME_INIT_PARAM); } rememberAfterLoginUrl = true; try { result = casLoginUrl + "?service=" + URLEncoder.encode( request.getScheme() + "://" + casServerName + request.getContextPath() + "/login", "UTF-8"); } catch (UnsupportedEncodingException e) { throw new DDRuntimeException(e.toString(), e); } } } } else { String servletPath = request.getServletPath(); if (servletPath == null || !servletPath.endsWith(LoginServlet.LOGIN_JSP)) { rememberAfterLoginUrl = true; } } if (rememberAfterLoginUrl) { String requestURL = request.getRequestURL().toString(); if (requestURL != null && !AfterCASLoginServlet.isSkipUrl(requestURL)) { request.getSession().setAttribute(AfterCASLoginServlet.AFTER_LOGIN_ATTR_NAME, buildAfterLoginURL(request)); } } return result; }
From source file:org.alfresco.web.ui.repo.tag.PageTag.java
/** * Please ensure you understand the terms of the license before changing the contents of this file. *///from w w w .j a v a2s . c o m private String getAlfrescoButton() { if (PageTag.alfresco == null) { final HttpServletRequest req = (HttpServletRequest) pageContext.getRequest(); PageTag.alfresco = ("<center><table style='margin: 0px auto;'><tr><td>" + "<a href='" + ALF_URL + "'>" + "<img style='vertical-align:middle;border-width:0px;' width='176' height='26' alt='' title='" + ALF_TEXT + "' src='" + ("http".equals(req.getScheme()) ? ALF_LOGO_HTTP : ALF_LOGO_HTTPS) + "'>" + "</a></td><td align='center'>" + "<span class='footer'>" + ALF_COPY + "</span></td><td></td></tr></table></center>"); } return PageTag.alfresco; }
From source file:com.identityconcepts.shibboleth.WSFedLoginHandler.java
/** * return URL to which redirect will be done * depending on the X509 handler configuration, * a full URL will be used or a path in the web app * * @param request HTTPServletRequest//from w ww .ja va2 s .c o m * @return URL for redirection */ private String getRedirectURL(HttpServletRequest request, String url) { URLBuilder urlBuilder = null; // if URL configured if (url.startsWith("http")) { urlBuilder = new URLBuilder(url); } else { // if path configured log.debug("No URL configured in loginPageURL: {}", url); StringBuilder pathBuilder = new StringBuilder(); urlBuilder = new URLBuilder(); urlBuilder.setScheme(request.getScheme()); urlBuilder.setHost(request.getServerName()); // set port if not standard port if (!(request.getScheme().equals("http")) || (request.getScheme().equals("https"))) { urlBuilder.setPort(request.getServerPort()); } pathBuilder.append(request.getContextPath()); if (!loginPageURL.startsWith("/")) { pathBuilder.append("/"); } pathBuilder.append(url); urlBuilder.setPath(pathBuilder.toString()); } return urlBuilder.buildURL(); }
From source file:br.com.sg.security.SgLoginUrlAuthenticationEntryPoint.java
/** * Performs the redirect (or forward) to the login form URL. *///from w w w . j a v a 2 s .c o m public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String redirectUrl = null; if (useForward) { if (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(httpRequest); } if (redirectUrl == null) { String loginForm = determineUrlToUseForThisRequest(httpRequest, httpResponse, authException); if (logger.isDebugEnabled()) { logger.debug("Server side forward to: " + loginForm); } RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(loginForm); dispatcher.forward(request, response); return; } } else { // redirect to login page. Use https if forceHttps true redirectUrl = buildRedirectUrlToLoginPage(httpRequest, httpResponse, authException); } redirectStrategy.sendRedirect(httpRequest, httpResponse, redirectUrl); }
From source file:org.xine.marketplace.frontend.views.security.JsfLoginUrlAuthenticationEntryPoint.java
protected String buildRedirectUrlToLoginPage(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) { final String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (UrlUtils.isAbsoluteUrl(loginForm)) { return loginForm; }/* w ww . j a v a 2 s. c om*/ final int serverPort = this.portResolver.getServerPort(request); final String scheme = request.getScheme(); final RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme(scheme); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(serverPort); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setPathInfo(loginForm); if (this.forceHttps && "http".equals(scheme)) { final Integer httpsPort = this.portMapper.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(); }