com.akaxin.proto.core.PluginProto Java Examples

The following examples show how to use com.akaxin.proto.core.PluginProto. 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: ConfigManageController.java    From openzaly with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/index")
public String homePage(@RequestBody byte[] bodyParam) {
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		String siteUserId = getRequestSiteUserId(pluginPackage);
		boolean isManager = SiteConfig.isSiteManager(siteUserId);
		if (!isManager) {
			throw new UserPermissionException("Current user is not a manager");
		}
		return "admin";
	} catch (InvalidProtocolBufferException e) {
		logger.error("to basic manage error", e);
	} catch (UserPermissionException u) {
		logger.error("to basic manage error : " + u.getMessage());
	}
	return "error";
}
 
Example #2
Source File: UserSquareController.java    From openzaly with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/index")
public ModelAndView toIndex(@RequestBody byte[] bodyParam) {
	ModelAndView modelAndView = new ModelAndView("siteMember/siteMember");
	Map<String, Object> model = modelAndView.getModel();
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
		UserProfileBean userProfile = userService.getUserProfile(siteUserId);
		model.put("site_user_id", siteUserId);
		model.put("site_user_name", userProfile.getUserName());
	} catch (InvalidProtocolBufferException e) {
		logger.error("to user square error", e);
		return new ModelAndView("siteMember/error");
	}

	return modelAndView;
}
 
Example #3
Source File: ConfigManageController.java    From openzaly with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/index")
public String homePage(@RequestBody byte[] bodyParam) {
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		String siteUserId = getRequestSiteUserId(pluginPackage);
		boolean isManager = SiteConfig.isSiteManager(siteUserId);
		if (!isManager) {
			throw new UserPermissionException("Current user is not a manager");
		}
		return "admin";
	} catch (InvalidProtocolBufferException e) {
		logger.error("to basic manage error", e);
	} catch (UserPermissionException u) {
		logger.error("to basic manage error : " + u.getMessage());
	}
	return "error";
}
 
Example #4
Source File: UserManageController.java    From openzaly with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, value = "delUser")
@ResponseBody
public String deleteUser(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		String siteUserId = getRequestSiteUserId(pluginPackage);

		if (isManager(siteUserId)) {
			Map<String, String> reqMap = getRequestDataMap(pluginPackage);
			String delUserID = reqMap.get("siteUserId");
			if (userService.delUser(delUserID)) {
				return SUCCESS;
			}
		} else {
			return NO_PERMISSION;
		}
	} catch (Exception e) {
		logger.error("del User error", e);
	}
	return ERROR;
}
 
Example #5
Source File: UserManageController.java    From openzaly with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, value = "delUser")
@ResponseBody
public String deleteUser(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		String siteUserId = getRequestSiteUserId(pluginPackage);

		if (isManager(siteUserId)) {
			Map<String, String> reqMap = getRequestDataMap(pluginPackage);
			String delUserID = reqMap.get("siteUserId");
			if (userService.delUser(delUserID)) {
				return SUCCESS;
			}
		} else {
			return NO_PERMISSION;
		}
	} catch (Exception e) {
		logger.error("del User error", e);
	}
	return ERROR;
}
 
Example #6
Source File: UserSquareController.java    From openzaly with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/index")
public ModelAndView toIndex(@RequestBody byte[] bodyParam) {
	ModelAndView modelAndView = new ModelAndView("siteMember/siteMember");
	Map<String, Object> model = modelAndView.getModel();
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
		UserProfileBean userProfile = userService.getUserProfile(siteUserId);
		model.put("site_user_id", siteUserId);
		model.put("site_user_name", userProfile.getUserName());
	} catch (InvalidProtocolBufferException e) {
		logger.error("to user square error", e);
		return new ModelAndView("siteMember/error");
	}

	return modelAndView;
}
 
Example #7
Source File: UserSquareController.java    From wind-im with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/index")
public ModelAndView toIndex(@RequestBody byte[] bodyParam) {
	ModelAndView modelAndView = new ModelAndView("siteMember/siteMember");
	Map<String, Object> model = modelAndView.getModel();
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
		UserProfileBean userProfile = userService.getUserProfile(siteUserId);
		model.put("site_user_id", siteUserId);
		model.put("site_user_name", userProfile.getUserName());
	} catch (InvalidProtocolBufferException e) {
		logger.error("to user square error", e);
		return new ModelAndView("siteMember/error");
	}

	return modelAndView;
}
 
