Java Code Examples for javax.servlet.http.httpservletrequest#getParameterMap()

The following examples show how to use javax.servlet.http.httpservletrequest#getParameterMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BenchmarkTest01376.java    From Benchmark with GNU General Public License v2.0 7 votes vote down vote up
@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
	
		java.util.Map<String,String[]> map = request.getParameterMap();
		String param = "";
		if (!map.isEmpty()) {
			String[] values = map.get("BenchmarkTest01376");
			if (values != null) param = values[0];
		}
		

		String bar = new Test().doSomething(request, param);
		
		// javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^)
		request.getSession().setAttribute( "userid", bar);
				
		response.getWriter().println(
		"Item: 'userid' with value: '" + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar)
			+ "' saved in session."
);
	}
 
Example 2
Source File: BenchmarkTest01336.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
	
		java.util.Map<String,String[]> map = request.getParameterMap();
		String param = "";
		if (!map.isEmpty()) {
			String[] values = map.get("BenchmarkTest01336");
			if (values != null) param = values[0];
		}
		

		String bar = new Test().doSomething(request, param);
		
response.setHeader("X-XSS-Protection", "0");
		Object[] obj = { "a", "b" };
		response.getWriter().format(java.util.Locale.US,bar,obj);
	}
 
Example 3
Source File: UnregisterController.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.GET)
public String unregister(@RequestParam String provider, HttpServletRequest request) {
	URL providerUrl = URL.valueOf(provider);
	registryContainer.getRegistry().unregister(providerUrl);

	String page;
	Map<String, String[]> params = request.getParameterMap();

	if (params.containsKey("service")) {
		page = "services/providers?service=" + request.getParameter("service");
	} else if (params.containsKey("host")) {
		page = "hosts/providers?host=" + request.getParameter("host");
	} else if (params.containsKey("application")) {
		page = "applications/providers?application=" + request.getParameter("application");
	} else {
		page = "services/providers?service=" + providerUrl.getServiceInterface();
	}

	return "redirect:" + page;
}
 
Example 4
Source File: SignatureUtil.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
    * 通过request获取签名Map
    * @param request
    * @return
    */
   public static Map<String,String> getSignMap(HttpServletRequest request){
	Map<String,String>  paramMap = new HashMap<String, String>();
	Map<String, Object> map = request.getParameterMap();
	Set<Entry<String, Object>> es = map.entrySet();
	Iterator<Entry<String, Object>> it = es.iterator();
	while (it.hasNext()) {
		@SuppressWarnings("rawtypes")
		Map.Entry entry = (Map.Entry) it.next();
		String k = (String) entry.getKey();
		Object ov =  entry.getValue();
		String v="";
		if(ov instanceof String[]){
			String[] value=(String[])ov;
			v= value[0];
           }else{
               v=ov.toString();
           }
		paramMap.put(k, v);
	}
	return paramMap;
}
 
Example 5
Source File: BenchmarkTest01360.java    From Benchmark with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	response.setContentType("text/html;charset=UTF-8");

	java.util.Map<String,String[]> map = request.getParameterMap();
	String param = "";
	if (!map.isEmpty()) {
		String[] values = map.get("BenchmarkTest01360");
		if (values != null) param = values[0];
	}
	

	String bar = new Test().doSomething(request, param);
	
	String cmd = "";
       String osName = System.getProperty("os.name");
       if (osName.indexOf("Windows") != -1) {
       	cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo");
       }
       
	Runtime r = Runtime.getRuntime();

	try {
		Process p = r.exec(cmd + bar);
		org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response);
	} catch (IOException e) {
		System.out.println("Problem executing cmdi - TestCase");
		response.getWriter().println(
		  org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())
		);
		return;
	}
}
 
