List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:com.boundlessgeo.geoserver.AppAuthFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) servletRequest; HttpServletResponse res = (HttpServletResponse) servletResponse; String path = req.getPathInfo(); if (req.getServletPath().startsWith("/app") && path.startsWith("/api")) { if ("POST".equalsIgnoreCase(req.getMethod()) && LOGIN_RE.matcher(path).matches()) { // hack: we have to jump through a few hoops to piggy back on the geoserver web auth: // 1. we fake the request path to fool the security filter // 2. we ignore redirects boolean success = runSecurityFilters(new HttpServletRequestWrapper(req) { @Override//from w w w . j ava 2 s.c om public String getServletPath() { return ""; } @Override public String getPathInfo() { return "/j_spring_security_check"; } }, new HttpServletResponseWrapper(res) { @Override public void sendRedirect(String location) throws IOException { } }, WEB_LOGIN_CHAIN_NAME); if (success) { filterChain.doFilter(servletRequest, servletResponse); } else { res.setStatus(401); } } else if (LOGOUT_RE.matcher(path).matches()) { // invalidate the session if it exists HttpSession session = req.getSession(false); if (session != null) { session.invalidate(); } } else { // two modes of authentication, basic vs form. String chainName = req.getHeader("Authorization") != null ? DEFAULT_CHAIN_NAME : WEB_CHAIN_NAME; if (runSecurityFilters(req, res, chainName)) { filterChain.doFilter(servletRequest, servletResponse); } else { res.setStatus(401); } } } else { filterChain.doFilter(servletRequest, servletResponse); } }
From source file:com.primeleaf.krystal.web.action.cpanel.NewClassIndexAction.java
public WebView execute(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); User loggedInUser = (User) session.getAttribute(HTTPConstants.SESSION_KRYSTAL); if (request.getMethod().equalsIgnoreCase("POST")) { try {//from w w w .j a v a 2 s . co m int documentClassId = 0; try { documentClassId = Integer.parseInt( request.getParameter("classid") != null ? request.getParameter("classid") : "0"); } catch (Exception e) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid input"); return (new ManageDocumentClassesAction().execute(request, response)); } DocumentClass documentClass = DocumentClassDAO.getInstance().readDocumentClassById(documentClassId); if (documentClass == null) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid document class"); return (new ManageDocumentClassesAction().execute(request, response)); } String indexName = request.getParameter("txtIndexName") != null ? request.getParameter("txtIndexName") : ""; String indexDisplayName = request.getParameter("txtIndexDisplayName") != null ? request.getParameter("txtIndexDisplayName") : ""; String indexType = request.getParameter("cmbIndexType") != null ? request.getParameter("cmbIndexType") : IndexDefinition.INDEXTYPE_STRING; String indexLength = request.getParameter("txtIndexLength") != null ? request.getParameter("txtIndexLength") : "100"; String mandatory = request.getParameter("radMandatory") != null ? request.getParameter("radMandatory") : ""; String defaultValue = request.getParameter("txtDefaultValue") != null ? request.getParameter("txtDefaultValue") : ""; int maximumIndexLength = Integer.parseInt(indexLength); if (!GenericValidator.maxLength(indexName, 50)) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Value too large for Index Name"); return (new ClassIndexesAction().execute(request, response)); } boolean isIndexDefinition = IndexDefinitionDAO.getInstance() .validateIndexDefinition(documentClass.getIndexId(), indexName); if (isIndexDefinition) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Index " + indexName + " already exist"); return (new ClassIndexesAction().execute(request, response)); } if (defaultValue.trim().length() > 0) { if (IndexDefinition.INDEXTYPE_NUMBER.equalsIgnoreCase(indexType)) { if (!GenericValidator.isDouble(defaultValue)) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid input for Default Value : " + defaultValue); return (new ClassIndexesAction().execute(request, response)); } } if (IndexDefinition.INDEXTYPE_DATE.equalsIgnoreCase(indexType)) { if (!GenericValidator.isDate(defaultValue, "yyyy-MM-dd", true)) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid input for Default Value : " + defaultValue); return (new ClassIndexesAction().execute(request, response)); } } } if (!GenericValidator.maxLength(defaultValue, maximumIndexLength)) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Value too large for Default Value : " + defaultValue); return (new ClassIndexesAction().execute(request, response)); } int i = documentClass.getIndexDefinitions().size(); indexName = indexName.replace(' ', '_'); IndexDefinition indexDefinition = new IndexDefinition(); indexDefinition.setIndexColumnName(indexName); indexDefinition.setIndexDisplayName(indexDisplayName); indexDefinition.setDefaultValue(defaultValue); indexDefinition.setIndexMaxLength(maximumIndexLength); indexDefinition.setIndexType(indexType); indexDefinition.setDefaultFilter(""); indexDefinition.setMandatory("Y".equalsIgnoreCase(mandatory)); indexDefinition.setSequence((byte) (++i)); int indexCount = documentClass.getIndexCount(); if (indexCount == 0 && documentClass.getIndexId() == -1) { int indexId = IndexDefinitionDAO.getInstance().getNextIndexId(); while (DocumentClassDAO.getInstance().readDocumentClasses(" INDEXID = " + indexId).size() > 0) { indexId++; } documentClass.setIndexId(indexId); } indexDefinition.setIndexId(documentClass.getIndexId()); IndexDefinitionDAO.getInstance().addIndexDefinition(indexDefinition); TableManager tableManager = new TableManager(); tableManager.alterIndexTable(documentClass, indexDefinition); indexCount++; documentClass.setIndexCount(indexCount); DocumentClassDAO.getInstance().updateDocumentClass(documentClass); AuditLogManager.log(new AuditLogRecord(documentClass.getClassId(), AuditLogRecord.OBJECT_DOCUMENTCLASS, AuditLogRecord.ACTION_EDITED, loggedInUser.getUserName(), request.getRemoteAddr(), AuditLogRecord.LEVEL_INFO, "Name : " + documentClass.getClassName(), "Index " + indexName + " added")); request.setAttribute(HTTPConstants.REQUEST_MESSAGE, "Index " + indexDefinition.getIndexDisplayName() + " added successfully"); return (new ClassIndexesAction().execute(request, response)); } catch (Exception ex) { ex.printStackTrace(); } } return (new ClassIndexesAction().execute(request, response)); }
From source file:com.mnt.base.web.DigestAuthenticator.java
public static boolean authenticate(HttpServletRequest req, HttpServletResponse resp) { boolean result = false; HttpSession session = req.getSession(); if (session != null) { result = session.getAttribute(AUTHENTICATED_FLAG_KEY) != null; if (!result) { session.setMaxInactiveInterval(60); Map<String, Object> authInfoMap = CommonUtil.uncheckedMapCast(session.getAttribute(AUTH_INFO_MAP)); if (authInfoMap == null) { authInfoMap = new HashMap<String, Object>(); session.setAttribute(AUTH_INFO_MAP, authInfoMap); }//from ww w. java 2s . c o m String authentication = req.getHeader("Authorization"); if (CommonUtil.isEmpty(authentication) || !authentication.startsWith("Digest ")) { postAuthRequired(req, resp, authInfoMap); } else { result = authenticate(req.getMethod(), authentication, authInfoMap); if (result) { if (authProvider != null) { try { authProvider.authenticated(authUser.get(), true); } catch (Exception e) { log.error("error while invoke the authProvider.authenticated: " + authUser.get(), e); } } session.setAttribute(AUTHENTICATED_FLAG_KEY, true); session.removeAttribute(AUTH_INFO_MAP); authInfoMap.clear(); authInfoMap = null; session.setMaxInactiveInterval(1800); } else { authProvider.authenticated(authUser.get(), false); authInfoMap.clear(); postAuthRequired(req, resp, authInfoMap); } } } } else { System.err.println("Just support session available authentication."); } return result; }
From source file:io.milton.servlet.ServletRequest.java
public ServletRequest(HttpServletRequest r, ServletContext servletContext) { this.request = r; this.servletContext = servletContext; String sMethod = r.getMethod(); method = Request.Method.valueOf(sMethod); String s = r.getRequestURL().toString(); //MiltonUtils.stripContext(r); url = s;/*from ww w .java2 s. c o m*/ tlRequest.set(r); tlServletContext.set(servletContext); if (log.isTraceEnabled()) { log.trace("Dumping headers ---- " + r.getMethod() + " " + r.getRequestURL() + " -----"); log.trace("Request class: " + r.getClass()); log.trace("Response class: " + r.getClass()); Enumeration names = r.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = r.getHeader(name); log.trace(" " + name + "=" + value); } log.trace("-------------------------------------------"); } }
From source file:nl.surfnet.coin.mock.MockHandler.java
private void respond(HttpServletResponse response, HttpServletRequest request) throws IOException { ServletOutputStream outputStream = response.getOutputStream(); String requestURI = request.getRequestURI(); InputStream inputStream = getResponseInputStream(requestURI); logger.debug("Received Http request ('" + requestURI + "')"); if (request.getMethod().equals(HttpMethods.POST)) { logger.debug("Received POST request ('" + IOUtils.toString(request.getInputStream()) + "')"); }/* w w w. j av a2 s. co m*/ if (status != 0) { response.setStatus(status); //reset status = 0; } IOUtils.copy(inputStream, outputStream); outputStream.flush(); }
From source file:edu.duke.cabig.c3pr.web.report.CreateReportController.java
@Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true)); if (request.getMethod().equals(METHOD_GET)) { CreateReportFacade studyFacade = new CreateReportFacade(); Context context = null;/*from w w w .j a v a 2 s. c o m*/ context = new HttpServletRequestContext(request); TableModel model = new TableModelImpl(context); Object viewData = null; try { viewData = studyFacade.build(model, null); } catch (Exception e) { e.printStackTrace(); } request.setAttribute("assembler", viewData); } }
From source file:es.logongas.ix3.web.security.AuthorizationInterceptorImplURL.java
public void checkAuthorized(Principal principal, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, DataSession dataSession) throws BusinessSecurityException { String secureResourceTypeName = SECURE_RESOURCE_TYPE_NAME; String secureResource = getSecureURI(httpServletRequest.getRequestURI(), httpServletRequest.getContextPath()); String permissionName = httpServletRequest.getMethod(); Object arguments = getArguments(httpServletRequest.getParameterMap()); boolean isAuthorized = authorizationManager.authorized(principal, secureResourceTypeName, secureResource, permissionName, arguments, dataSession); if (isAuthorized == false) { throw new BusinessSecurityException( "El usuario " + principal + " no tiene acceso a la URL:" + secureResource); }/*ww w . ja v a 2 s. c o m*/ }
From source file:gxu.software_engineering.shen10.market.core.MappingJacksonJsonpView.java
@Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // utf8//from ww w . j av a 2 s.co m // String charset = response.getCharacterEncoding(); // if (charset == null || charset.length() == 0) { // response.setCharacterEncoding(DEFAULT_CHARSET); // } if (request.getMethod().toUpperCase().equals("GET")) { if (request.getParameterMap().containsKey("callback")) { ServletOutputStream ostream = response.getOutputStream(); // try ostream.write(new String("try{" + request.getParameter("callback") + "(").getBytes()); super.render(model, request, response); ostream.write(new String(");}catch(e){}").getBytes()); // ????closeflushspring? // ? ostream.flush(); ostream.close(); } else { super.render(model, request, response); } } else { super.render(model, request, response); } }
From source file:com.doitnext.http.router.RestRouterServlet.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpMethod httpMethod = HttpMethod.valueOf(request.getMethod().toUpperCase()); if (!routeRequest(httpMethod, request, response)) logger.error(String.format("Failed to handle %s request.", httpMethod.name())); }
From source file:com.lm.lic.manager.controller.AddProductController.java
/** * Determine if the given request represents a form submission. * <p>// w w w . j a va 2 s . co m * The default implementation treats a POST request as form submission. Note: If the form session attribute doesn't exist when * using session form mode, the request is always treated as new form by handleRequestInternal. It is possible for the user to * issue a GET request with enough parameters to issue a full meaningful LDAP search. This method detects that and tries to * treat it as a form submission. * * @param request current HTTP request * @return if the request represents a form submission */ @Override protected boolean isFormSubmission(HttpServletRequest request) { boolean formSubmission = false; String method = request.getMethod(); formSubmission = METHOD_POST.equals(method); return formSubmission; }