List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:br.com.flucianofeijao.security.JsfLoginUrlAuthenticationEntryPoint.java
/** * Performs the redirect (or forward) to the login form URL. *///www . jav a2s .c o m public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 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(request); } if (redirectUrl == null) { String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (logger.isDebugEnabled()) { logger.debug("Server side forward to: " + loginForm); } 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); } redirectStrategy.sendRedirect(request, response, redirectUrl); }
From source file:com.google.step2.example.consumer.servlet.LoginServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { log.info("Login Servlet Post"); // posted means they're sending us an OpenID4 StringBuffer realmBuf = new StringBuffer(req.getScheme()).append("://").append(req.getServerName()); if ((req.getScheme().equalsIgnoreCase("http") && req.getServerPort() != 80) || (req.getScheme().equalsIgnoreCase("https") && req.getServerPort() != 443)) { realmBuf.append(":").append(req.getServerPort()); }//from w w w . j a va2 s .c o m String realm = realmBuf.toString(); String returnToUrl = new StringBuffer(realm).append(req.getContextPath()).append(REDIRECT_PATH).toString(); // this is magic - normally this would also fall out of the discovery: OAuthAccessor accessor = null; // Fetch an unauthorized OAuth request token to test authorizing if (YES_STRING.equals(req.getParameter("oauth"))) { try { accessor = providerStore.getOAuthAccessor("google"); accessor = oauthConsumerUtil.getRequestToken(accessor); // TODO(sweis): Put this string contstant somewhere that makes sense String oauthTestEndpoint = (String) accessor.getProperty("oauthTestEndpoint"); if (oauthTestEndpoint != null) { realm = oauthTestEndpoint; returnToUrl = oauthTestEndpoint; } } catch (ProviderInfoNotFoundException e) { throw new ServletException(e); } catch (OAuthException e) { throw new ServletException(e); } catch (URISyntaxException e) { throw new ServletException(e); } } // we assume that the user typed an identifier for an IdP, not for a user IdpIdentifier openId = new IdpIdentifier(req.getParameter("openid")); AuthRequestHelper helper = consumerHelper.getAuthRequestHelper(openId, returnToUrl.toString()); helper.requestUxIcon(true); if (accessor != null) { log.debug("Requesting OAuth scope : " + (String) accessor.getProperty("scope")); helper.requestOauthAuthorization(accessor.consumer.consumerKey, (String) accessor.getProperty("scope")); } if (YES_STRING.equals(req.getParameter("email"))) { log.debug("Requesting AX email"); helper.requestAxAttribute(Step2.AxSchema.EMAIL, true); } if (YES_STRING.equals(req.getParameter("country"))) { log.debug("Requesting AX country"); helper.requestAxAttribute(Step2.AxSchema.COUNTRY, true); } if (YES_STRING.equals(req.getParameter("language"))) { log.debug("Requesting AX country"); helper.requestAxAttribute(Step2.AxSchema.LANGUAGE, true); } if (YES_STRING.equals(req.getParameter("firstName"))) { log.debug("Requesting AX country"); helper.requestAxAttribute(Step2.AxSchema.FIRST_NAME, true); } if (YES_STRING.equals(req.getParameter("lastName"))) { log.debug("Requesting AX country"); helper.requestAxAttribute(Step2.AxSchema.LAST_NAME, true); } HttpSession session = req.getSession(); AuthRequest authReq = null; try { authReq = helper.generateRequest(); authReq.setRealm(realm); // add PAPE, if requested if (YES_STRING.equals(req.getParameter("reauth"))) { log.debug("Requesting PAPE reauth"); PapeRequest pape = PapeRequest.createPapeRequest(); pape.setMaxAuthAge(1); authReq.addExtension(pape); } session.setAttribute("discovered", helper.getDiscoveryInformation()); } catch (DiscoveryException e) { StringBuffer errorMessage = new StringBuffer("Could not discover OpenID endpoint."); errorMessage.append("\n\n").append("Check if URL is valid: "); errorMessage.append(openId).append("\n\n"); errorMessage.append("Stack Trace:\n"); for (StackTraceElement s : e.getStackTrace()) { errorMessage.append(s.toString()).append('\n'); } resp.sendError(400, errorMessage.toString()); return; } catch (MessageException e) { throw new ServletException(e); } catch (ConsumerException e) { throw new ServletException(e); } if (YES_STRING.equals(req.getParameter("usePost"))) { // using POST req.setAttribute("message", authReq); RequestDispatcher d = req.getRequestDispatcher("/WEB-INF/formredirection.jsp"); d.forward(req, resp); } else { // using GET resp.sendRedirect(authReq.getDestinationUrl(true)); } }
From source file:br.com.wavii.securyti.JsfLoginUrlAuthenticationEntryPoint.java
/** * Performs the redirect (or forward) to the login form URL. */// ww w . j a v a 2 s .c o m public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 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(request); } if (redirectUrl == null) { String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (logger.isDebugEnabled()) { logger.debug("Server side forward to: " + loginForm); } 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); } redirectStrategy.sendRedirect(request, response, redirectUrl); }
From source file:com.yoshio3.modules.AzureADServerAuthModule.java
private String getCurrentUri(HttpServletRequest request) { String scheme = request.getScheme(); int serverPort = request.getServerPort(); String portNumberString = ""; if (!((scheme.equals("http") && serverPort == 80) || (scheme.equals("https") && serverPort == 443))) { portNumberString = ":" + String.valueOf(serverPort); }/* w ww. ja va 2 s. co m*/ String uri = scheme + "://" + request.getServerName() + portNumberString + request.getRequestURI(); return uri; }
From source file:X509Snoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); X509Certificate[] certs = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate"); if (certs != null) { for (int i = 0; i < certs.length; i++) { out.println("Client Certificate [" + i + "] = " + certs[i].toString()); }/* w w w.j av a 2 s .c om*/ } else { if ("https".equals(req.getScheme())) { out.println("This was an HTTPS request, " + "but no client certificate is available"); } else { out.println("This was not an HTTPS request, " + "so no client certificate is available"); } } }
From source file:br.com.gerenciapessoal.security.JsfLoginUrlAuthenticationEntryPoint.java
/** * Performs the redirect (or forward) to the login form URL. * * @param request// w w w. j av a 2 s . com * @param response * @param authException * @throws java.io.IOException * @throws javax.servlet.ServletException */ @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 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(request); } if (redirectUrl == null) { String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (logger.isDebugEnabled()) { logger.debug("Server side forward to: " + loginForm); } 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); } redirectStrategy.sendRedirect(request, response, redirectUrl); }
From source file:it.greenvulcano.gvesb.debug.DebuggerServlet.java
private void dump(HttpServletRequest request, StringBuffer log) throws IOException { String hN;/*from ww w . j a v a 2s . c o m*/ log.append("-- DUMP HttpServletRequest START").append("\n"); log.append("Method : ").append(request.getMethod()).append("\n"); log.append("RequestedSessionId : ").append(request.getRequestedSessionId()).append("\n"); log.append("Scheme : ").append(request.getScheme()).append("\n"); log.append("IsSecure : ").append(request.isSecure()).append("\n"); log.append("Protocol : ").append(request.getProtocol()).append("\n"); log.append("ContextPath : ").append(request.getContextPath()).append("\n"); log.append("PathInfo : ").append(request.getPathInfo()).append("\n"); log.append("QueryString : ").append(request.getQueryString()).append("\n"); log.append("RequestURI : ").append(request.getRequestURI()).append("\n"); log.append("RequestURL : ").append(request.getRequestURL()).append("\n"); log.append("ContentType : ").append(request.getContentType()).append("\n"); log.append("ContentLength : ").append(request.getContentLength()).append("\n"); log.append("CharacterEncoding : ").append(request.getCharacterEncoding()).append("\n"); log.append("---- Headers START\n"); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { hN = headerNames.nextElement(); log.append("[" + hN + "]="); Enumeration<String> headers = request.getHeaders(hN); while (headers.hasMoreElements()) { log.append("[" + headers.nextElement() + "]"); } log.append("\n"); } log.append("---- Headers END\n"); log.append("---- Body START\n"); log.append(IOUtils.toString(request.getInputStream(), "UTF-8")).append("\n"); log.append("---- Body END\n"); log.append("-- DUMP HttpServletRequest END \n"); }
From source file:gov.nih.nci.cabig.caaers.web.admin.InvestigatorImporter.java
public void save(ImportCommand command, HttpServletRequest request) { List<DomainObjectImportOutcome<Investigator>> importableInvestigators = command .getImportableInvestigators(); for (DomainObjectImportOutcome<Investigator> importOutcome : importableInvestigators) { try {//from w w w. java 2 s . c o m investigatorRepository.save(importOutcome.getImportedDomainObject(), ResetPasswordController.getURL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath())); } catch (MailException mEx) { logger.warn("Exception while sending email to Investigator", mEx); } } // CAAERS-4461 if (CollectionUtils.isNotEmpty(importableInvestigators)) getEventFactory().publishEntityModifiedEvent(new LocalInvestigator(), true); }
From source file:gov.nih.nci.cabig.caaers.web.admin.ResearchStaffImporter.java
public void save(ImportCommand command, HttpServletRequest request) { List<DomainObjectImportOutcome<ResearchStaff>> importableResearchStaff = command .getImportableResearchStaff(); for (DomainObjectImportOutcome<ResearchStaff> importOutcome : importableResearchStaff) { try {//w w w. jav a 2 s .c o m researchStaffRepository.save(importOutcome.getImportedDomainObject(), ResetPasswordController.getURL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath())); } catch (MailException mEx) { logger.warn("Exception wile sending email to ResearchStaff", mEx); } } // CAAERS-4461 if (CollectionUtils.isNotEmpty(importableResearchStaff)) getEventFactory().publishEntityModifiedEvent(new LocalResearchStaff(), true); }
From source file:com.linkcm.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(); tempLoginUrl.append(servletRequest.getScheme()).append("://"); tempLoginUrl.append(servletRequest.getServerName()); if (serverPort != null && !"".equals(serverPort)) { serverUrl.append(tempLoginUrl).append(":").append(serverPort); }/* w w w. j av a 2s .com*/ 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); }