Example 6
Source File: ServletServerHttpRequest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use {@link javax.servlet.ServletRequest#getParameterMap()} to reconstruct the
 * body of a form 'POST' providing a predictable outcome as opposed to reading
 * from the body, which can fail if any other code has used the ServletRequest
 * to access a parameter, thus causing the input stream to be "consumed".
 */
private static InputStream getBodyFromServletRequestParameters(HttpServletRequest request) throws IOException {
	ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
	Writer writer = new OutputStreamWriter(bos, FORM_CHARSET);

	Map<String, String[]> form = request.getParameterMap();
	for (Iterator<String> nameIterator = form.keySet().iterator(); nameIterator.hasNext();) {
		String name = nameIterator.next();
		List<String> values = Arrays.asList(form.get(name));
		for (Iterator<String> valueIterator = values.iterator(); valueIterator.hasNext();) {
			String value = valueIterator.next();
			writer.write(URLEncoder.encode(name, FORM_CHARSET));
			if (value != null) {
				writer.write('=');
				writer.write(URLEncoder.encode(value, FORM_CHARSET));
				if (valueIterator.hasNext()) {
					writer.write('&');
				}
			}
		}
		if (nameIterator.hasNext()) {
			writer.append('&');
		}
	}
	writer.flush();

	return new ByteArrayInputStream(bos.toByteArray());
}
 
Example 7
Source File: WebUtils.java    From spring-backend-boilerplate with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> getRequestParameters(HttpServletRequest request) {
    Map<String, String> parameters = new HashMap<String, String>();
    Map<String, String[]> map = request.getParameterMap();
    for (String key : map.keySet()) {
        String[] values = map.get(key);
        if (values != null && values.length > 0) {
            parameters.put(key, values[0]);
        }
    }
    return parameters;
}
 
Example 8
Source File: AlipayWAPPayController.java    From springboot-pay-example with Apache License 2.0 5 votes vote down vote up
/**
 * 支付宝页面跳转同步通知页面
 * @param request
 * @return
 * @throws UnsupportedEncodingException
 * @throws AlipayApiException
 */
@RequestMapping("/returnUrl")
public String returnUrl(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, AlipayApiException {
    response.setContentType("text/html;charset=" + alipayProperties.getCharset());

    //获取支付宝GET过来反馈信息
    Map<String,String> params = new HashMap<>();
    Map requestParams = request.getParameterMap();
    for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
        String name = (String) iter.next();
        String[] values = (String[]) requestParams.get(name);
        String valueStr = "";
        for (int i = 0; i < values.length; i++) {
            valueStr = (i == values.length - 1) ? valueStr + values[i]
                    : valueStr + values[i] + ",";
        }
        //乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
        valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
        params.put(name, valueStr);
    }

    boolean verifyResult = AlipaySignature.rsaCheckV1(params, alipayProperties.getAlipayPublicKey(), alipayProperties.getCharset(), "RSA2");
    if(verifyResult){
        //验证成功
        //请在这里加上商户的业务逻辑程序代码,如保存支付宝交易号
        //商户订单号
        String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
        //支付宝交易号
        String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");

        return "wapPaySuccess";

    }else{
        return "wapPayFail";

    }
}
 
Example 9
Source File: JsonHandlerExceptionResolver.java    From everyone-java-blog with Apache License 2.0 5 votes vote down vote up
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {
    Map<String, String[]> parameterMap = request.getParameterMap();
    logException(handler, exception, parameterMap);
    JsonResponse result = new JsonResponse(exception);
    ModelAndView view = new ModelAndView(errorView);
    view.addObject(KEY, result);
    return view;
}
 
Example 10
Source File: Basic26.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
   Map m = req.getParameterMap();
   for(Iterator iter = m.entrySet().iterator(); iter.hasNext();) {
       Map.Entry e = (Entry) iter.next();
       if(e.getKey().equals(FIELD_NAME)) {
           PrintWriter writer = resp.getWriter();
           writer.println(e.getValue());        
       }           
   }
}
 
