List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:com.google.ratel.util.RatelUtils.java
public static boolean isPost(HttpServletRequest request) { boolean isPost = Constants.POST.equals(request.getMethod()); return isPost; }
From source file:com.flipkart.poseidon.core.PoseidonServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String method = request.getMethod(); if (PATCH.toString().equals(method)) { doPatch(request, response);/*from w ww .j a v a 2 s . c om*/ } else { super.service(request, response); } }
From source file:kziomek.filter.logging.MvcLoggingFilter.java
private String buildRequestMessage(final HttpServletRequest request, String prefix) { StringBuilder msg = new StringBuilder(); msg.append(prefix);/* www.j a v a 2 s . c o m*/ /* Query params */ if (isIncludeQueryString()) { msg.append(request.getMethod()).append(" ").append(request.getRequestURI()); if (request.getQueryString() != null) { msg.append('?').append(request.getQueryString()); } } /* Headers */ if (isIncludeHeaders()) { Map<String, String> headers = getHeadersInfo(request); msg.append(" headers=").append(headers); } /* Payload */ if (isIncludePayload()) { if (request instanceof BufferedRequestWrapper && !isMultipart(request)) { BufferedRequestWrapper requestWrapper = (BufferedRequestWrapper) request; try { int length = Math.min(requestWrapper.toByteArray().length, getMaxPayloadLength()); String charEncoding = requestWrapper.getCharacterEncoding() != null ? requestWrapper.getCharacterEncoding() : "UTF-8"; String payload = new String(requestWrapper.toByteArray(), 0, length, charEncoding).trim() .replace("\n", ""); if (!StringUtils.isEmpty(payload)) { msg.append(" payload=").append(payload); } } catch (UnsupportedEncodingException e) { logger.warn("Failed to parse request payload", e); } } } return msg.toString(); }
From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilter.java
@Override public void doFilter(final ServletRequest servletRequest, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) servletRequest; final Authentication authentication = org.springframework.security.core.context.SecurityContextHolder .getContext().getAuthentication(); if (authentication != null && HttpMethod.GET.name().equalsIgnoreCase(request.getMethod())) { logger.debug("applying " + RESTRICTION + " to " + authentication); Set<GrantedAuthority> restricted = RESTRICTION.mapAuthorities(authentication.getAuthorities()); if (restricted.isEmpty()) { // anonymous and remember me tokens require at least one authority restricted = Collections.<GrantedAuthority>singleton(Role.NONE); }/*from w w w.j a v a 2 s .co m*/ if (!restricted.containsAll(authentication.getAuthorities())) { final AbstractAuthenticationToken replacement = copy(authentication, restricted); replacement.setDetails(authentication.getDetails()); logger.debug("injecting " + replacement); org.springframework.security.core.context.SecurityContextHolder.getContext() .setAuthentication(replacement); } else { logger.debug("skip restricting " + authentication + " as it contains no restricted authorities"); } } else { logger.debug("skip restricting " + authentication + " on HTTP method " + request.getMethod()); } chain.doFilter(request, response); }
From source file:es.galvarez.rest.config.CORSFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Credentials", "true"); if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) { // CORS "pre-flight" request response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); response.addHeader("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, X-Requested-With, Content-Type, Accept"); }// w ww . java 2 s .c o m filterChain.doFilter(request, response); }
From source file:org.sakaiproject.metaobj.utils.mvc.impl.servlet.FormControllerImpl.java
protected boolean isFormSubmission(HttpServletRequest request) { if (getFormMethod() != null && getFormMethod().equalsIgnoreCase("get") && request.getMethod().equalsIgnoreCase("get")) { return true; }// ww w.j a va2 s .co m if (getFormMethod() != null && getFormMethod().equalsIgnoreCase("post") && request.getMethod().equalsIgnoreCase("post")) { return true; } return super.isFormSubmission(request); }
From source file:org.solmix.wmix.web.servlet.AbstractWmixFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String method = httpRequest.getMethod(); if ("HEAD".equalsIgnoreCase(method)) { httpResponse = new NoBodyResponse(httpResponse); }/*from ww w.ja va2 s. co m*/ try { doFilter(httpRequest, httpResponse, chain); } finally { if (httpResponse instanceof NoBodyResponse) { ((NoBodyResponse) httpResponse).setContentLength(); } } } else { LOG.debug("Skipped filtering due to the unknown request/response types: {}, {}", request.getClass().getName(), response.getClass().getName()); chain.doFilter(request, response); } }
From source file:com.singbon.service.CustomAuthenticationFilter.java
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (postOnly && !request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }/*from ww w . jav a 2 s. co m*/ String username = obtainUsername(request); String password = obtainPassword(request); String companyName = null; try { companyName = new String(obtainCompanyName(request).getBytes("ISO-8859-1"), "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (username == null) { username = ""; } if (password == null) { password = ""; } if (companyName == null) { companyName = ""; } try { username = DesUtil.encrypt(username.trim()); password = DesUtil.encrypt(password.trim()); } catch (Exception e) { e.printStackTrace(); } companyName = companyName.trim(); // ?? SysUser user = this.sysUserDAO.login(companyName, username, password); username = DesUtil.decrypt(username); password = DesUtil.decrypt(password); if (user == null) { username = 0 + USERNAME_LOGINID_SPLIT + username + USERNAME_LOGINID_SPLIT + password; } else { Company company = (Company) this.companyDAO.selectById(user.getCompanyId()); request.getSession().setAttribute("company", company); user.setLoginName(username); request.getSession().setAttribute("sysUser", user); username = user.getOperId() + USERNAME_LOGINID_SPLIT + username + USERNAME_LOGINID_SPLIT + password; if (user.getDeviceId() != null && user.getDeviceId() != 0) { Device device = (Device) this.deviceDAO.selectById(user.getDeviceId()); request.getSession().setAttribute("device", device); } } UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password); // Allow subclasses to set the "details" property authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); return this.getAuthenticationManager().authenticate(authRequest); }
From source file:eu.trentorise.smartcampus.resourceprovider.filter.ResourceFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { final boolean debug = logger.isDebugEnabled(); final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; try {//from w ww . j a v a2s. c om String tokenValue = parseToken(request); if (HttpMethod.OPTIONS.equals(HttpMethod.valueOf(request.getMethod()))) { chain.doFilter(request, response); // throw new OAuth2Exception("options"); } else if (tokenValue == null) { if (debug) { logger.debug("No token in request, will continue chain."); } throw new OAuth2Exception("empty token"); } else { ResourceCallAuthenticationToken authentication = new ResourceCallAuthenticationToken(tokenValue, ""); request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE, tokenValue); authentication.setDetails(authenticationDetailsSource.buildDetails(request)); authentication.setRequestPath(getFullURL(request)); authentication.setHttpMethod(HttpMethod.valueOf(request.getMethod())); Authentication authResult = authenticationManager.authenticate(authentication); SecurityContextHolder.getContext().setAuthentication(authResult); chain.doFilter(request, response); } } catch (OAuth2Exception failed) { SecurityContextHolder.clearContext(); if (debug) { logger.debug("Authentication request failed: " + failed); } authenticationEntryPoint.commence(request, response, new InsufficientAuthenticationException(failed.getMessage(), failed)); return; } }
From source file:alpha.portal.webapp.controller.UserFormController.java
/** * Checks if is form submission.// w ww. j a va2 s . co m * * @param request * the request * @return true, if is form submission */ private boolean isFormSubmission(final HttpServletRequest request) { return request.getMethod().equalsIgnoreCase("post"); }