Example #8
Source File: ConfigManageController.java    From wind-im with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/index")
public String homePage(@RequestBody byte[] bodyParam) {
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		String siteUserId = getRequestSiteUserId(pluginPackage);
		boolean isManager = SiteConfig.isSiteManager(siteUserId);
		if (!isManager) {
			throw new UserPermissionException("Current user is not a manager");
		}
		return "admin";
	} catch (InvalidProtocolBufferException e) {
		logger.error("to basic manage error", e);
	} catch (UserPermissionException u) {
		logger.error("to basic manage error : " + u.getMessage());
	}
	return "error";
}
 
Example #9
Source File: UserManageController.java    From wind-im with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, value = "delUser")
@ResponseBody
public String deleteUser(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		String siteUserId = getRequestSiteUserId(pluginPackage);

		if (isManager(siteUserId)) {
			Map<String, String> reqMap = getRequestDataMap(pluginPackage);
			String delUserID = reqMap.get("siteUserId");
			if (userService.delUser(delUserID)) {
				return SUCCESS;
			}
		} else {
			return NO_PERMISSION;
		}
	} catch (Exception e) {
		logger.error("del User error", e);
	}
	return ERROR;
}
 
Example #10
Source File: UserSquareController.java    From openzaly with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "/pullMemberList")
@ResponseBody
public Map<String, Object> getMemberList(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	Map<String, Object> results = new HashMap<String, Object>();
	boolean nodata = true;
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);

		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);

		int pageNum = Integer.valueOf(ReqMap.get("page"));
		List<SimpleUserBean> userList = userService.getUserList(pageNum, 20);
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		if (userList != null && userList.size() > 0) {
			if (20 == userList.size()) {
				nodata = false;
			}
			for (SimpleUserBean bean : userList) {
				Map<String, String> memberMap = new HashMap<String, String>();
				if (siteUserId != bean.getUserId()) {
					memberMap.put("site_user_id", bean.getUserId());
					memberMap.put("site_user_name", bean.getUserName());
					UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
							bean.getUserId());
					memberMap.put("site_user_relation", String.valueOf(userRelation.getNumber()));
				}
				data.add(memberMap);
			}
		}
		results.put("Data", data);

	} catch (Exception e) {
		logger.error("get Member list error", e);
	}
	results.put("loading", nodata);
	return results;
}
 
Example #11
Source File: ApiPluginService.java    From openzaly with Apache License 2.0 5 votes vote down vote up
private PluginProto.Plugin.Builder getPluginProtoBuilder(PluginBean bean) {
	PluginProto.Plugin.Builder pluginBuilder = PluginProto.Plugin.newBuilder();
	pluginBuilder.setId(String.valueOf(bean.getId()));
	if (StringUtils.isNotBlank(bean.getName())) {
		pluginBuilder.setName(bean.getName());
	}
	if (StringUtils.isNotBlank(bean.getIcon())) {
		pluginBuilder.setIcon(bean.getIcon());
	}
	if (StringUtils.isNotBlank(bean.getUrlPage())) {
		pluginBuilder.setUrlPage(bean.getUrlPage());
	}
	if (StringUtils.isNotBlank(bean.getApiUrl())) {
		pluginBuilder.setApiUrl(bean.getApiUrl());
	}
	if (StringUtils.isNotBlank(bean.getAuthKey())) {
		pluginBuilder.setAuthKey(bean.getAuthKey());
	}
	if (StringUtils.isNotBlank(bean.getAllowedIp())) {
		pluginBuilder.setAllowedIp(bean.getAllowedIp());
	}
	pluginBuilder.setOrder(bean.getSort());
	pluginBuilder.setPositionValue(bean.getPosition());
	pluginBuilder.setPermissionStatusValue(bean.getPermissionStatus());
	pluginBuilder.setDisplayModeValue(bean.getDisplayMode());
	// pluginBuilder.setEncryptedSessionIdBase64(value)
	return pluginBuilder;
}
 
