You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by li...@apache.org on 2019/01/24 02:25:47 UTC
[incubator-iotdb] branch fix_sonar updated: fix vulnerability in
Role.java
This is an automated email from the ASF dual-hosted git repository.
liurui pushed a commit to branch fix_sonar
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/fix_sonar by this push:
new 6b0d060 fix vulnerability in Role.java
6b0d060 is described below
commit 6b0d060cb25ee309852aa5028294c3c6a17c4f54
Author: liuruiyiyang <24...@qq.com>
AuthorDate: Thu Jan 24 10:25:33 2019 +0800
fix vulnerability in Role.java
---
.../apache/iotdb/db/auth/entity/PathPrivilege.java | 10 +++++-
.../java/org/apache/iotdb/db/auth/entity/Role.java | 20 +++++++++--
.../iotdb/db/auth/role/LocalFileRoleAccessor.java | 16 ++++-----
.../iotdb/db/qp/executor/OverflowQPExecutor.java | 4 +--
.../java/org/apache/iotdb/db/utils/AuthUtils.java | 2 +-
.../iotdb/db/auth/LocalFIleRoleAccessorTest.java | 12 +++----
.../iotdb/db/auth/LocalFileRoleManagerTest.java | 40 +++++++++++-----------
7 files changed, 64 insertions(+), 40 deletions(-)
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/PathPrivilege.java b/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/PathPrivilege.java
index 2ae6900..7f95e9e 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/PathPrivilege.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/PathPrivilege.java
@@ -55,6 +55,14 @@ public class PathPrivilege {
this.path = path;
}
+ public AtomicInteger getReferenceCnt() {
+ return referenceCnt;
+ }
+
+ public void setReferenceCnt(AtomicInteger referenceCnt) {
+ this.referenceCnt = referenceCnt;
+ }
+
/**
* This field records how many times this privilege is referenced during a life cycle (from being
* loaded to being discarded). When serialized to a file, this determines the order of
@@ -62,7 +70,7 @@ public class PathPrivilege {
* result, the hot privileges will be in the first place so that the hit time will decrease when
* being queried.
*/
- public AtomicInteger referenceCnt = new AtomicInteger(0);
+ private AtomicInteger referenceCnt = new AtomicInteger(0);
public PathPrivilege(String path) {
this.path = path;
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/Role.java b/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/Role.java
index a8317ce..d034ee0 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/Role.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/auth/entity/Role.java
@@ -29,8 +29,24 @@ import org.apache.iotdb.db.utils.AuthUtils;
*/
public class Role {
- public String name;
- public List<PathPrivilege> privilegeList;
+ private String name;
+ private List<PathPrivilege> privilegeList;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<PathPrivilege> getPrivilegeList() {
+ return privilegeList;
+ }
+
+ public void setPrivilegeList(List<PathPrivilege> privilegeList) {
+ this.privilegeList = privilegeList;
+ }
public Role() {
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/auth/role/LocalFileRoleAccessor.java b/iotdb/src/main/java/org/apache/iotdb/db/auth/role/LocalFileRoleAccessor.java
index 42efd37..52b2509 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/auth/role/LocalFileRoleAccessor.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/auth/role/LocalFileRoleAccessor.java
@@ -80,7 +80,7 @@ public class LocalFileRoleAccessor implements IRoleAccessor {
try (DataInputStream dataInputStream = new DataInputStream(
new BufferedInputStream(inputStream))) {
Role role = new Role();
- role.name = IOUtils.readString(dataInputStream, STRING_ENCODING, strBufferLocal);
+ role.setName(IOUtils.readString(dataInputStream, STRING_ENCODING, strBufferLocal));
int privilegeNum = dataInputStream.readInt();
List<PathPrivilege> pathPrivilegeList = new ArrayList<>();
@@ -88,7 +88,7 @@ public class LocalFileRoleAccessor implements IRoleAccessor {
pathPrivilegeList
.add(IOUtils.readPathPrivilege(dataInputStream, STRING_ENCODING, strBufferLocal));
}
- role.privilegeList = pathPrivilegeList;
+ role.setPrivilegeList(pathPrivilegeList);
return role;
} catch (Exception e) {
@@ -99,16 +99,16 @@ public class LocalFileRoleAccessor implements IRoleAccessor {
@Override
public void saveRole(Role role) throws IOException {
File roleProfile = new File(
- roleDirPath + File.separator + role.name + IoTDBConstant.PROFILE_SUFFIX + TEMP_SUFFIX);
+ roleDirPath + File.separator + role.getName() + IoTDBConstant.PROFILE_SUFFIX + TEMP_SUFFIX);
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(roleProfile));
try {
- IOUtils.writeString(outputStream, role.name, STRING_ENCODING, encodingBufferLocal);
+ IOUtils.writeString(outputStream, role.getName(), STRING_ENCODING, encodingBufferLocal);
- role.privilegeList.sort(PathPrivilege.referenceDescentSorter);
- int privilegeNum = role.privilegeList.size();
+ role.getPrivilegeList().sort(PathPrivilege.referenceDescentSorter);
+ int privilegeNum = role.getPrivilegeList().size();
IOUtils.writeInt(outputStream, privilegeNum, encodingBufferLocal);
for (int i = 0; i < privilegeNum; i++) {
- PathPrivilege pathPrivilege = role.privilegeList.get(i);
+ PathPrivilege pathPrivilege = role.getPrivilegeList().get(i);
IOUtils
.writePathPrivilege(outputStream, pathPrivilege, STRING_ENCODING, encodingBufferLocal);
}
@@ -121,7 +121,7 @@ public class LocalFileRoleAccessor implements IRoleAccessor {
}
File oldFile = new File(
- roleDirPath + File.separator + role.name + IoTDBConstant.PROFILE_SUFFIX);
+ roleDirPath + File.separator + role.getName() + IoTDBConstant.PROFILE_SUFFIX);
IOUtils.replaceFile(roleProfile, oldFile);
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/qp/executor/OverflowQPExecutor.java b/iotdb/src/main/java/org/apache/iotdb/db/qp/executor/OverflowQPExecutor.java
index 52cd307..3b37fac 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/qp/executor/OverflowQPExecutor.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/qp/executor/OverflowQPExecutor.java
@@ -435,7 +435,7 @@ public class OverflowQPExecutor extends QueryProcessExecutor {
msg = new StringBuilder("Privileges are : [ \n");
role = authorizer.getRole(roleName);
if (role != null) {
- for (PathPrivilege pathPrivilege : role.privilegeList) {
+ for (PathPrivilege pathPrivilege : role.getPrivilegeList()) {
if (nodeName == null || AuthUtils
.pathBelongsTo(nodeName.getFullPath(), pathPrivilege.getPath())) {
msg.append(pathPrivilege.toString());
@@ -464,7 +464,7 @@ public class OverflowQPExecutor extends QueryProcessExecutor {
role = authorizer.getRole(roleN);
if (role != null) {
msg.append("From role ").append(roleN).append(" : {\n");
- for (PathPrivilege pathPrivilege : role.privilegeList) {
+ for (PathPrivilege pathPrivilege : role.getPrivilegeList()) {
if (nodeName == null
|| AuthUtils.pathBelongsTo(nodeName.getFullPath(), pathPrivilege.getPath())) {
msg.append(pathPrivilege.toString());
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java
index a830ca3..28c5200 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java
@@ -239,7 +239,7 @@ public class AuthUtils {
List<PathPrivilege> privilegeList) {
for (PathPrivilege pathPrivilege : privilegeList) {
if (pathPrivilege.getPath().equals(path) && pathPrivilege.getPrivileges().contains(privilegeId)) {
- pathPrivilege.referenceCnt.incrementAndGet();
+ pathPrivilege.getReferenceCnt().incrementAndGet();
return true;
}
}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFIleRoleAccessorTest.java b/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFIleRoleAccessorTest.java
index 5fdaee5..88ef1da 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFIleRoleAccessorTest.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFIleRoleAccessorTest.java
@@ -59,7 +59,7 @@ public class LocalFIleRoleAccessorTest {
for (int j = 0; j <= i; j++) {
PathPrivilege pathPrivilege = new PathPrivilege("root.a.b.c" + j);
pathPrivilege.getPrivileges().add(j);
- roles[i].privilegeList.add(pathPrivilege);
+ roles[i].getPrivilegeList().add(pathPrivilege);
}
}
@@ -70,21 +70,21 @@ public class LocalFIleRoleAccessorTest {
// load
for (Role role : roles) {
- Role loadedRole = accessor.loadRole(role.name);
+ Role loadedRole = accessor.loadRole(role.getName());
assertEquals(role, loadedRole);
}
assertEquals(null, accessor.loadRole("not a role"));
// delete
- assertEquals(true, accessor.deleteRole(roles[roles.length - 1].name));
- assertEquals(false, accessor.deleteRole(roles[roles.length - 1].name));
- assertEquals(null, accessor.loadRole(roles[roles.length - 1].name));
+ assertEquals(true, accessor.deleteRole(roles[roles.length - 1].getName()));
+ assertEquals(false, accessor.deleteRole(roles[roles.length - 1].getName()));
+ assertEquals(null, accessor.loadRole(roles[roles.length - 1].getName()));
// list
List<String> roleNames = accessor.listAllRoles();
roleNames.sort(null);
for (int i = 0; i < roleNames.size(); i++) {
- assertEquals(roles[i].name, roleNames.get(i));
+ assertEquals(roles[i].getName(), roleNames.get(i));
}
}
}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFileRoleManagerTest.java b/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFileRoleManagerTest.java
index db607ea..1027fdd 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFileRoleManagerTest.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/auth/LocalFileRoleManagerTest.java
@@ -58,22 +58,22 @@ public class LocalFileRoleManagerTest {
for (int j = 0; j <= i; j++) {
PathPrivilege pathPrivilege = new PathPrivilege("root.a.b.c" + j);
pathPrivilege.getPrivileges().add(j);
- roles[i].privilegeList.add(pathPrivilege);
+ roles[i].getPrivilegeList().add(pathPrivilege);
}
}
// create
- Role role = manager.getRole(roles[0].name);
+ Role role = manager.getRole(roles[0].getName());
assertEquals(null, role);
for (Role role1 : roles) {
- assertEquals(true, manager.createRole(role1.name));
+ assertEquals(true, manager.createRole(role1.getName()));
}
for (Role role1 : roles) {
- role = manager.getRole(role1.name);
- assertEquals(role1.name, role.name);
+ role = manager.getRole(role1.getName());
+ assertEquals(role1.getName(), role.getName());
}
- assertEquals(false, manager.createRole(roles[0].name));
+ assertEquals(false, manager.createRole(roles[0].getName()));
boolean caught = false;
try {
manager.createRole("too");
@@ -84,19 +84,19 @@ public class LocalFileRoleManagerTest {
// delete
assertEquals(false, manager.deleteRole("not a role"));
- assertEquals(true, manager.deleteRole(roles[roles.length - 1].name));
- assertEquals(null, manager.getRole(roles[roles.length - 1].name));
- assertEquals(false, manager.deleteRole(roles[roles.length - 1].name));
+ assertEquals(true, manager.deleteRole(roles[roles.length - 1].getName()));
+ assertEquals(null, manager.getRole(roles[roles.length - 1].getName()));
+ assertEquals(false, manager.deleteRole(roles[roles.length - 1].getName()));
// grant privilege
- role = manager.getRole(roles[0].name);
+ role = manager.getRole(roles[0].getName());
String path = "root.a.b.c";
int privilegeId = 0;
assertEquals(false, role.hasPrivilege(path, privilegeId));
- assertEquals(true, manager.grantPrivilegeToRole(role.name, path, privilegeId));
- assertEquals(true, manager.grantPrivilegeToRole(role.name, path, privilegeId + 1));
- assertEquals(false, manager.grantPrivilegeToRole(role.name, path, privilegeId));
- role = manager.getRole(roles[0].name);
+ assertEquals(true, manager.grantPrivilegeToRole(role.getName(), path, privilegeId));
+ assertEquals(true, manager.grantPrivilegeToRole(role.getName(), path, privilegeId + 1));
+ assertEquals(false, manager.grantPrivilegeToRole(role.getName(), path, privilegeId));
+ role = manager.getRole(roles[0].getName());
assertEquals(true, role.hasPrivilege(path, privilegeId));
caught = false;
try {
@@ -107,16 +107,16 @@ public class LocalFileRoleManagerTest {
assertEquals(true, caught);
caught = false;
try {
- manager.grantPrivilegeToRole(role.name, path, -1);
+ manager.grantPrivilegeToRole(role.getName(), path, -1);
} catch (AuthException e) {
caught = true;
}
assertEquals(true, caught);
// revoke privilege
- role = manager.getRole(roles[0].name);
- assertEquals(true, manager.revokePrivilegeFromRole(role.name, path, privilegeId));
- assertEquals(false, manager.revokePrivilegeFromRole(role.name, path, privilegeId));
+ role = manager.getRole(roles[0].getName());
+ assertEquals(true, manager.revokePrivilegeFromRole(role.getName(), path, privilegeId));
+ assertEquals(false, manager.revokePrivilegeFromRole(role.getName(), path, privilegeId));
caught = false;
try {
manager.revokePrivilegeFromRole("not a role", path, privilegeId);
@@ -126,7 +126,7 @@ public class LocalFileRoleManagerTest {
assertEquals(true, caught);
caught = false;
try {
- manager.revokePrivilegeFromRole(role.name, path, -1);
+ manager.revokePrivilegeFromRole(role.getName(), path, -1);
} catch (AuthException e) {
caught = true;
}
@@ -136,7 +136,7 @@ public class LocalFileRoleManagerTest {
List<String> rolenames = manager.listAllRoles();
rolenames.sort(null);
for (int i = 0; i < roles.length - 1; i++) {
- assertEquals(roles[i].name, rolenames.get(i));
+ assertEquals(roles[i].getName(), rolenames.get(i));
}
}
}