Skip to content

Commit

Permalink
Merge pull request #1816 from akto-api-security/feature/test_role_del…
Browse files Browse the repository at this point in the history
…etion_admin_check

feat: now users can only delete their own test roles unless it's admin
  • Loading branch information
Ark2307 authored Dec 12, 2024
2 parents 959dbca + 66e4576 commit 8d848c1
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.akto.action.testing;

import com.akto.action.UserAction;
import com.akto.dao.RBACDao;
import com.akto.dao.context.Context;
import com.akto.dao.testing.EndpointLogicalGroupDao;
import com.akto.dao.testing.TestRolesDao;
import com.akto.dao.testing.config.TestCollectionPropertiesDao;
import com.akto.dto.RBAC;
import com.akto.dto.User;
import com.akto.dto.testing.config.TestCollectionProperty;
import com.akto.dto.RecordedLoginFlowInput;
import com.akto.dto.data_types.Conditions;
Expand Down Expand Up @@ -136,6 +139,22 @@ public String deleteTestRole() {
return ERROR.toUpperCase();
}

User user = getSUser();
if(user == null) {
addActionError("User not found.");
return ERROR.toUpperCase();
}

boolean noAccess = !user.getLogin().equals(role.getCreatedBy());

if(noAccess) {
RBAC.Role currentRoleForUser = RBACDao.getCurrentRoleForUser(user.getId(), Context.accountId.get());
if (!currentRoleForUser.equals(RBAC.Role.ADMIN)) {
addActionError("You do not have permission to delete this role.");
return ERROR.toUpperCase();
}
}

Bson roleFilterQ = Filters.eq(TestRoles.NAME, roleName);
DeleteResult delete = TestRolesDao.instance.deleteAll(roleFilterQ);
loggerMaker.infoAndAddToDb("Deleted role: " + roleName + " : " + delete, LoggerMaker.LogDb.DASHBOARD);
Expand Down

0 comments on commit 8d848c1

Please sign in to comment.