Example #12
Source File: UserSquareController.java    From openzaly with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/applyFriend")
@ResponseBody
public String[] applyFriend(@RequestBody byte[] bodyParam) {
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);
		String friendSiteUserId = ReqMap.get("site_user_id");
		String apply_reason = ReqMap.get("apply_reason");
		if (StringUtils.isBlank(siteUserId)) {
			return new String[] { "添加失败", "0" };
		} else if (siteUserId.equals(friendSiteUserId)) {

		} else {
			int applyTimes = UserFriendDao.getInstance().getApplyCount(friendSiteUserId, siteUserId);
			if (applyTimes >= 5) {
				return new String[] { "失败,次数过多", "0" };

			} else {
				if (UserFriendDao.getInstance().saveFriendApply(siteUserId, friendSiteUserId, apply_reason)) {
					new User2Notice().applyFriendNotice(siteUserId, friendSiteUserId);
					// 同时下发一条PUSH消息
					if (applyTimes < 2) {
						PushNotification.sendAddFriend(siteUserId, friendSiteUserId);
					}
					return new String[] { "成功", friendSiteUserId };
				}
			}
		}
	} catch (InvalidProtocolBufferException e) {
		logger.error("Friend apply error.", e);
	}
	return new String[] { "添加失败", "0" };

}
 
Example #13
Source File: ApiPluginService.java    From openzaly with Apache License 2.0 5 votes vote down vote up
private PluginProto.Plugin.Builder getPluginProtoBuilder(PluginBean bean) {
	PluginProto.Plugin.Builder pluginBuilder = PluginProto.Plugin.newBuilder();
	pluginBuilder.setId(String.valueOf(bean.getId()));
	if (StringUtils.isNotBlank(bean.getName())) {
		pluginBuilder.setName(bean.getName());
	}
	if (StringUtils.isNotBlank(bean.getIcon())) {
		pluginBuilder.setIcon(bean.getIcon());
	}
	if (StringUtils.isNotBlank(bean.getUrlPage())) {
		pluginBuilder.setUrlPage(bean.getUrlPage());
	}
	if (StringUtils.isNotBlank(bean.getApiUrl())) {
		pluginBuilder.setApiUrl(bean.getApiUrl());
	}
	if (StringUtils.isNotBlank(bean.getAuthKey())) {
		pluginBuilder.setAuthKey(bean.getAuthKey());
	}
	if (StringUtils.isNotBlank(bean.getAllowedIp())) {
		pluginBuilder.setAllowedIp(bean.getAllowedIp());
	}
	pluginBuilder.setOrder(bean.getSort());
	pluginBuilder.setPositionValue(bean.getPosition());
	pluginBuilder.setPermissionStatusValue(bean.getPermissionStatus());
	pluginBuilder.setDisplayModeValue(bean.getDisplayMode());
	// pluginBuilder.setEncryptedSessionIdBase64(value)
	return pluginBuilder;
}
 
Example #14
Source File: SitePluginDao.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * 获取普通用户的扩展列表
 *
 * @param pageNum
 * @param pageSize
 * @param position
 * @return
 */
public List<PluginBean> getOrdinaryPluginPageList(int pageNum, int pageSize, int position) {
    List<PluginBean> pluginList = null;
    try {
        pluginList = pluginDao.getPluginPageList(pageNum, pageSize, position,
                PluginProto.PermissionStatus.AVAILABLE_VALUE);
    } catch (SQLException e) {
        logger.error("get plugin list error.", e);
    }
    return pluginList;
}
 
Example #15
Source File: UserSquareController.java    From openzaly with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/applyFriend")
@ResponseBody
public String[] applyFriend(@RequestBody byte[] bodyParam) {
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);
		String friendSiteUserId = ReqMap.get("site_user_id");
		String apply_reason = ReqMap.get("apply_reason");
		if (StringUtils.isBlank(siteUserId)) {
			return new String[] { "添加失败", "0" };
		} else if (siteUserId.equals(friendSiteUserId)) {

		} else {
			int applyTimes = UserFriendDao.getInstance().getApplyCount(friendSiteUserId, siteUserId);
			if (applyTimes >= 5) {
				return new String[] { "失败,次数过多", "0" };

			} else {
				if (UserFriendDao.getInstance().saveFriendApply(siteUserId, friendSiteUserId, apply_reason)) {
					new User2Notice().applyFriendNotice(siteUserId, friendSiteUserId);
					// 同时下发一条PUSH消息
					if (applyTimes < 2) {
						PushNotification.sendAddFriend(siteUserId, friendSiteUserId);
					}
					return new String[] { "成功", friendSiteUserId };
				}
			}
		}
	} catch (InvalidProtocolBufferException e) {
		logger.error("Friend apply error.", e);
	}
	return new String[] { "添加失败", "0" };

}
 