Example 11
Source File: PathDisplay.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public PathDisplay(HttpServletRequest req, String caller) {
      this.caller = caller;
      title = (String) req.getAttribute("title");
      async_request_uri = (String) req.getAttribute("javax.servlet.async.request_uri");
      async_context_path = (String) req.getAttribute("javax.servlet.async.context_path");
      async_servlet_path = (String) req.getAttribute("javax.servlet.async.servlet_path");
      async_path_info = (String) req.getAttribute("javax.servlet.async.path_info");
      async_query_string = (String) req.getAttribute("javax.servlet.async.query_string");

      forward_request_uri = (String) req.getAttribute("javax.servlet.forward.request_uri");
      forward_context_path = (String) req.getAttribute("javax.servlet.forward.context_path");
      forward_servlet_path = (String) req.getAttribute("javax.servlet.forward.servlet_path");
      forward_path_info = (String) req.getAttribute("javax.servlet.forward.path_info");
      forward_query_string = (String) req.getAttribute("javax.servlet.forward.query_string");

      include_request_uri = (String) req.getAttribute("javax.servlet.include.request_uri");
      include_context_path = (String) req.getAttribute("javax.servlet.include.context_path");
      include_servlet_path = (String) req.getAttribute("javax.servlet.include.servlet_path");
      include_path_info = (String) req.getAttribute("javax.servlet.include.path_info");
      include_query_string = (String) req.getAttribute("javax.servlet.include.query_string");

      method_request_uri = req.getRequestURI();
      method_context_path = req.getContextPath();
      method_servlet_path = req.getServletPath();
      method_path_info = req.getPathInfo();
      method_path_xlated = req.getPathTranslated();
      method_query_string = req.getQueryString();
      
      type = req.getDispatcherType().name();
      isAsyncSupported = req.isAsyncSupported();
      
      Map<String, String[]> pmap = req.getParameterMap();
      for (String key : pmap.keySet()) {
         params.put(key, Arrays.asList(pmap.get(key)));
      }
}
 
Example 12
Source File: LoginCredentials.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public LoginCredentials(HttpServletRequest request) {
	this.identifier = request.getParameter("eid");
	this.password = request.getParameter("pw");
	this.remoteAddr = request.getRemoteAddr();
	this.parameterMap = request.getParameterMap();
	this.request = request;
}
 
Example 13
Source File: RequestUtils.java    From quartz-web with Apache License 2.0 5 votes vote down vote up
/**
 * 获取reuqest中的map数据
 * 数据结构 mapKeyPrefix_index,value
 *
 * @param request      request请求
 * @param mapKeyPrefix key前缀
 * @return map数据
 */
public static Map<String, String> getMapData(HttpServletRequest request, String mapKeyPrefix,String mapValuePrefix) {

    Map<String,String> mapData = new LinkedHashMap<String, String>();
    Map<String, String[]> requestParameterMap = request.getParameterMap();

    for (Map.Entry<String, String[]> dataEntry : requestParameterMap.entrySet()) {
        String key = dataEntry.getKey();
        // 是否为构造函数参数
        if (key.startsWith(mapKeyPrefix)) {

            String[] dataMapKeyInfo = key.split("_");

            //参数名称是否正确
            if (dataMapKeyInfo.length != 2) {
                throw new UnsupportedTranslateException("resolve request map data format exception");
            }
            //序号
            String index = dataMapKeyInfo[1];
            if (!StringUtils.isIntegerGTNumber(index, -1)) {
                throw new UnsupportedTranslateException("resolve request map data format exception");
            }

            mapData.put(request.getParameter(mapKeyPrefix + index), request.getParameter(mapValuePrefix + index));
        }
    }
    return mapData;
}
 
Example 14
Source File: BenchmarkTest01382.java    From Benchmark with GNU General Public License v2.0 5 votes vote down vote up
@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
	
		java.util.Map<String,String[]> map = request.getParameterMap();
		String param = "";
		if (!map.isEmpty()) {
			String[] values = map.get("BenchmarkTest01382");
			if (values != null) param = values[0];
		}
		

		String bar = new Test().doSomething(request, param);
		
		String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='"+ bar +"'";
				
		try {
			java.sql.Connection connection = org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection();
			java.sql.PreparedStatement statement = connection.prepareStatement( sql, 
			    java.sql.Statement.RETURN_GENERATED_KEYS );
			    statement.setString(1, "foo");
			statement.execute();
            org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response);
		} catch (java.sql.SQLException e) {
			if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
        		response.getWriter().println(
"Error processing request."
);
        		return;
        	}
			else throw new ServletException(e);
		}
	}
 
