Skip to content

Commit

Permalink
[Major] Privilege refactorings, remove unused services and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
eitch committed Oct 5, 2023
1 parent 6f72955 commit 6b6a61a
Show file tree
Hide file tree
Showing 22 changed files with 385 additions and 1,329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public RoleRep roleRepFromJson(JsonObject jsonObject) {

String name = nameE == null ? null : nameE.getAsString().trim();

List<PrivilegeRep> privileges = new ArrayList<>();
Map<String, PrivilegeRep> privileges = new HashMap<>();
if (privilegesE != null) {
JsonArray privilegesArr = privilegesE.getAsJsonArray();
for (JsonElement privilegeE : privilegesArr) {
privileges.add(privilegeRepFromJson(privilegeE.getAsJsonObject()));
PrivilegeRep privilegeRep = privilegeRepFromJson(privilegeE.getAsJsonObject());
privileges.put(privilegeRep.getName(), privilegeRep);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public JsonObject visitRoleRep(RoleRep roleRep) {
jsonObject.addProperty("name", roleRep.getName());

JsonArray privilegesJ = new JsonArray();
roleRep.getPrivileges().forEach(p -> privilegesJ.add(p.accept(this)));
roleRep.getPrivileges().values().forEach(p -> privilegesJ.add(p.accept(this)));
jsonObject.add("privileges", privilegesJ);

return jsonObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,9 @@ public void addOrUpdateUsers(Certificate certificate, List<UserRep> userReps) th
}

@Override
public UserRep replaceUser(Certificate certificate, UserRep userRep, char[] password) throws PrivilegeException {
public UserRep updateUser(Certificate certificate, UserRep userRep, char[] password) throws PrivilegeException {
return this.lockingHandler.lockedExecuteWithResult(userRep.getUsername(),
() -> crudHandler.replaceUser(certificate, userRep, password));
}

@Override
public UserRep updateUser(Certificate certificate, UserRep userRep) throws PrivilegeException {
return this.lockingHandler.lockedExecuteWithResult(userRep.getUsername(),
() -> crudHandler.updateUser(certificate, userRep));
() -> crudHandler.updateUser(certificate, userRep, password));
}

@Override
Expand All @@ -257,18 +251,6 @@ public UserRep removeUser(Certificate certificate, String username) {
() -> crudHandler.removeUser(certificate, username));
}

@Override
public UserRep addRoleToUser(Certificate certificate, String username, String roleName) {
return this.lockingHandler.lockedExecuteWithResult(username,
() -> crudHandler.addRoleToUser(certificate, username, roleName));
}

@Override
public UserRep removeRoleFromUser(Certificate certificate, String username, String roleName) {
return this.lockingHandler.lockedExecuteWithResult(username,
() -> crudHandler.removeRoleFromUser(certificate, username, roleName));
}

@Override
public UserRep setUserLocale(Certificate certificate, String username, Locale locale) {
return this.lockingHandler.lockedExecuteWithResult(username,
Expand Down Expand Up @@ -309,18 +291,6 @@ public RoleRep removeRole(Certificate certificate, String roleName) {
() -> crudHandler.removeRole(certificate, roleName));
}

@Override
public RoleRep addOrReplacePrivilegeOnRole(Certificate certificate, String roleName, PrivilegeRep privilegeRep) {
return this.lockingHandler.lockedExecuteWithResult(roleName,
() -> crudHandler.addOrReplacePrivilegeOnRole(certificate, roleName, privilegeRep));
}

@Override
public RoleRep removePrivilegeFromRole(Certificate certificate, String roleName, String privilegeName) {
return this.lockingHandler.lockedExecuteWithResult(roleName,
() -> crudHandler.removePrivilegeFromRole(certificate, roleName, privilegeName));
}

void invalidSessionsFor(User user) {
List<PrivilegeContext> contexts = new ArrayList<>(this.privilegeContextMap.values());
for (PrivilegeContext ctx : contexts) {
Expand Down
Loading

0 comments on commit 6b6a61a

Please sign in to comment.