List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.Cas2Authenticator.java
public Boolean handleLogout(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { log.debug(String.format("handleLogout %s", httpRequest.getRequestURL().toString())); if (logoutURL == null || logoutURL.equals("")) { log.debug("No CAS logout params, skipping CAS2Logout"); return false; }// ww w . jav a 2s . co m try { httpResponse.sendRedirect(getServiceURL(httpRequest, LOGOUT_ACTION)); } catch (IOException e) { log.error("Unable to redirect to CAS logout screen:", e); return false; } return true; }
From source file:com.erudika.para.security.FacebookAuthFilter.java
/** * Handles an authentication request.//w ww . j a v a2s . c om * @param request HTTP request * @param response HTTP response * @return an authentication object that contains the principal object if successful. * @throws IOException ex */ @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException { final String requestURI = request.getRequestURI(); UserAuthentication userAuth = null; if (requestURI.endsWith(FACEBOOK_ACTION)) { String authCode = request.getParameter("code"); if (!StringUtils.isBlank(authCode)) { String url = Utils.formatMessage(TOKEN_URL, authCode, request.getRequestURL().toString(), Config.FB_APP_ID, Config.FB_SECRET); HttpGet tokenPost = new HttpGet(url); CloseableHttpResponse resp1 = httpclient.execute(tokenPost); if (resp1 != null && resp1.getEntity() != null) { String token = EntityUtils.toString(resp1.getEntity(), Config.DEFAULT_ENCODING); if (token != null && token.startsWith("access_token")) { String accessToken = token.substring(token.indexOf("=") + 1, token.indexOf("&")); userAuth = getOrCreateUser(null, accessToken); } EntityUtils.consumeQuietly(resp1.getEntity()); } } } User user = SecurityUtils.getAuthenticatedUser(userAuth); if (userAuth == null || user == null || user.getIdentifier() == null) { throw new BadCredentialsException("Bad credentials."); } else if (!user.getActive()) { throw new LockedException("Account is locked."); } return userAuth; }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.SecurityExceptionHandler.java
protected String getURLToReach(HttpServletRequest request) { log.debug(String.format("getURLToReach#urlToReach")); DocumentView docView = (DocumentView) request.getAttribute(URLPolicyService.DOCUMENT_VIEW_REQUEST_KEY); if (docView != null) { String urlToReach = getURLPolicyService().getUrlFromDocumentView(docView, ""); if (urlToReach != null) { return urlToReach; }// w w w . j ava 2 s . co m } log.debug(String.format("getURLToReach#urlToReach#%s?%s", request.getRequestURL().toString(), request.getQueryString())); return request.getRequestURL().toString() + "?" + request.getQueryString(); }
From source file:org.osiam.addons.self_administration.registration.RegistrationService.java
public void sendRegistrationEmail(User user, HttpServletRequest request) { Optional<Email> email = SCIMHelper.getPrimaryOrFirstEmail(user); if (!email.isPresent()) { String message = "Could not register user. No email of user " + user.getUserName() + " found!"; throw new InvalidAttributeException(message, "registration.exception.noEmail"); }// w w w . j av a 2 s . c om StringBuffer requestURL = request.getRequestURL().append("/activation"); String activationToken = user.getExtension(internalScimExtensionUrn).getFieldAsString(activationTokenField); String registrationLink = SelfAdministrationHelper.createLinkForEmail(requestURL.toString(), user.getId(), "activationToken", activationToken); Map<String, Object> mailVariables = new HashMap<>(); mailVariables.put("registrationLink", registrationLink); mailVariables.put("user", user); Locale locale = SelfAdministrationHelper.getLocale(user.getLocale()); renderAndSendEmailService.renderAndSendEmail("registration", fromAddress, email.get().getValue(), locale, mailVariables); }
From source file:com.ibm.jaggr.service.impl.transport.AbstractHttpTransport.java
/** * This method checks the request for the has conditions which may either be contained in URL * query arguments or in a cookie sent from the client. * /* w w w.ja v a 2s . c o m*/ * @return The has conditions from the request. * @throws UnsupportedEncodingException */ protected static String getHasConditionsFromRequest(HttpServletRequest request) throws IOException { String ret = null; if (request.getParameter(FEATUREMAPHASH_REQPARAM) != null) { // The cookie called 'has' contains the has conditions Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; ret == null && i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(FEATUREMAP_REQPARAM) && cookie.getValue() != null) { ret = URLDecoder.decode(cookie.getValue(), "US-ASCII"); //$NON-NLS-1$ break; } } } if (ret == null) { if (log.isLoggable(Level.WARNING)) { StringBuffer url = request.getRequestURL(); if (url != null) { // might be null if using mock request for unit testing url.append("?").append(request.getQueryString()).toString(); //$NON-NLS-1$ log.warning(MessageFormat.format(Messages.AbstractHttpTransport_0, new Object[] { url, request.getHeader("User-Agent") })); //$NON-NLS-1$ } } } } else ret = request.getParameter(FEATUREMAP_REQPARAM); return ret; }
From source file:org.ocpsoft.rewrite.servlet.config.proxy.ProxyServlet.java
/** * For a redirect response from the target server, this translates {@code theUrl} to redirect to and translates it to * one the original client can use.// w w w . j a va2 s.c o m */ protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) { /* * TODO document example paths */ if (theUrl.startsWith(targetUri)) { String curUrl = servletRequest.getRequestURL().toString();// no query String pathInfo = servletRequest.getPathInfo(); if (pathInfo != null) { assert curUrl.endsWith(pathInfo); curUrl = curUrl.substring(0, curUrl.length() - pathInfo.length());// take pathInfo off } theUrl = curUrl + theUrl.substring(targetUri.length()); } return theUrl; }
From source file:org.artifactory.webapp.servlet.RepoFilter.java
private boolean isGitLfsRequest(HttpServletRequest request) { String lfsApiPath = "/api/" + GitLfsResourceConstants.PATH_ROOT; String joinedRequestPath = request.getServletPath() + request.getPathInfo(); return joinedRequestPath.contains(lfsApiPath) || request.getRequestURL().toString().contains(lfsApiPath); }
From source file:com.ctc.storefront.filters.cms.CMSSiteFilter.java
/** * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit) * <p/>//from w w w . ja v a 2 s. co m * <b>Note:</b> <br/> * We preparing application by setting correct: * <ul> * <li>Current Site</li> * <li>Current Catalog Versions</li> * <li>Enabled language fallback</li> * </ul> * * @see ContextInformationLoader#initializeSiteFromRequest(String) * @see ContextInformationLoader#setCatalogVersions() * @param httpRequest * current request * @param httpResponse * the http response * @throws java.io.IOException */ protected boolean processNormalRequest(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws IOException { final String queryString = httpRequest.getQueryString(); final String currentRequestURL = httpRequest.getRequestURL().toString(); //set current site CMSSiteModel cmsSiteModel = getCurrentCmsSite(); if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) { final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/") + (StringUtils.isBlank(queryString) ? "" : "?" + queryString); cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL); } if (cmsSiteModel == null) { // Failed to lookup CMS site httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE); return false; } else if (!getSiteChannelValidationStrategy().validateSiteChannel(cmsSiteModel.getChannel())) // Restrict to configured channel { // CMS site that we looked up was for an unsupported channel httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE); return false; } if (!isActiveSite(cmsSiteModel)) { throw new IllegalStateException( "Site is not active. Active flag behaviour must be implement for this project."); } getContextInformationLoader().setCatalogVersions(); //set fall back language enabled setFallbackLanguage(httpRequest, Boolean.TRUE); return true; }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.Cas2Authenticator.java
protected String checkProxyCasTicket(String ticket, HttpServletRequest httpRequest) { log.debug(String.format("checkProxyCasTicket %s", httpRequest.getRequestURL().toString())); String service = httpRequest.getParameter(serviceKey); if (service == null) { // added ESUP => does not work otherwise. service = getAppURL(httpRequest); }/*from w w w.j ava2 s . c om*/ ProxyTicketValidator proxyValidator; try { proxyValidator = (ProxyTicketValidator) Framework.getRuntime().getContext() .loadClass(proxyValidatorClassName).newInstance(); } catch (InstantiationException e) { log.error( "checkProxyCasTicket during the ProxyTicketValidator initialization with InstantiationException:", e); return null; } catch (IllegalAccessException e) { log.error( "checkProxyCasTicket during the ProxyTicketValidator initialization with IllegalAccessException:", e); return null; } catch (ClassNotFoundException e) { log.error( "checkProxyCasTicket during the ProxyTicketValidator initialization with ClassNotFoundException:", e); return null; } proxyValidator.setCasValidateUrl(getServiceURL(httpRequest, PROXY_VALIDATE_ACTION)); proxyValidator.setService(service); proxyValidator.setServiceTicket(ticket); try { proxyValidator.validate(); } catch (IOException e) { log.error("checkProxyCasTicket failed with IOException:", e); return null; } catch (SAXException e) { log.error("checkProxyCasTicket failed with SAXException:", e); return null; } catch (ParserConfigurationException e) { log.error("checkProxyCasTicket failed with ParserConfigurationException:", e); return null; } log.debug("checkProxyCasTicket: validation executed without error"); String username = proxyValidator.getUser(); log.debug("checkProxyCasTicket: validation returned username = " + username); return username; }
From source file:com.netflix.genie.web.controllers.JobRestControllerUnitTests.java
/** * Makes sure if we do forward and get back an error we return it to the user. * * @throws IOException on error// w w w. j a va2s. c o m * @throws ServletException on error * @throws GenieException on error */ @Test public void canRespondToKillRequestForwardError() throws IOException, ServletException, GenieException { this.jobsProperties.getForwarding().setEnabled(true); final String jobId = UUID.randomUUID().toString(); final String forwardedFrom = null; final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer(UUID.randomUUID().toString())); Mockito.when(this.jobSearchService.getJobHost(jobId)).thenReturn(UUID.randomUUID().toString()); final StatusLine statusLine = Mockito.mock(StatusLine.class); Mockito.when(statusLine.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND.value()); final HttpResponse forwardResponse = Mockito.mock(HttpResponse.class); Mockito.when(forwardResponse.getStatusLine()).thenReturn(statusLine); Mockito.when(this.restTemplate.execute(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); this.controller.killJob(jobId, forwardedFrom, request, response); Mockito.verify(response, Mockito.times(1)).sendError(Mockito.eq(HttpStatus.NOT_FOUND.value()), Mockito.anyString()); Mockito.verify(this.jobSearchService, Mockito.times(1)).getJobHost(jobId); Mockito.verify(this.restTemplate, Mockito.times(1)).execute(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString()); }