Skip to content

Commit

Permalink
Optimization, the check of groupName's values are allowed to contain …
Browse files Browse the repository at this point in the history
…hyphen characters (#149)
  • Loading branch information
gosonzhang authored and lizhiboo committed Dec 12, 2019
1 parent 3f1154d commit cddaf43
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 63 deletions.
Binary file modified docs/http_access_API_definition_cn.xls
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private StringBuilder adminQueryBrokerAllConsumerInfo(HttpServletRequest req) th
int index = 0;
StringBuilder sBuilder = new StringBuilder(1024);
String groupNameInput =
WebParameterUtils.validStringParameter("groupName",
WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH, false, null);
sBuilder.append("{\"result\":true,\"errCode\":0,\"errMsg\":\"Success!\",\"dataSet\":[");
Expand Down Expand Up @@ -365,7 +365,7 @@ private StringBuilder adminManuSetCurrentOffSet(HttpServletRequest req) throws E
req.getParameter("topicName"),
TBaseConstants.META_MAX_TOPICNAME_LENGTH, true, "");
final String groupName =
WebParameterUtils.validStringParameter("groupName",
WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH, true, "");
final String modifyUser =
Expand Down Expand Up @@ -476,7 +476,7 @@ private StringBuilder adminQueryCurrentGroupOffSet(HttpServletRequest req)
req.getParameter("topicName"),
TBaseConstants.META_MAX_TOPICNAME_LENGTH, true, "");
String groupName =
WebParameterUtils.validStringParameter("groupName",
WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH, true, "");
int partitionId =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,38 @@ public static String validStringParameter(String paramName, Object paramValue, i
return tmpParamValue;
}

/**
* Parse the parameter value from an object value to group string value
*
* @param paramName the parameter name
* @param paramValue the parameter value which is an object for parsing
* @param paramMaxLen the max length of string to return
* @param required a boolean value represent whether the parameter is must required
* @param defaultValue a default value returned if failed to parse value from the given object
* @return a string value of parameter
* @throws Exception if failed to parse the object
*/
public static String validGroupParameter(String paramName, Object paramValue, int paramMaxLen,
boolean required, String defaultValue) throws Exception {
String tmpParamValue = checkParamCommonRequires(paramName, paramValue, required);
if (TStringUtils.isBlank(tmpParamValue)) {
return defaultValue;
}
if (paramMaxLen != TBaseConstants.META_VALUE_UNDEFINED) {
if (tmpParamValue.length() > paramMaxLen) {
throw new Exception(new StringBuilder(512).append("the max length of ")
.append(paramName).append(" parameter is ")
.append(paramMaxLen).append(" characters").toString());
}
}
if (!tmpParamValue.matches(TBaseConstants.META_TMP_GROUP_VALUE)) {
throw new Exception(new StringBuilder(512).append("the value of ")
.append(paramName).append(" parameter must begin with a letter, ")
.append("can only contain characters,numbers,hyphen,and underscores").toString());
}
return tmpParamValue;
}

