List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:ru.mystamps.web.support.spring.security.SessionLocaleResolverAwareFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {/*from w ww. java 2 s . c o m*/ HttpServletRequest req = (HttpServletRequest) request; LOG.debug("Handling request {} {}", req.getMethod(), req.getRequestURI()); Locale locale = (Locale) WebUtils.getSessionAttribute((HttpServletRequest) request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); if (locale == null) { locale = Locale.ENGLISH; LOG.debug("Locale reset to 'en' (default)"); } else { LOG.debug("Locale reset to '{}' (from session)", locale); } LocaleContextHolder.setLocale(locale); } catch (RuntimeException ex) { // NOPMD: AvoidCatchingGenericException LOG.warn("Couldn't handle request: {}", ex); } finally { chain.doFilter(request, response); } }
From source file:ru.org.linux.csrf.CSRFHandlerInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (!request.getMethod().equalsIgnoreCase("POST")) { // Not a POST - allow the request return true; } else {//from w w w .j a va2 s .c o m // This is a POST request - need to check the CSRF token //CSRFProtectionService.checkCSRF(request); if ((handler instanceof HandlerMethod) && (((HandlerMethod) handler).getMethodAnnotation(CSRFNoAuto.class) != null)) { logger.debug("Auto CSRF disabled for " + ((HandlerMethod) handler).getBeanType().getName()); return true; } String csrfInput = request.getParameter(CSRFProtectionService.CSRF_INPUT_NAME); if (Strings.isNullOrEmpty(csrfInput)) { if ((handler instanceof HandlerMethod)) { logger.warn("Missing CSRF field for " + request.getRequestURI() + ' ' + ((HandlerMethod) handler).getBeanType().getName() + '.' + ((HandlerMethod) handler).getMethod().getName()); } else { logger.warn("Missing CSRF field for " + request.getRequestURI()); } } if (!CSRFProtectionService.checkCSRF(request)) { throw new AccessViolationException( "? CSRF. ???? ?"); } return true; } }
From source file:com.epam.trade.storefront.filters.StorefrontFilter.java
private boolean isPostMethod(final HttpServletRequest request) { return "POST".equalsIgnoreCase(request.getMethod()); }
From source file:cf.spring.servicebroker.CatalogHandler.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!"get".equalsIgnoreCase(request.getMethod())) { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return;/*from ww w . j a v a2 s. com*/ } if (!authenticator.authenticate(request, response)) { return; } ApiVersionValidator.validateApiVersion(request); response.setContentType(Constants.JSON_CONTENT_TYPE); mapper.writeValue(response.getOutputStream(), catalog.get()); }
From source file:com.wwpass.springsecurity.web.authentication.WwpassAuthenticationFilter.java
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (!request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }// www .j a v a 2 s . c o m String ticket = request.getParameter("ticket"); String puid; try { ticket = conn.putTicket(ticket); puid = conn.getPUID(ticket); } catch (UnsupportedEncodingException e) { throw new AuthenticationServiceException("Exception in WWPassConnection library: \n", e); } catch (IOException e) { throw new AuthenticationServiceException("Exception in WWPassConnection library: \n", e); } if (puid == null) { throw new IllegalArgumentException("PUID cannot be null."); } request.getSession().setAttribute("puid", puid); WwpassAuthenticationToken authRequest = new WwpassAuthenticationToken(null, puid, null); return this.getAuthenticationManager().authenticate(authRequest); }
From source file:com.thoughtworks.go.server.newsecurity.filters.ModeAwareFilter.java
private boolean isReadOnlyRequest(HttpServletRequest servletRequest) { return RequestMethod.GET.name().equalsIgnoreCase(servletRequest.getMethod()) || RequestMethod.HEAD.name().equalsIgnoreCase(servletRequest.getMethod()); }
From source file:com.github.glue.mvc.RequestHandler.java
private boolean isMultipartContent(HttpServletRequest request) { if (!"post".equalsIgnoreCase(request.getMethod())) { return false; }/*from w w w .jav a 2s. c om*/ String contentType = request.getContentType(); if (contentType == null) { return false; } if (contentType.toLowerCase().startsWith("multipart/")) { return true; } return false; }
From source file:foam.nanos.blob.HttpBlobService.java
@Override public void execute(X x) { HttpServletRequest req = x.get(HttpServletRequest.class); try {/*from ww w.j av a 2 s . c o m*/ if ("GET".equals(req.getMethod())) { download(x); } else if ("PUT".equals(req.getMethod())) { upload(x); } } catch (Throwable t) { throw new RuntimeException(t); } }
From source file:io.lavagna.web.security.login.PasswordLogin.java
@Override public boolean doAction(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (!"POST".equalsIgnoreCase(req.getMethod())) { return false; }// w ww .ja v a 2s . c o m String username = req.getParameter("username"); String password = req.getParameter("password"); if (username != null && users.userExistsAndEnabled(USER_PROVIDER, username) && authenticate(username, password)) { String url = Redirector.cleanupRequestedUrl(req.getParameter("reqUrl"), req); SecurityConfiguration.User user = users.findUserByName(USER_PROVIDER, username); sessionHandler.setUser(user.getId(), user.isAnonymous(), req, resp); Redirector.sendRedirect(req, resp, url, Collections.<String, List<String>>emptyMap()); } else { Redirector.sendRedirect(req, resp, req.getContextPath() + "/" + removeStart(errorPage, "/"), Collections.<String, List<String>>emptyMap()); } return true; }
From source file:org.smigo.config.RequestLogFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; resp.addHeader("SmigoUser", req.getRemoteUser()); log.info("Incoming request:" + req.getMethod() + req.getRequestURL().toString()); request.setAttribute(REQUEST_TIMER, System.nanoTime()); chain.doFilter(request, response);//w w w . j av a 2s . co m logHandler.log(req, resp); }