You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/04/30 06:16:38 UTC
[GitHub] [iotdb] RYH61 opened a new pull request, #5741: [IOTDB-3043] AuthorInfo serialization and deserialization interfaces
RYH61 opened a new pull request, #5741:
URL: https://github.com/apache/iotdb/pull/5741
AuthorInfo serialization and deserialization interfaces
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [iotdb] RYH61 closed pull request #5741: [IOTDB-3043] AuthorInfo serialization and deserialization interfaces
Posted by GitBox <gi...@apache.org>.
RYH61 closed pull request #5741: [IOTDB-3043] AuthorInfo serialization and deserialization interfaces
URL: https://github.com/apache/iotdb/pull/5741
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [iotdb] CRZbulabula commented on a diff in pull request #5741: [IOTDB-3043] AuthorInfo serialization and deserialization interfaces
Posted by GitBox <gi...@apache.org>.
CRZbulabula commented on code in PR #5741:
URL: https://github.com/apache/iotdb/pull/5741#discussion_r862367352
##########
node-commons/src/main/java/org/apache/iotdb/commons/utils/BasicStructureSerDeUtil.java:
##########
@@ -239,4 +241,78 @@ public static Map<Integer, List<Integer>> readIntMapLists(ByteBuffer buffer) {
}
return map;
}
+
+ /**
+ * write int set to buffer
+ *
+ * @param set Set<Integer> set
+ * @param buffer
+ * @return length
+ */
+ public static int writeIntSet(Set<Integer> set, ByteBuffer buffer) {
+ if (set == null) {
+ return write(-1, buffer);
+ }
+ int length = 0;
+ buffer.putInt(set.size());
+ for (Integer i : set) {
+ buffer.putInt(i);
+ }
+ return length;
+ }
+
+ /**
+ * read int set from buffer
+ *
+ * @param buffer
+ * @return Set<Integer>
+ */
+ public static Set<Integer> readIntSet(ByteBuffer buffer) {
+ int length = readInt(buffer);
+ if (length == -1) {
+ return null;
+ }
+ Set<Integer> set = new HashSet<>();
+ for (int i = 0; i < length; i++) {
+ set.add(readInt(buffer));
+ }
+ return set;
+ }
+
+ /**
+ * write string list to buffer
+ *
+ * @param strings List<String> strings
+ * @param buffer
+ * @return length
+ */
+ public static int writeStringList(List<String> strings, ByteBuffer buffer) {
+ if (strings == null) {
+ return write(-1, buffer);
+ }
+ int length = 0;
+ buffer.putInt(strings.size());
+ for (String s : strings) {
+ write(s, buffer);
+ }
+ return length;
+ }
+
+ /**
+ * read string list to buffer
+ *
+ * @param buffer
+ * @return List<String>
+ */
+ public static List<String> readStringList(ByteBuffer buffer) {
+ int length = readInt(buffer);
+ if (length == -1) {
+ return null;
+ }
+ List<String> strings = new ArrayList<>();
+ for (int i = 0; i < length; i++) {
+ strings.add(readString(buffer));
+ }
+ return strings;
+ }
Review Comment:
Please add tests in BasicStructureSerDeUtilTest.
##########
server/src/main/java/org/apache/iotdb/db/auth/authorizer/BasicAuthorizer.java:
##########
@@ -404,4 +410,105 @@ public void replaceAllUsers(Map<String, User> users) throws AuthException {
public void replaceAllRoles(Map<String, Role> roles) throws AuthException {
roleManager.replaceAllRoles(roles);
}
+
+ public IUserManager getUserManager() {
+ return userManager;
+ }
+
+ public void setUserManager(IUserManager userManager) {
+ this.userManager = userManager;
+ }
+
+ public IRoleManager getRoleManager() {
+ return roleManager;
+ }
+
+ public void setRoleManager(IRoleManager roleManager) {
+ this.roleManager = roleManager;
+ }
+
+ public ByteBuffer serialize(ByteBuffer buffer) {
+ Map<String, User> userMap = ((BasicUserManager) userManager).getUserMap();
+ Map<String, Role> roleMap = ((BasicRoleManager) roleManager).getRoleMap();
+ User user;
+ Role role;
+
+ // serialize userinfo
+ BasicStructureSerDeUtil.write(userMap.size(), buffer);
+
+ for (String userName : userMap.keySet()) {
+ user = userMap.get(userName);
+ BasicStructureSerDeUtil.write(user.getName(), buffer);
+ BasicStructureSerDeUtil.write(user.getPassword(), buffer);
+ BasicStructureSerDeUtil.write(user.getPrivilegeList().size(), buffer);
+ for (PathPrivilege pathPrivilege : user.getPrivilegeList()) {
+ BasicStructureSerDeUtil.writeIntSet(pathPrivilege.getPrivileges(), buffer);
+ BasicStructureSerDeUtil.write(pathPrivilege.getPath(), buffer);
+ }
+ BasicStructureSerDeUtil.writeStringList(user.getRoleList(), buffer);
+ }
+
+ // serialize roleinfo
+ BasicStructureSerDeUtil.write(roleMap.size(), buffer);
+ for (String roleName : roleMap.keySet()) {
+ role = roleMap.get(roleName);
+ BasicStructureSerDeUtil.write(role.getName(), buffer);
+ for (PathPrivilege pathPrivilege : role.getPrivilegeList()) {
+ BasicStructureSerDeUtil.writeIntSet(pathPrivilege.getPrivileges(), buffer);
+ BasicStructureSerDeUtil.write(pathPrivilege.getPath(), buffer);
+ }
+ }
+ return buffer;
+ }
+
+ public void deserialize(ByteBuffer buffer) {
+ Map<String, User> userMap = new HashMap<>();
+ Map<String, Role> roleMap = new HashMap<>();
+ String username;
+ String password;
+ List<PathPrivilege> privilegeList = null;
+ Set<Integer> privilegesId = null;
+ String path = null;
+ List<String> roleList;
+ String roleName;
+
+ // deserialize user
+ int userMapSize = BasicStructureSerDeUtil.readInt(buffer);
+ for (int i = 0; i < userMapSize; i++) {
+ username = BasicStructureSerDeUtil.readString(buffer);
+ password = BasicStructureSerDeUtil.readString(buffer);
+ int privilegesSize = BasicStructureSerDeUtil.readInt(buffer);
+ if (privilegesSize == 0) {
+ privilegeList = new ArrayList<>();
+ } else {
+ for (int m = 0; m < privilegesSize; m++) {
+ privilegesId = BasicStructureSerDeUtil.readIntSet(buffer);
+ path = BasicStructureSerDeUtil.readString(buffer);
+ }
+ privilegeList.add(new PathPrivilege(privilegesId, path));
+ }
+ roleList = BasicStructureSerDeUtil.readStringList(buffer);
+ userMap.put(username, new User(username, password, privilegeList, roleList));
+ }
+
+ // deserialize role
+ int roleMapSize = BasicStructureSerDeUtil.readInt(buffer);
+ for (int i = 0; i < roleMapSize; i++) {
+ roleName = BasicStructureSerDeUtil.readString(buffer);
+ int privilegesSize = BasicStructureSerDeUtil.readInt(buffer);
+ if (privilegesSize == 0) {
+ privilegeList = new ArrayList<>();
+ } else {
+ for (int m = 0; m < privilegesSize; m++) {
+ privilegesId = BasicStructureSerDeUtil.readIntSet(buffer);
+ path = BasicStructureSerDeUtil.readString(buffer);
+ }
+ privilegeList.add(new PathPrivilege(privilegesId, path));
+ }
+ roleMap.put(roleName, new Role(roleName, privilegeList));
+ }
+
+ ((BasicUserManager) userManager).setUserMap(userMap);
+ ((BasicRoleManager) roleManager).setRoleMap(roleMap);
+ }
Review Comment:
Please add serialize and deserialize tests for BasicAuthorizer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [iotdb] RYH61 commented on a diff in pull request #5741: [IOTDB-3043] AuthorInfo serialization and deserialization interfaces
Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5741:
URL: https://github.com/apache/iotdb/pull/5741#discussion_r862436119
##########
node-commons/src/main/java/org/apache/iotdb/commons/utils/BasicStructureSerDeUtil.java:
##########
@@ -239,4 +241,78 @@ public static Map<Integer, List<Integer>> readIntMapLists(ByteBuffer buffer) {
}
return map;
}
+
+ /**
+ * write int set to buffer
+ *
+ * @param set Set<Integer> set
+ * @param buffer
+ * @return length
+ */
+ public static int writeIntSet(Set<Integer> set, ByteBuffer buffer) {
+ if (set == null) {
+ return write(-1, buffer);
+ }
+ int length = 0;
+ buffer.putInt(set.size());
+ for (Integer i : set) {
+ buffer.putInt(i);
+ }
+ return length;
+ }
+
+ /**
+ * read int set from buffer
+ *
+ * @param buffer
+ * @return Set<Integer>
+ */
+ public static Set<Integer> readIntSet(ByteBuffer buffer) {
+ int length = readInt(buffer);
+ if (length == -1) {
+ return null;
+ }
+ Set<Integer> set = new HashSet<>();
+ for (int i = 0; i < length; i++) {
+ set.add(readInt(buffer));
+ }
+ return set;
+ }
+
+ /**
+ * write string list to buffer
+ *
+ * @param strings List<String> strings
+ * @param buffer
+ * @return length
+ */
+ public static int writeStringList(List<String> strings, ByteBuffer buffer) {
+ if (strings == null) {
+ return write(-1, buffer);
+ }
+ int length = 0;
+ buffer.putInt(strings.size());
+ for (String s : strings) {
+ write(s, buffer);
+ }
+ return length;
+ }
+
+ /**
+ * read string list to buffer
+ *
+ * @param buffer
+ * @return List<String>
+ */
+ public static List<String> readStringList(ByteBuffer buffer) {
+ int length = readInt(buffer);
+ if (length == -1) {
+ return null;
+ }
+ List<String> strings = new ArrayList<>();
+ for (int i = 0; i < length; i++) {
+ strings.add(readString(buffer));
+ }
+ return strings;
+ }
Review Comment:
fix
##########
server/src/main/java/org/apache/iotdb/db/auth/authorizer/BasicAuthorizer.java:
##########
@@ -404,4 +410,105 @@ public void replaceAllUsers(Map<String, User> users) throws AuthException {
public void replaceAllRoles(Map<String, Role> roles) throws AuthException {
roleManager.replaceAllRoles(roles);
}
+
+ public IUserManager getUserManager() {
+ return userManager;
+ }
+
+ public void setUserManager(IUserManager userManager) {
+ this.userManager = userManager;
+ }
+
+ public IRoleManager getRoleManager() {
+ return roleManager;
+ }
+
+ public void setRoleManager(IRoleManager roleManager) {
+ this.roleManager = roleManager;
+ }
+
+ public ByteBuffer serialize(ByteBuffer buffer) {
+ Map<String, User> userMap = ((BasicUserManager) userManager).getUserMap();
+ Map<String, Role> roleMap = ((BasicRoleManager) roleManager).getRoleMap();
+ User user;
+ Role role;
+
+ // serialize userinfo
+ BasicStructureSerDeUtil.write(userMap.size(), buffer);
+
+ for (String userName : userMap.keySet()) {
+ user = userMap.get(userName);
+ BasicStructureSerDeUtil.write(user.getName(), buffer);
+ BasicStructureSerDeUtil.write(user.getPassword(), buffer);
+ BasicStructureSerDeUtil.write(user.getPrivilegeList().size(), buffer);
+ for (PathPrivilege pathPrivilege : user.getPrivilegeList()) {
+ BasicStructureSerDeUtil.writeIntSet(pathPrivilege.getPrivileges(), buffer);
+ BasicStructureSerDeUtil.write(pathPrivilege.getPath(), buffer);
+ }
+ BasicStructureSerDeUtil.writeStringList(user.getRoleList(), buffer);
+ }
+
+ // serialize roleinfo
+ BasicStructureSerDeUtil.write(roleMap.size(), buffer);
+ for (String roleName : roleMap.keySet()) {
+ role = roleMap.get(roleName);
+ BasicStructureSerDeUtil.write(role.getName(), buffer);
+ for (PathPrivilege pathPrivilege : role.getPrivilegeList()) {
+ BasicStructureSerDeUtil.writeIntSet(pathPrivilege.getPrivileges(), buffer);
+ BasicStructureSerDeUtil.write(pathPrivilege.getPath(), buffer);
+ }
+ }
+ return buffer;
+ }
+
+ public void deserialize(ByteBuffer buffer) {
+ Map<String, User> userMap = new HashMap<>();
+ Map<String, Role> roleMap = new HashMap<>();
+ String username;
+ String password;
+ List<PathPrivilege> privilegeList = null;
+ Set<Integer> privilegesId = null;
+ String path = null;
+ List<String> roleList;
+ String roleName;
+
+ // deserialize user
+ int userMapSize = BasicStructureSerDeUtil.readInt(buffer);
+ for (int i = 0; i < userMapSize; i++) {
+ username = BasicStructureSerDeUtil.readString(buffer);
+ password = BasicStructureSerDeUtil.readString(buffer);
+ int privilegesSize = BasicStructureSerDeUtil.readInt(buffer);
+ if (privilegesSize == 0) {
+ privilegeList = new ArrayList<>();
+ } else {
+ for (int m = 0; m < privilegesSize; m++) {
+ privilegesId = BasicStructureSerDeUtil.readIntSet(buffer);
+ path = BasicStructureSerDeUtil.readString(buffer);
+ }
+ privilegeList.add(new PathPrivilege(privilegesId, path));
+ }
+ roleList = BasicStructureSerDeUtil.readStringList(buffer);
+ userMap.put(username, new User(username, password, privilegeList, roleList));
+ }
+
+ // deserialize role
+ int roleMapSize = BasicStructureSerDeUtil.readInt(buffer);
+ for (int i = 0; i < roleMapSize; i++) {
+ roleName = BasicStructureSerDeUtil.readString(buffer);
+ int privilegesSize = BasicStructureSerDeUtil.readInt(buffer);
+ if (privilegesSize == 0) {
+ privilegeList = new ArrayList<>();
+ } else {
+ for (int m = 0; m < privilegesSize; m++) {
+ privilegesId = BasicStructureSerDeUtil.readIntSet(buffer);
+ path = BasicStructureSerDeUtil.readString(buffer);
+ }
+ privilegeList.add(new PathPrivilege(privilegesId, path));
+ }
+ roleMap.put(roleName, new Role(roleName, privilegeList));
+ }
+
+ ((BasicUserManager) userManager).setUserMap(userMap);
+ ((BasicRoleManager) roleManager).setRoleMap(roleMap);
+ }
Review Comment:
fix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [iotdb] RYH61 commented on pull request #5741: [IOTDB-3043] AuthorInfo serialization and deserialization interfaces
Posted by GitBox <gi...@apache.org>.
RYH61 commented on PR #5741:
URL: https://github.com/apache/iotdb/pull/5741#issuecomment-1115875731
> Could we directly use the file of .user and .role for the auth snapshot?
At present, when the system is started, the userMap has root information by default, but no other user information. When other users are used, they will be added to the user map. If you use these files directly, may not know which user information to restore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org