List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:org.osiam.resource_server.resources.helper.JsonInputValidator.java
public Group validateJsonGroup(HttpServletRequest request) throws IOException { String jsonInput = getRequestBody(request); Validator validator = validators.get(RequestMethod.valueOf(request.getMethod())); Group group;/*from www. ja va2s . c o m*/ try { group = validator.validateGroup(jsonInput); } catch (JsonParseException ex) { throw new IllegalArgumentException("The JSON structure is invalid", ex); } if (group.getSchemas() == null || group.getSchemas().isEmpty() || !group.getSchemas().contains(Constants.GROUP_CORE_SCHEMA)) { throw new SchemaUnknownException(); } return group; }
From source file:com.neelo.glue.ApplicationModule.java
public RequestResolution resolve(Lifecycle lifecycle) throws ResolutionException { HttpServletRequest request = lifecycle.getRequest(); HttpMethod method = HttpMethod.valueOf(request.getMethod()); // TODO: These two lines depend on the servlet mapping (/app/*, /) // String path = // request.getRequestURI().substring(request.getContextPath().length()); String path = request.getPathInfo(); path = StringUtils.removeEnd(path, FORWARD_SLASH); for (Route route : routes) { if (!method.equals(route.getHttpMethod())) continue; if (StringUtils.isBlank(path) && StringUtils.isBlank(route.getFullPath())) return new RequestResolution(route, EMPTY_PARAMETERS); NamedPattern np = NamedPattern.compile(route.getFullPath()); NamedMatcher nm = np.matcher(path); List<String> names = np.groupNames(); if (nm.matches()) { if (names.size() > 0) { List<Parameter> params = new ArrayList<Parameter>(); for (String name : names) { params.add(new Parameter(name, nm.group(name))); }/* ww w.j av a2 s . c om*/ return new RequestResolution(route, params); } return new RequestResolution(route, EMPTY_PARAMETERS); } } throw new ResolutionException(404, "Resource not found @ " + path); }
From source file:com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule.java
/** * Begin request processing.//from w w w .ja va 2s . c om * @param req The request to process * @param res The response to modify */ @Override public void onBeginRequest(ServletRequest req, ServletResponse res) { if (!isInitialized) { // Avoid logging to not spam the log. It is sufficient that the module initialization failure // has been logged. return; } try { RequestTelemetryContext context = ThreadContext.getRequestTelemetryContext(); RequestTelemetry telemetry = context.getHttpRequestTelemetry(); HttpServletRequest request = (HttpServletRequest) req; String method = request.getMethod(); String rURI = request.getRequestURI(); String scheme = request.getScheme(); String host = request.getHeader("Host"); String query = request.getQueryString(); String userAgent = request.getHeader("User-Agent"); telemetry.setHttpMethod(method); if (!Strings.isNullOrEmpty(query)) { telemetry.setUrl(String.format("%s://%s%s?%s", scheme, host, rURI, query)); } else { telemetry.setUrl(String.format("%s://%s%s", scheme, host, rURI)); } // TODO: this is a very naive implementation, which doesn't take into account various MVC f/ws implementation. // Next step is to implement the smart request name calculation which will support the leading MVC f/ws. String rUriWithoutSessionId = removeSessionIdFromUri(rURI); telemetry.setName(String.format("%s %s", method, rUriWithoutSessionId)); telemetry.getContext().getUser().setUserAgent(userAgent); telemetry.setTimestamp(new Date(context.getRequestStartTimeTicks())); } catch (Exception e) { String moduleClassName = this.getClass().getSimpleName(); InternalLogger.INSTANCE.error( "Telemetry module " + moduleClassName + " onBeginRequest failed with exception: %s", e.getMessage()); } }
From source file:org.osiam.resource_server.resources.helper.JsonInputValidator.java
public User validateJsonUser(HttpServletRequest request) throws IOException { String jsonInput = getRequestBody(request); Validator validator = validators.get(RequestMethod.valueOf(request.getMethod())); User user;// w w w.ja v a2 s. c o m try { user = validator.validateJsonUser(jsonInput); } catch (JsonParseException ex) { throw new IllegalArgumentException("The JSON structure is invalid", ex); } if (user.getSchemas() == null || user.getSchemas().isEmpty() || !user.getSchemas().contains(Constants.USER_CORE_SCHEMA)) { throw new SchemaUnknownException(); } if (user.getId() != null && !user.getId().isEmpty()) { user = new User.Builder(user).setId(null).build(); } return user; }
From source file:com.googlecode.webutilities.servlets.WebProxyServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (HttpOptions.METHOD_NAME.equals(req.getMethod())) { resp.setStatus(200);//from w w w. j a va 2s.c om this.responseHeadersToInject.forEach(resp::setHeader); LOGGER.debug("Sending headers headers with status 200"); return; } try { this.makeProxyRequest(req, resp); } catch (IOException ioe) { LOGGER.error("Failed to make proxy request", ioe); resp.setStatus(404); // Return 404 } }
From source file:io.lavagna.web.security.login.PersonaLogin.java
@Override public boolean doAction(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (!("POST".equalsIgnoreCase(req.getMethod()) && req.getParameterMap().containsKey("assertion"))) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return true; }//from ww w. j av a2 s . co m String audience = configurationRepository.getValue(Key.PERSONA_AUDIENCE); MultiValueMap<String, String> toPost = new LinkedMultiValueMap<>(); toPost.add("assertion", req.getParameter("assertion")); toPost.add("audience", audience); VerifierResponse verifier = restTemplate.postForObject("https://verifier.login.persona.org/verify", toPost, VerifierResponse.class); if ("okay".equals(verifier.status) && audience.equals(verifier.audience) && userRepository.userExistsAndEnabled(USER_PROVIDER, verifier.email)) { String url = Redirector.cleanupRequestedUrl(req.getParameter("reqUrl")); UserSession.setUser(userRepository.findUserByName(USER_PROVIDER, verifier.email), req, resp, userRepository); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/json"); JsonObject jsonObject = new JsonObject(); jsonObject.add("redirectTo", new JsonPrimitive(url)); resp.getWriter().write(jsonObject.toString()); } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } return true; }
From source file:com.sun.socialsite.web.filters.DebugFilter.java
/** * Inspect incoming urls and see if they should be routed. */// ww w. j a v a2s. c om public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; log.info("--- entering"); log.info(request.getMethod() + " " + request.getRequestURL().toString()); log.info("st=" + request.getParameter("st")); // print out session details HttpSession session = request.getSession(false); if (session != null) { log.info("inbound session contains:"); Enumeration foo = session.getAttributeNames(); while (foo.hasMoreElements()) { String attr = (String) foo.nextElement(); log.info(" " + attr + " = " + session.getAttribute("attr")); } } // keep going chain.doFilter(request, response); // print out session details session = request.getSession(false); if (session != null) { log.info("outbound session contains:"); Enumeration bar = session.getAttributeNames(); while (bar.hasMoreElements()) { String attr = (String) bar.nextElement(); log.info(" " + attr + " = " + session.getAttribute("attr")); } } log.info("--- exiting"); }
From source file:nl.surfnet.coin.selfservice.interceptor.AuthorityScopeInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (TOKEN_CHECK_METHODS.contains(request.getMethod().toUpperCase())) { String token = request.getParameter(TOKEN_CHECK); String sessionToken = (String) request.getSession().getAttribute(TOKEN_CHECK); if (StringUtils.isBlank(token) || !token.equals(sessionToken)) { throw new SecurityException(String.format( "Token from session '%s' does not match token '%s' from request", sessionToken, token)); }//from w ww . j av a 2s.co m } return true; }
From source file:ch.entwine.weblounge.kernel.security.SpringSecurityFormAuthentication.java
/** * {@inheritDoc}/*from w w w . j a va 2 s . c o m*/ * * @see org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter#attemptAuthentication(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { if (postOnly && !"POSTS".equals(request.getMethod())) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); } // Get the username String username = StringUtils.trimToEmpty(request.getParameter(SPRING_SECURITY_FORM_USERNAME_KEY)); // Get the password String password = request.getParameter(SPRING_SECURITY_FORM_PASSWORD_KEY); if (password == null) { password = ""; } // Using the extracted credentials, create an authentication request UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password); authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); // Place the last username attempted into HttpSession for views HttpSession session = request.getSession(false); if (session != null || getAllowSessionCreation()) { request.getSession().setAttribute(SPRING_SECURITY_LAST_USERNAME_KEY, TextEscapeUtils.escapeEntities(username)); } return this.getAuthenticationManager().authenticate(authRequest); }