Example #16
Source File: UserSquareController.java    From openzaly with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "/pullMemberList")
@ResponseBody
public Map<String, Object> getMemberList(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	Map<String, Object> results = new HashMap<String, Object>();
	boolean nodata = true;
	int pageSize = 20;
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);

		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);

		int pageNum = Integer.valueOf(ReqMap.get("pageNum"));
		List<SimpleUserBean> userList = userService.getUserList(pageNum, pageSize);
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		if (userList != null && userList.size() > 0) {
			nodata = false;
			for (SimpleUserBean bean : userList) {
				Map<String, String> memberMap = new HashMap<String, String>();
				if (siteUserId != bean.getUserId()) {
					memberMap.put("site_user_id", bean.getUserId());
					memberMap.put("site_user_name", bean.getUserName());
					memberMap.put("site_user_photo", bean.getUserPhoto());
					UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
							bean.getUserId());
					memberMap.put("site_user_relation", String.valueOf(userRelation.getNumber()));
				}
				data.add(memberMap);
			}
		} 
		results.put("Data", data);

	} catch (Exception e) {
		logger.error("get Member list error", e);
	}
	results.put("loading", nodata);
	return results;
}
 
Example #17
Source File: SitePluginDao.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * 获取普通用户的扩展列表
 *
 * @param pageNum
 * @param pageSize
 * @param position
 * @return
 */
public List<PluginBean> getOrdinaryPluginPageList(int pageNum, int pageSize, int position) {
    List<PluginBean> pluginList = null;
    try {
        pluginList = pluginDao.getPluginPageList(pageNum, pageSize, position,
                PluginProto.PermissionStatus.AVAILABLE_VALUE);
    } catch (SQLException e) {
        logger.error("get plugin list error.", e);
    }
    return pluginList;
}
 
Example #18
Source File: ApiPluginService.java    From wind-im with Apache License 2.0 5 votes vote down vote up
private PluginProto.Plugin.Builder getPluginProtoBuilder(PluginBean bean) {
	PluginProto.Plugin.Builder pluginBuilder = PluginProto.Plugin.newBuilder();
	pluginBuilder.setId(String.valueOf(bean.getId()));
	if (StringUtils.isNotBlank(bean.getName())) {
		pluginBuilder.setName(bean.getName());
	}
	if (StringUtils.isNotBlank(bean.getIcon())) {
		pluginBuilder.setIcon(bean.getIcon());
	}
	if (StringUtils.isNotBlank(bean.getUrlPage())) {
		pluginBuilder.setUrlPage(bean.getUrlPage());
	}
	if (StringUtils.isNotBlank(bean.getApiUrl())) {
		pluginBuilder.setApiUrl(bean.getApiUrl());
	}
	if (StringUtils.isNotBlank(bean.getAuthKey())) {
		pluginBuilder.setAuthKey(bean.getAuthKey());
	}
	if (StringUtils.isNotBlank(bean.getAllowedIp())) {
		pluginBuilder.setAllowedIp(bean.getAllowedIp());
	}
	pluginBuilder.setOrder(bean.getSort());
	pluginBuilder.setPositionValue(bean.getPosition());
	pluginBuilder.setPermissionStatusValue(bean.getPermissionStatus());
	pluginBuilder.setDisplayModeValue(bean.getDisplayMode());
	// pluginBuilder.setEncryptedSessionIdBase64(value)
	return pluginBuilder;
}
 
Example #19
Source File: UserSquareController.java    From wind-im with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "/pullMemberList")
@ResponseBody
public Map<String, Object> getMemberList(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	Map<String, Object> results = new HashMap<String, Object>();
	boolean nodata = true;
	int pageSize = 20;
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);

		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);

		int pageNum = Integer.valueOf(ReqMap.get("pageNum"));
		List<SimpleUserBean> userList = userService.getUserList(pageNum, pageSize);
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		if (userList != null && userList.size() > 0) {
			nodata = false;
			for (SimpleUserBean bean : userList) {
				Map<String, String> memberMap = new HashMap<String, String>();
				if (siteUserId != bean.getUserId()) {
					memberMap.put("site_user_id", bean.getUserId());
					memberMap.put("site_user_name", bean.getUserName());
					memberMap.put("site_user_photo", bean.getUserPhoto());
					UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
							bean.getUserId());
					memberMap.put("site_user_relation", String.valueOf(userRelation.getNumber()));
				}
				data.add(memberMap);
			}
		} 
		results.put("Data", data);

	} catch (Exception e) {
		logger.error("get Member list error", e);
	}
	results.put("loading", nodata);
	return results;
}
 