/**
* Parse the parameter value from an object value to ip address of string value
*
Expand Down Expand Up @@ -422,12 +454,11 @@ public static Set<String> getBatchGroupNames(String inputGroupName,
.append(TBaseConstants.META_MAX_GROUPNAME_LENGTH)
.append(" characters").toString());
}
if (!groupName.matches(TBaseConstants.META_TMP_STRING_VALUE)) {
if (!groupName.matches(TBaseConstants.META_TMP_GROUP_VALUE)) {
throw new Exception(sb.append("Illegal value: the value of ")
.append(groupName)
.append("in groupName parameter must begin with a letter, can only contain characters," +
"numbers,and underscores")
.toString());
.append(groupName)
.append("in groupName parameter must begin with a letter, can only contain ")
.append("characters,numbers,hyphen,and underscores").toString());
}
bathOpGroupNames.add(groupName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public StringBuilder getGroupAddressStrInfo(BrokerConfManage brokerConfManage) {
private StringBuilder getSubscribeInfo(HttpServletRequest req) {
StringBuilder strBuffer = new StringBuilder();
try {
String strConsumeGroup = WebParameterUtils.validStringParameter("consumeGroup",
String strConsumeGroup = WebParameterUtils.validGroupParameter("consumeGroup",
req.getParameter("consumeGroup"), TBaseConstants.META_MAX_GROUPNAME_LENGTH, false, "");
String strTopicName = WebParameterUtils.validStringParameter("topicName",
req.getParameter("topicName"), TBaseConstants.META_MAX_TOPICNAME_LENGTH, false, "");
Expand Down Expand Up @@ -413,7 +413,7 @@ private StringBuilder getSubscribeInfo(HttpServletRequest req) {
private StringBuilder getConsumeGroupDetailInfo(HttpServletRequest req) {
StringBuilder strBuffer = new StringBuilder(1024);
try {
String strConsumeGroup = WebParameterUtils.validStringParameter("consumeGroup",
String strConsumeGroup = WebParameterUtils.validGroupParameter("consumeGroup",
req.getParameter("consumeGroup"), TBaseConstants.META_MAX_GROUPNAME_LENGTH, true, "");
boolean isBandConsume = false;
boolean isNotAllocate = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public StringBuilder adminAddGroupFilterCondInfo(HttpServletRequest req) throws
req.getParameter("condStatus"),
false, 0, 0);
String groupName =
WebParameterUtils.validStringParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
final String strNewFilterConds =
WebParameterUtils.checkAndGetFilterConds(req.getParameter("filterConds"), true, sBuilder);
BdbTopicAuthControlEntity topicAuthControlEntity =
Expand Down Expand Up @@ -175,10 +175,10 @@ public StringBuilder adminBathAddGroupFilterCondInfo(HttpServletRequest req) thr
Map<String, Object> groupObject = filterJsonArray.get(j);
try {
String groupName =
WebParameterUtils.validStringParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
String groupTopicName =
WebParameterUtils.validStringParameter("topicName",
groupObject.get("topicName"),
Expand Down Expand Up @@ -285,10 +285,10 @@ public StringBuilder adminModGroupFilterCondInfo(HttpServletRequest req) throws
.append(" not configure in master's topic configure, please configure first!").toString());
}
String groupName =
WebParameterUtils.validStringParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
BdbGroupFilterCondEntity curFilterCondEntity =
brokerConfManage.getBdbAllowedGroupFilterConds(topicName, groupName);
if (curFilterCondEntity == null) {
Expand Down Expand Up @@ -374,10 +374,10 @@ public StringBuilder adminBathModGroupFilterCondInfo(HttpServletRequest req) thr
Map<String, Object> groupObject = jsonArray.get(j);
try {
String groupName =
WebParameterUtils.validStringParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
String topicName =
WebParameterUtils.validStringParameter("topicName",
groupObject.get("topicName"),
Expand Down Expand Up @@ -522,10 +522,10 @@ public StringBuilder adminRebalanceGroupAllocateInfo(HttpServletRequest req) thr
WebParameterUtils.reqAuthorizenCheck(master, brokerConfManage,
req.getParameter("confModAuthToken"));
String groupName =
WebParameterUtils.validStringParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
String modifyUser =
WebParameterUtils.validStringParameter("modifyUser",
req.getParameter("modifyUser"),
Expand Down Expand Up @@ -623,10 +623,10 @@ public StringBuilder adminQueryGroupFilterCondInfo(HttpServletRequest req) throw
TBaseConstants.META_MAX_TOPICNAME_LENGTH,
false, null));
webGroupFilterCondEntity
.setConsumerGroupName(WebParameterUtils.validStringParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
.setConsumerGroupName(WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
webGroupFilterCondEntity
.setCreateUser(WebParameterUtils.validStringParameter("createUser",
req.getParameter("createUser"),
Expand Down Expand Up @@ -785,10 +785,10 @@ public StringBuilder adminBathAddConsumerGroupInfo(HttpServletRequest req) throw
Map<String, Object> groupObject = jsonArray.get(j);
try {
String groupName =
WebParameterUtils.validStringParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
String groupTopicName =
WebParameterUtils.validStringParameter("topicName",
groupObject.get("topicName"),
Expand Down Expand Up @@ -872,11 +872,11 @@ public StringBuilder adminQueryConsumerGroupInfo(HttpServletRequest req) throws
TBaseConstants.META_MAX_TOPICNAME_LENGTH,
false, null));
webConsumerGroupEntity
.setConsumerGroupName(WebParameterUtils.validStringParameter(
"groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
.setConsumerGroupName(WebParameterUtils.validGroupParameter(
"groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
webConsumerGroupEntity
.setRecordCreateUser(WebParameterUtils.validStringParameter("createUser",
req.getParameter("createUser"),
Expand Down Expand Up @@ -1052,10 +1052,10 @@ public StringBuilder adminBathAddBlackGroupInfo(HttpServletRequest req) throws E
Map<String, Object> groupObject = jsonArray.get(j);
try {
String groupName =
WebParameterUtils.validStringParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
String groupTopicName =
WebParameterUtils.validStringParameter("topicName",
groupObject.get("topicName"),
Expand Down Expand Up @@ -1128,10 +1128,10 @@ public StringBuilder adminQueryBlackGroupInfo(HttpServletRequest req) throws Exc
TBaseConstants.META_MAX_TOPICNAME_LENGTH,
false, null));
webBlackGroupEntity
.setBlackGroupName(WebParameterUtils.validStringParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
.setBlackGroupName(WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
webBlackGroupEntity
.setCreateUser(WebParameterUtils.validStringParameter("createUser",
req.getParameter("createUser"),
Expand Down Expand Up @@ -1299,10 +1299,10 @@ public StringBuilder adminBathAddConsumeGroupSetting(HttpServletRequest req) thr
Map<String, Object> groupObject = groupNameJsonArray.get(j);
try {
String groupName =
WebParameterUtils.validStringParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
String groupCreateUser =
WebParameterUtils.validStringParameter("createUser",
groupObject.get("createUser"),
Expand Down Expand Up @@ -1361,10 +1361,10 @@ public StringBuilder adminQueryConsumeGroupSetting(HttpServletRequest req) throw
new BdbConsumeGroupSettingEntity();
try {
queryEntity
.setConsumeGroupName(WebParameterUtils.validStringParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
.setConsumeGroupName(WebParameterUtils.validGroupParameter("groupName",
req.getParameter("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
false, null));
queryEntity
.setCreateUser(WebParameterUtils.validStringParameter("createUser",
req.getParameter("createUser"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ private HashMap<String, BdbConsumerGroupEntity> getAuthConsumeGroupInfo(
for (int j = 0; j < authConsumeGroupSet.size(); j++) {
Map<String, String> groupObject = authConsumeGroupSet.get(j);
String groupName =
WebParameterUtils.validStringParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
WebParameterUtils.validGroupParameter("groupName",
groupObject.get("groupName"),
TBaseConstants.META_MAX_GROUPNAME_LENGTH,
true, "");
String groupTopicName =
WebParameterUtils.validStringParameter("topicName",
groupObject.get("topicName"),
Expand Down

0 comments on commit cddaf43

Please sign in to comment.