Example 15
Source File: TestBlobUploadServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);

  // Verify all of the header accessors contain the upload header.
  if (!req.getHeader(UPLOAD_HEADER).equals("true")
      || !Collections.list(req.getHeaderNames()).contains(UPLOAD_HEADER)
      || !Collections.list(req.getHeaders(UPLOAD_HEADER)).contains("true")) {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expected header to be present: " + UPLOAD_HEADER);
    return;
  }
  try {
    req.getIntHeader(UPLOAD_HEADER);
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expected header to be present: " + UPLOAD_HEADER);
    return;
  } catch (NumberFormatException e) {
  }

  Map<String, String[]> parameterMap = req.getParameterMap();
  if (!parameterMap.containsKey("text1")) {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expected text1 to be found in the parameterMap.");
  }
  if (req.getParameter("text1") == null || req.getParameter("text1").length() == 0) {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Expected non-empty text1 field.");
    return;
  }

  // Verify blob keys are present.
  if (blobs.size() == 1) {
    BlobKey blobKey =
        blobs
            .entrySet()
            .iterator()
            .next()
            .getValue();
    resp.sendRedirect("/serve-blob?key=" + blobKey.getKeyString());
  } else {
    resp.sendError(
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "Expect one uploaded blob, got " + blobs.size());
  }
}
 
Example 16
Source File: FirmwareController.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
   * Here
   * @param request
   * @param locale
   * @param model
   * @return
   * @throws Exception
   */
  @RequestMapping(value="/device/status.do")
  public String deviceUpgradeScheduleStatus(HttpServletRequest request,
  		                   Locale locale,
  		                   ModelMap model)
          throws Exception {

HttpSession session = request.getSession(false);
if(session != null){
	//페이지 권한 확인
	GroupAuthorization requestAuth = (GroupAuthorization) session.getAttribute("requestAuth");
	if(!requestAuth.getAuthorizationDBRead().equals("1")){
		model.addAttribute("authMessage", "사용자관리 메뉴는 읽기 권한이 없습니다.");
		return "forward:" + HeritProperties.getProperty("Globals.MainPage");
	}
}

/*
String deviceModel = po.getDeviceModel();
String[] tokens = deviceModel.split("\\|");
if (tokens.length == 2) {
	po.setOui(tokens[0]);
	po.setModelName(tokens[1]);
}
*/

Map<String, String[]> paramMap = request.getParameterMap();

String[] tokens = paramMap.get("deviceModelId");
String deviceModelId = "";
String firmwareId = "";
List firmwareList = null;
List versionList = null;
  	if (tokens != null && tokens.length > 0) {
  		deviceModelId = tokens[0];
  		firmwareList = firmwareService.getFirmwareListWithDeviceModelId(deviceModelId);
  	}
tokens = paramMap.get("firmwareId");
  	if (tokens != null && tokens.length > 0) {    		
  		firmwareId = tokens[0];
  		versionList = firmwareService.getFirmwareVersionList(firmwareId);
  	}

int page = StringUtil.parseInt(request.getParameter("page"), 1);
      PagingUtil resultPagingUtil = deviceService.getDeviceFirmwareListPaging(page, 0, paramMap);
      List deviceModelList = deviceService.getDeviceModelList(null);
      

/**
 * 데이터 셋팅
 */
model.addAttribute("page", page);
model.addAttribute("param", paramMap);
model.addAttribute("firmwareList", firmwareList);
model.addAttribute("deviceModelList", deviceModelList);
model.addAttribute("versionList", versionList);
model.addAttribute("resultPagingUtil", resultPagingUtil);

ObjectMapper objectMapper = new ObjectMapper();

model.addAttribute("paramJson", objectMapper.writeValueAsString(paramMap));
model.addAttribute("firmwareListJson", objectMapper.writeValueAsString(firmwareList));
model.addAttribute("versionListJson", objectMapper.writeValueAsString(versionList));
model.addAttribute("deviceModelListJson", objectMapper.writeValueAsString(deviceModelList));
model.addAttribute("resultPagingUtilJson", objectMapper.writeValueAsString(resultPagingUtil));

  	return "/v2/firmware/status";
  }
 