Example #20
Source File: SitePluginDao.java    From wind-im with Apache License 2.0 5 votes vote down vote up
/**
 * 获取普通用户的扩展列表
 *
 * @param pageNum
 * @param pageSize
 * @param position
 * @return
 */
public List<PluginBean> getOrdinaryPluginPageList(int pageNum, int pageSize, int position) {
    List<PluginBean> pluginList = null;
    try {
        pluginList = pluginDao.getPluginPageList(pageNum, pageSize, position,
                PluginProto.PermissionStatus.AVAILABLE_VALUE);
    } catch (SQLException e) {
        logger.error("get plugin list error.", e);
    }
    return pluginList;
}
 
Example #21
Source File: UserSquareController.java    From wind-im with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/applyFriend")
@ResponseBody
public String[] applyFriend(@RequestBody byte[] bodyParam) {
	PluginProto.ProxyPluginPackage pluginPackage = null;
	try {
		pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);
		String friendSiteUserId = ReqMap.get("site_user_id");
		String apply_reason = ReqMap.get("apply_reason");
		if (StringUtils.isBlank(siteUserId)) {
			return new String[] { "添加失败", "0" };
		} else if (siteUserId.equals(friendSiteUserId)) {

		} else {
			int applyTimes = UserFriendDao.getInstance().getApplyCount(friendSiteUserId, siteUserId);
			if (applyTimes >= 5) {
				return new String[] { "失败,次数过多", "0" };

			} else {
				if (UserFriendDao.getInstance().saveFriendApply(siteUserId, friendSiteUserId, apply_reason)) {
					new User2Notice().applyFriendNotice(siteUserId, friendSiteUserId);
					// 同时下发一条PUSH消息
					if (applyTimes < 2) {
						PushNotification.sendAddFriend(siteUserId, friendSiteUserId);
					}
					return new String[] { "成功", friendSiteUserId };
				}
			}
		}
	} catch (InvalidProtocolBufferException e) {
		logger.error("Friend apply error.", e);
	}
	return new String[] { "添加失败", "0" };

}
 
Example #22
Source File: GroupManageController.java    From wind-im with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, Object> getRequestDataMapObj(PluginProto.ProxyPluginPackage pluginPackage) {
	return GsonUtils.fromJson(pluginPackage.getData(), Map.class);
}
 
Example #23
Source File: AbstractController.java    From openzaly with Apache License 2.0 4 votes vote down vote up
public String getRequestSiteUserId(PluginProto.ProxyPluginPackage pluginPackage) {
	Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
	return headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
}
 
Example #24
Source File: ApiPluginService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * <pre>
 * 	代理前台客户端中扩展的请求
 * 		1.界面请求后台一般使用http请求
 * 		2.使用tcp代理,代替http请求
 * </pre>
 * 
 * @param command
 * @return
 */
