Caideyipi commented on code in PR #13158:
URL: https://github.com/apache/iotdb/pull/13158#discussion_r1928194098
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/role/BasicRoleManager.java:
##########
@@ -35,197 +36,197 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
/**
* This class reads roles from local files through LocalFileRoleAccessor and
manages them in a hash
* map. We save all roles in our memory. Before providing service, we should
load all role
* information from filesystem. Access filesystem only happens at
starting、taking snapshot、 loading
* snapshot.
*/
-public abstract class BasicRoleManager implements IRoleManager {
+public abstract class BasicRoleManager implements IEntityManager,
SnapshotProcessor {
- protected Map<String, Role> roleMap;
- protected IRoleAccessor accessor;
- protected HashLock lock;
- private boolean preVersion = false;
+ protected Map<String, Role> entityMap;
+ protected IEntityAccessor accessor;
+ protected HashLock lock;
private static final Logger LOGGER =
LoggerFactory.getLogger(BasicRoleManager.class);
- BasicRoleManager(LocalFileRoleAccessor accessor) {
- this.roleMap = new HashMap<>();
+ protected TSStatusCode getEntityNotExistErrorCode() {
+ return TSStatusCode.ROLE_NOT_EXIST;
+ }
+
+ protected String getNoSuchEntityError() {
+ return "No such role %s";
+ }
+
+ protected BasicRoleManager() {
+ this.entityMap = new HashMap<>();
+ this.lock = new HashLock();
+ }
+
+ protected BasicRoleManager(IEntityAccessor accessor) {
+ this.entityMap = new HashMap<>();
this.accessor = accessor;
this.lock = new HashLock();
this.accessor.reset();
}
- @Override
- public Role getRole(String rolename) {
- lock.readLock(rolename);
- Role role = roleMap.get(rolename);
- lock.readUnlock(rolename);
+ public Role getEntity(String entityName) {
+ lock.readLock(entityName);
+ Role role = entityMap.get(entityName);
+ lock.readUnlock(entityName);
return role;
}
- @Override
- public boolean createRole(String rolename) throws AuthException {
-
- Role role = getRole(rolename);
+ public boolean createRole(String entityName) {
+ Role role = getEntity(entityName);
if (role != null) {
return false;
}
- lock.writeLock(rolename);
- role = new Role(rolename);
- roleMap.put(rolename, role);
- lock.writeUnlock(rolename);
+ lock.writeLock(entityName);
+ role = new Role(entityName);
+ entityMap.put(entityName, role);
+ lock.writeUnlock(entityName);
return true;
}
- @Override
- public boolean deleteRole(String rolename) {
- lock.writeLock(rolename);
- try {
- return roleMap.remove(rolename) != null;
- } finally {
- lock.writeUnlock(rolename);
- }
+ public boolean deleteEntity(String entityName) {
Review Comment:
Better check the @Overrides
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]