Example 17
Source File: FirmwareController.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@RequestMapping(value="/device/upgrade.do")
  public String deviceUpgrade(HttpServletRequest request,
  		                   Locale locale,
  		                   ModelMap model)
          throws Exception {

HttpSession session = request.getSession(false);
if(session != null){
	//페이지 권한 확인
	GroupAuthorization requestAuth = (GroupAuthorization) session.getAttribute("requestAuth");
	if(!requestAuth.getAuthorizationDBRead().equals("1")){
		model.addAttribute("authMessage", "사용자관리 메뉴는 읽기 권한이 없습니다.");
		return "forward:" + HeritProperties.getProperty("Globals.MainPage");
	}
}

/*
String deviceModel = po.getDeviceModel();
String[] tokens = deviceModel.split("\\|");
if (tokens.length == 2) {
	po.setOui(tokens[0]);
	po.setModelName(tokens[1]);
}
*/

Map<String, String[]> paramMap = request.getParameterMap();

String[] tokens = paramMap.get("deviceModelId");
String deviceModelId = "";
String firmwareId = "";
List firmwareList = null;
List versionList = null;
  	if (tokens != null && tokens.length > 0) {
  		deviceModelId = tokens[0];
  		firmwareList = firmwareService.getFirmwareListWithDeviceModelId(deviceModelId);
  	}
tokens = paramMap.get("firmwareId");
  	if (tokens != null && tokens.length > 0) {    		
  		firmwareId = tokens[0];
  		versionList = firmwareService.getFirmwareVersionList(firmwareId);
  	}

int page = StringUtil.parseInt(request.getParameter("page"), 1);
      PagingUtil resultPagingUtil = deviceService.getDeviceFirmwareListPaging(page, 0, paramMap);
      List deviceModelList = deviceService.getDeviceModelList(null);
      

/**
 * 데이터 셋팅
 */
model.addAttribute("page", page);
model.addAttribute("param", paramMap);
model.addAttribute("firmwareList", firmwareList);
model.addAttribute("deviceModelList", deviceModelList);
model.addAttribute("versionList", versionList);
model.addAttribute("resultPagingUtil", resultPagingUtil);

ObjectMapper objectMapper = new ObjectMapper();

model.addAttribute("paramJson", objectMapper.writeValueAsString(paramMap));
model.addAttribute("firmwareListJson", objectMapper.writeValueAsString(firmwareList));
model.addAttribute("versionListJson", objectMapper.writeValueAsString(versionList));
model.addAttribute("deviceModelListJson", objectMapper.writeValueAsString(deviceModelList));
model.addAttribute("resultPagingUtilJson", objectMapper.writeValueAsString(resultPagingUtil));

  	return "/v2/firmware/upgrade";
  }
 
Example 18
Source File: BenchmarkTest00481.java    From Benchmark with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	response.setContentType("text/html;charset=UTF-8");

	java.util.Map<String,String[]> map = request.getParameterMap();
	String param = "";
	if (!map.isEmpty()) {
		String[] values = map.get("BenchmarkTest00481");
		if (values != null) param = values[0];
	}
	
	
	
	String bar;
	
	// Simple if statement that assigns constant to bar on true condition
	int num = 86;
	if ( (7*42) - num > 200 )
	   bar = "This_should_always_happen"; 
	else bar = param;
	
	
	java.util.List<String> argList = new java.util.ArrayList<String>();
	
	String osName = System.getProperty("os.name");
       if (osName.indexOf("Windows") != -1) {
       	argList.add("cmd.exe");
       	argList.add("/c");
       } else {
       	argList.add("sh");
       	argList.add("-c");
       }
       argList.add("echo " + bar);

	ProcessBuilder pb = new ProcessBuilder(argList);

	try {
		Process p = pb.start();
		org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response);
	} catch (IOException e) {
		System.out.println("Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case");
           throw new ServletException(e);
	}
}
 
