List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:it.govpay.web.filters.SessionTimeoutFilter.java
/** * //from ww w . j av a 2 s . c o m * session shouldn't be checked for some pages. For example: for timeout page.. * Since we're redirecting to timeout page from this filter, * if we don't disable session control for it, filter will again redirect to it * and this will be result with an infinite loop... */ private boolean isSessionControlRequiredForThisResource(HttpServletRequest httpServletRequest) { String requestPath = httpServletRequest.getRequestURI(); boolean controlRequired = false; if (StringUtils.contains(requestPath, this.loginErrorPage) || StringUtils.contains(requestPath, this.loginPage)) { controlRequired = false; } else { if (this.excludedPages.size() > 0) for (String page : this.excludedPages) { if (StringUtils.contains(requestPath, page)) { controlRequired = false; break; } } else controlRequired = true; } return controlRequired; }
From source file:com.lixiaocong.security.DaoBasedUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest();//from ww w. j a v a 2 s . c om if (request.getRequestURI().equals("/signin")) { String postcode = request.getParameter("imagecode"); if (!codeService.check(postcode, request.getSession())) throw new UsernameNotFoundException("image code error"); } com.lixiaocong.entity.User user = userRepository.findByUsername(username); if (user == null) { log.info("user not exists"); throw new UsernameNotFoundException("user not exists"); } Set<GrantedAuthority> authorities = new HashSet<>(); authorities.add(new SimpleGrantedAuthority("ROLE_USER")); if (user.isAdmin()) authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN")); return new DaoBasedUserDetails(user.getId(), user.getUsername(), user.getPassword(), authorities); }
From source file:es.ucm.fdi.storage.web.StorageController.java
@RequestMapping(method = RequestMethod.GET, value = "/storage/**") public void servirArchivos(HttpServletRequest request, HttpServletResponse response) throws IOException { String ctxPath = request.getContextPath(); String objectId = request.getRequestURI(); objectId = objectId.substring(ctxPath.length() + "/storage/".length()); int pos = objectId.indexOf('/'); if (pos < 0) { response.sendError(400, "Upps"); return;//from w w w . j av a 2 s .c om } String bucket = objectId.substring(0, pos); String key = objectId.substring(pos + 1); StorageObject object = storage.getObject(bucket, key); String mimeType = object.getMimeType(); long length = object.getContentLength(); // set content attributes for the response response.setContentType(mimeType); response.setContentLength((int) length); try { object.transferTo(response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { logger.error("Error writing file to output stream. bucket=>'{}', key=>'{}'", bucket, key, ex); response.sendError(500, "Upps"); } }
From source file:com.erudika.para.security.PasswordAuthFilter.java
/** * Handles an authentication request.//from w w w. ja v a 2 s . c o m * @param request HTTP request * @param response HTTP response * @return an authentication object that contains the principal object if successful. * @throws IOException ex * @throws ServletException ex */ @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String requestURI = request.getRequestURI(); Authentication userAuth = null; User user = new User(); if (requestURI.endsWith(PASSWORD_ACTION)) { user.setIdentifier(request.getParameter(EMAIL)); user.setPassword(request.getParameter(PASSWORD)); if (User.passwordMatches(user) && StringUtils.contains(user.getIdentifier(), "@")) { //success! user = User.readUserForIdentifier(user); userAuth = new UserAuthentication(new AuthenticatedUserDetails(user)); } } if (userAuth == null || user == null || user.getIdentifier() == null) { throw new BadCredentialsException("Bad credentials."); } else if (!user.getActive()) { throw new LockedException("Account is locked."); // } else { // SecurityUtils.setAuthCookie(user, request, response); } return userAuth; }
From source file:com.github.rabid_fish.proxy.servlet.ProxySoapServlet.java
boolean sendMockResponse(HttpServletRequest request, HttpServletResponse response) { String method = request.getMethod(); String url = request.getRequestURI(); // Don't break parent functionality if ("CONNECT".equalsIgnoreCase(method)) { return false; }// w w w .ja va2 s. c o m if (url.startsWith("/favicon.ico")) { return false; } try { String mockBody; if (method.equals("POST")) { ServletInputStream stream = request.getInputStream(); String requestBody = IOUtils.toString(stream); // Need to save off the body so that the input stream can be reset later // by the parent class. request.setAttribute(ReverseProxyServlet.PROXY_REQUEST_BODY, requestBody); mockBody = mockMapRegexHelper.getMockBodyForBody(requestBody); if (mockBody != null) { writeMockResponse(response, mockBody); return true; } } } catch (Exception e) { return false; } return false; }
From source file:io.apiman.manager.test.server.MockGatewayServlet.java
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from ww w .ja v a2 s.com @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { builder.append("POST:").append(req.getRequestURI()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ payloads.add(getPayload(req)); resp.setStatus(204); }
From source file:com.ebay.pulsar.metric.controller.PulsarReportingController.java
@RequestMapping(value = { "pulsar/metric", "pulsar/counter" }, method = RequestMethod.GET) @ResponseBody/*from w w w .j av a 2s. co m*/ public String listMetrics(HttpMethod method, HttpServletRequest request, HttpServletResponse response) throws URISyntaxException { URI uri = new URI("http", null, MetricServer, MetricSeverPort, request.getRequestURI(), request.getQueryString(), null); ResponseEntity<String> responseEntity = restTemplate.exchange(uri, method, HttpEntity.EMPTY, String.class); return responseEntity.getBody(); }
From source file:org.dspace.webmvc.controller.BitstreamController.java
@ModelAttribute("bitstream") protected Bitstream getBitstream(@RequestAttribute Context context, HttpServletRequest request) { String path = request.getRequestURI(); Integer bitstreamId = null;//from w w w .j a v a2 s. c o m if (path != null) { String handle; String extraPathInfo; if (path.contains("bitstream")) { if (path.startsWith("/bitstream/")) { path = path.substring(11); } else if (path.contains("/bitstream/")) { path = path.substring(path.indexOf("/bitstream/") + 11); } // Extract the Handle int firstSlash = path.indexOf('/'); int secondSlash = path.indexOf('/', firstSlash + 1); if (secondSlash != -1) { // We have extra path info handle = path.substring(0, secondSlash); extraPathInfo = path.substring(secondSlash); } else { // The path is just the Handle handle = path; extraPathInfo = null; } } else { if (path.startsWith("/retrieve/")) { path = path.substring(10); } else if (path.contains("/retrieve/")) { path = path.substring(path.indexOf("/retrieve/") + 10); } // Extract the id int firstSlash = path.indexOf('/'); if (firstSlash != -1) { // We have extra path info bitstreamId = Integer.parseInt(path.substring(0, firstSlash)); extraPathInfo = path.substring(firstSlash); } else { // The path is just the Handle bitstreamId = Integer.parseInt(path); extraPathInfo = null; } } } if (bitstreamId != null) { try { return Bitstream.find(context, bitstreamId); } catch (SQLException e) { } } return null; }
From source file:com.cloudstone.emenu.web.filter.LicenceFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; // add context before url // String context = req.getContextPath(); String url = req.getRequestURI().toLowerCase(); if (url.startsWith("/licence") || url.startsWith("/static")) { chain.doFilter(request, response); return;//from w w w . ja v a2 s. c om } // skip license check in non-prodution environment if (!Profiles.isProd()) { chain.doFilter(request, response); LOG.debug("not in production environment skip the license check"); return; } if (licenceHelper.checkLicence().isSuccess()) { chain.doFilter(req, resp); return; } LOG.info("licence filter not pass"); resp.sendRedirect("licence"); return; }
From source file:com.ewcms.web.filter.PreviewFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse rep, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String uri = request.getRequestURI(); if (!StringUtils.endsWith(uri, PREVIEW_PATH)) { logger.debug("Uri is not preview address"); chain.doFilter(req, rep);// ww w .jav a 2 s .c o m return; } HttpServletResponse response = (HttpServletResponse) rep; try { Integer channelId = getChannelId(request); Integer templateId = getTemplateId(request); Long articleId = getArticleId(request); if (templateId == null && (channelId == null || articleId == null)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } String redirectUri = getRedirectUri(request, articleId, templateId); if (redirectUri == null) { logger.debug("Redirect's address is null"); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } else { logger.debug("Redirect's address is {}", redirectUri); response.sendRedirect(redirectUri); } } catch (Exception e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.toString()); } }