public CommandResponse proxy(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		ApiPluginProxyProto.ApiPluginProxyRequest request = ApiPluginProxyProto.ApiPluginProxyRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String pluginId = request.getPluginId();
		String requestApi = request.getApi();
		String requestParams = request.getParams();
		LogUtils.requestDebugLog(logger, command, request.toString());

		Map<Integer, String> header = command.getHeader();
		String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE);
		String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE);

		if (!StringUtils.isAnyBlank(siteUserId, pluginId, requestApi)) {
			PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId));
			if (bean != null && bean.getApiUrl() != null) {
				String pluginUrl = this.buildUrl(bean.getApiUrl(), requestApi, null);
				logger.debug("action={} pluginId={} api={} url={} params={}", command.getAction(), pluginId,
						requestApi, pluginUrl, requestParams);

				PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder();
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId);
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE,
						siteSessionId);
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId);
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE,
						String.valueOf(System.currentTimeMillis()));
				if (StringUtils.isNotEmpty(pluginRefere)) {
					packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere);
				}
				if (StringUtils.isNotEmpty(requestParams)) {
					packageBuilder.setData(requestParams);
				}

				byte[] httpContent = packageBuilder.build().toByteArray();
				String authKey = bean.getAuthKey();
				if (StringUtils.isNotEmpty(authKey)) {
					// AES 加密整个proto,通过http传输给plugin
					// byte[] tsk = AESCrypto.generateTSKey(bean.getAuthKey());
					byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1);
					byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent);
					httpContent = enPostContent;
				}

				byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pluginUrl, httpContent);
				if (httpResponse != null) {
					ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse
							.newBuilder().setData(ByteString.copyFrom(httpResponse)).build();
					commandResponse.setParams(response.toByteArray());// httpResposne,callback方法的回调方法参数
				}
				errCode = ErrorCode2.SUCCESS;
			}
		} else {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example #25
Source File: ApiPluginService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * <pre>
 * 获取插件扩展的展示页面,支持两种方式
 * 	1.非加密方式,此时扩展authkey不存在
 *  2.加密方式,此时扩展authkey存在
 * </pre>
 * 
 * @param command
 * @return
 */
public CommandResponse page(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		ApiPluginPageProto.ApiPluginPageRequest request = ApiPluginPageProto.ApiPluginPageRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String pluginId = request.getPluginId();
		String requestPage = request.getPage();// /index || index.php || index.html
		String requestParams = request.getParams();
		LogUtils.requestDebugLog(logger, command, request.toString());

		Map<Integer, String> header = command.getHeader();
		String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE);
		String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE);
		if (StringUtils.isNoneEmpty(siteUserId, pluginId)) {
			PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId));
			if (bean != null && bean.getApiUrl() != null) {
				String pageUrl = buildUrl(bean.getApiUrl(), requestPage, bean.getUrlPage());
				logger.debug("http request uri={}", pageUrl);

				PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder();
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId);
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE,
						siteSessionId);
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId);
				packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE,
						String.valueOf(System.currentTimeMillis()));
				if (StringUtils.isNotEmpty(pluginRefere)) {
					packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere);
				}
				if (StringUtils.isNotEmpty(requestParams)) {
					packageBuilder.setData(requestParams);
				}

				byte[] httpContent = packageBuilder.build().toByteArray();
				String authKey = bean.getAuthKey();
				if (StringUtils.isNotEmpty(authKey)) {
					// AES 加密整个proto,通过http传输给plugin
					byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1);
					byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent);
					httpContent = enPostContent;
				}

				byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pageUrl, httpContent);
				if (httpResponse != null) {
					ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse
							.newBuilder().setData(ByteString.copyFrom(httpResponse)).build();

					commandResponse.setParams(response.toByteArray());
					errCode = ErrorCode2.SUCCESS;
				} else {
					logger.error("http request uri={} response={}", pageUrl, httpResponse);
				}
			}
		} else {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example #26
Source File: ConfigManageController.java    From wind-im with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "/updateConfig")
@ResponseBody
public String updateSiteConfig(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);

		String siteUserId = getRequestSiteUserId(pluginPackage);

		if (!isManager(siteUserId)) {
			throw new UserPermissionException("Current user is not a manager");
		}
		Map<String, String> dataMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);
		logger.info("siteUserId={} update config={}", siteUserId, dataMap);
		Map<Integer, String> configMap = new HashMap<Integer, String>();
		if (StringUtils.isNotEmpty(trim(dataMap.get("site_name")))) {
			configMap.put(ConfigProto.ConfigKey.SITE_NAME_VALUE, trim(dataMap.get("site_name")));
		}
		if (StringUtils.isNotEmpty(trim(dataMap.get("site_address")))) {
			configMap.put(ConfigProto.ConfigKey.SITE_ADDRESS_VALUE, trim(dataMap.get("site_address")));
		}
		if (StringUtils.isNotEmpty(trim(dataMap.get("site_port")))) {
			configMap.put(ConfigProto.ConfigKey.SITE_PORT_VALUE, trim(dataMap.get("site_port")));
		}
		if (StringUtils.isNotEmpty(trim(dataMap.get("group_members_count")))) {
			configMap.put(ConfigProto.ConfigKey.GROUP_MEMBERS_COUNT_VALUE,
					trim(dataMap.get("group_members_count")));
		}
		if (StringUtils.isNotEmpty(trim(dataMap.get("pic_path")))) {
			configMap.put(ConfigProto.ConfigKey.PIC_PATH_VALUE, trim(dataMap.get("pic_path")));
		}
		if (StringUtils.isNotEmpty(dataMap.get("site_logo"))) {
			configMap.put(ConfigProto.ConfigKey.SITE_LOGO_VALUE, dataMap.get("site_logo"));
		}
		if (StringUtils.isNotEmpty(dataMap.get("uic_status"))) {
			configMap.put(ConfigProto.ConfigKey.INVITE_CODE_STATUS_VALUE, dataMap.get("uic_status"));
		}
		if (StringUtils.isNotEmpty(dataMap.get("realName_status"))) {
			configMap.put(ConfigProto.ConfigKey.REALNAME_STATUS_VALUE, dataMap.get("realName_status"));
		}
		if (StringUtils.isNotEmpty(dataMap.get("u2_encryption_status"))) {
			configMap.put(ConfigProto.ConfigKey.U2_ENCRYPTION_STATUS_VALUE, dataMap.get("u2_encryption_status"));
		}

		if (StringUtils.isNotEmpty(dataMap.get("add_friends_status"))) {
			configMap.put(ConfigProto.ConfigKey.CONFIG_FRIEND_REQUEST_VALUE, dataMap.get("add_friends_status"));
		}

		if (StringUtils.isNotEmpty(dataMap.get("create_groups_status"))) {
			configMap.put(ConfigProto.ConfigKey.CONFIG_CREATE_GROUP_VALUE, dataMap.get("create_groups_status"));
		}

		if (StringUtils.isNotEmpty(dataMap.get("group_qrcode_expire_time"))) {
			configMap.put(ConfigProto.ConfigKey.GROUP_QR_EXPIRE_TIME_VALUE,
					dataMap.get("group_qrcode_expire_time"));
		}

		if (StringUtils.isNotEmpty(dataMap.get("push_client_status"))) {
			configMap.put(ConfigProto.ConfigKey.PUSH_CLIENT_STATUS_VALUE, dataMap.get("push_client_status"));
		}
		if (StringUtils.isNotEmpty(dataMap.get("log_level"))) {
			String logLevel = dataMap.get("log_level");
			configMap.put(ConfigProto.ConfigKey.LOG_LEVEL_VALUE, logLevel);
			Level level = Level.INFO;
			if ("DEBUG".equalsIgnoreCase(logLevel)) {
				level = Level.DEBUG;
			} else if ("ERROR".equalsIgnoreCase(logLevel)) {
				level = Level.ERROR;
			}
			// 更新日志级别
			AkxLog4jManager.setLogLevel(level);
		}
		// 普通管理员无权限
		if (isAdmin(siteUserId) && StringUtils.isNotEmpty(trim(dataMap.get("site_manager")))) {
			configMap.put(ConfigProto.ConfigKey.SITE_MANAGER_VALUE, trim(dataMap.get("site_manager")));
		}
		if (configManageService.updateSiteConfig(siteUserId, configMap)) {
			return SUCCESS;
		}
	} catch (InvalidProtocolBufferException e) {
		logger.error("update site config error", e);
	} catch (UserPermissionException u) {
		logger.error("update site config error : " + u.getMessage());
		return NO_PERMISSION;
	}
	return ERROR;
}
 
Example #27
Source File: AbstractController.java    From wind-im with Apache License 2.0 4 votes vote down vote up
public String getRequestSiteUserId(PluginProto.ProxyPluginPackage pluginPackage) {
	Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
	return headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
}
 
Example #28
Source File: AbstractController.java    From wind-im with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, String> getRequestDataMap(PluginProto.ProxyPluginPackage pluginPackage) {
	return GsonUtils.fromJson(pluginPackage.getData(), Map.class);
}
 
Example #29
Source File: AbstractController.java    From openzaly with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, String> getRequestDataMap(PluginProto.ProxyPluginPackage pluginPackage) {
	return GsonUtils.fromJson(pluginPackage.getData(), Map.class);
}
 
Example #30
Source File: AbstractController.java    From openzaly with Apache License 2.0 4 votes vote down vote up
public String getRequestSiteUserId(PluginProto.ProxyPluginPackage pluginPackage) {
	Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
	return headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);
}