Example 19
Source File: SysUserController.java    From teaching with Apache License 2.0 4 votes vote down vote up
@PermissionData(pageComponent = "system/UserList")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public Result<IPage<SysUserModel>> queryPageList(SysUserModel user, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
		Result<IPage<SysUserModel>> result = new Result<IPage<SysUserModel>>();
//		QueryWrapper<SysUserModel> queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
        Map<String, String[]> param = req.getParameterMap();
        String[] areaRaw = param.get("area");
        String provinceId = null;
        String cityId = null;
        if (areaRaw != null && areaRaw.length == 1){
            JSONObject area = JSONObject.parseObject(areaRaw[0]);
            provinceId = area.getString("provinceId");
            cityId = area.getString("cityId");
        }
        String roleId = param.containsKey("roleId")?param.get("roleId")[0]:null;
        String departName = param.containsKey("departName")?param.get("departName")[0]:null;
        QueryWrapper<SysUserModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(org.apache.commons.lang3.StringUtils.isNotEmpty(provinceId), "sys_user.province", provinceId);
        queryWrapper.eq(org.apache.commons.lang3.StringUtils.isNotEmpty(cityId),"sys_user.city", cityId);
        queryWrapper.eq(org.apache.commons.lang3.StringUtils.isNotEmpty(roleId), "role_id", roleId);
        queryWrapper.eq(org.apache.commons.lang3.StringUtils.isNotEmpty(departName), "sys_depart.depart_name", departName);

        QueryGenerator.installMplus(queryWrapper, user, req.getParameterMap());

		Page<SysUserModel> page = new Page<SysUserModel>(pageNo, pageSize);
        IPage<SysUserModel> pageList = sysUserService.getUserList(page, queryWrapper);

//		IPage<SysUserModel> pageList = sysUserService.page(page, queryWrapper);

		//批量查询用户的所属部门
        //step.1 先拿到全部的 useids
        //step.2 通过 useids,一次性查询用户的所属部门名字
//        List<String> userIds = pageList.getRecords().stream().map(SysUser::getId).collect(Collectors.toList());
//        if(userIds!=null && userIds.size()>0){
//            Map<String,String>  useDepNames = sysUserService.getDepNamesByUserIds(userIds);
//            pageList.getRecords().forEach(item->{
//                //TODO 临时借用这个字段用于页面展示
//                item.setOrgCode(useDepNames.get(item.getId()));
//            });
//        }
		result.setSuccess(true);
		result.setResult(pageList);
		log.info(pageList.toString());
		return result;
	}
 
Example 20
Source File: BenchmarkTest01366.java    From Benchmark with GNU General Public License v2.0 4 votes vote down vote up
@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
	
		java.util.Map<String,String[]> map = request.getParameterMap();
		String param = "";
		if (!map.isEmpty()) {
			String[] values = map.get("BenchmarkTest01366");
			if (values != null) param = values[0];
		}
		

		String bar = new Test().doSomething(request, param);
		
	    try {
		    java.security.SecureRandom secureRandomGenerator = java.security.SecureRandom.getInstance("SHA1PRNG");
		
		    // Get 40 random bytes
		    byte[] randomBytes = new byte[40];
		    secureRandomGenerator.nextBytes(randomBytes);
		    
	        String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true);
	
			String user = "SafeByron";
			String fullClassName = this.getClass().getName();
			String testCaseNumber = fullClassName.substring(fullClassName.lastIndexOf('.')+1+"BenchmarkTest".length());
			user+= testCaseNumber;
			
			String cookieName = "rememberMe" + testCaseNumber;
			
			boolean foundUser = false;
			javax.servlet.http.Cookie[] cookies = request.getCookies();
			if (cookies != null) {
				for (int i = 0; !foundUser && i < cookies.length; i++) {
					javax.servlet.http.Cookie cookie = cookies[i];
					if (cookieName.equals(cookie.getName())) {
						if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) {
							foundUser = true;
						}
					}
				}
			}
			
			if (foundUser) {
				response.getWriter().println(
"Welcome back: " + user + "<br/>"
);
			
			} else {			
				javax.servlet.http.Cookie rememberMe = new javax.servlet.http.Cookie(cookieName, rememberMeKey);
				rememberMe.setSecure(true);
	//			rememberMe.setPath("/benchmark/" + this.getClass().getSimpleName());
				rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet 
															 // e.g., /benchmark/sql-01/BenchmarkTest01001
				request.getSession().setAttribute(cookieName, rememberMeKey);
response.addCookie(rememberMe);
response.getWriter().println(
user + " has been remembered with cookie: " + rememberMe.getName() 
						+ " whose value is: " + rememberMe.getValue() + "<br/>"
);
			}  
	    } catch (java.security.NoSuchAlgorithmException e) {
			System.out.println("Problem executing SecureRandom.nextBytes() - TestCase");
			throw new ServletException(e);
	    } finally {
			response.getWriter().println(
"Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"
);
	    }
	}