Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-4535. Remove Ability to edit all users team #2341

Merged
merged 20 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
public class WebServiceAdmin implements DBWServiceAdmin {

private static final Log log = Log.getLog(WebServiceAdmin.class);
public static final String All_USERS_TEAM = "all_users";
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved

private final Map<String, WebPermissionDescriptor> permissionDescriptorByName = WebServiceRegistry.getInstance()
.getWebServices()
Expand Down Expand Up @@ -216,6 +217,9 @@ public AdminTeamInfo updateTeam(@NotNull WebSession webSession, String teamId, S
webSession.addInfoMessage("Update team - " + teamId);

try {
if (teamId.equals(All_USERS_TEAM)) {
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
throw new DBWebException("You can not update all_users team");
}
webSession.getAdminSecurityController().updateTeam(teamId, teamName, description);
SMTeam newTeam = webSession.getAdminSecurityController().findTeam(teamId);
return new AdminTeamInfo(webSession, newTeam);
Expand All @@ -231,6 +235,9 @@ public boolean deleteTeam(@NotNull WebSession webSession, String teamId, boolean

var adminSecurityController = webSession.getAdminSecurityController();
SMTeam[] userTeams = adminSecurityController.getUserTeams(webSession.getUser().getUserId());
if (Arrays.stream(userTeams).anyMatch(team -> team.getTeamId().equals(All_USERS_TEAM))) {
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
throw new DBWebException("You can not delete all_users team");
}
if (Arrays.stream(userTeams).anyMatch(team -> team.getTeamId().equals(teamId))) {
throw new DBWebException("You can not delete your own team");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
private static final Type MAP_STRING_OBJECT_TYPE = new TypeToken<Map<String, Object>>() {
}.getType();
private static final Gson gson = new GsonBuilder().create();
public static final String ALL_USERS_ROLE = "all_users";
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved

protected final T application;
protected final CBDatabase database;
Expand Down Expand Up @@ -216,15 +217,29 @@ public void deleteUser(String userId) throws DBCException {
public void setUserTeams(String userId, String[] teamIds, String grantorId) throws DBCException {
try (Connection dbCon = database.openConnection()) {
try (JDBCTransaction txn = new JDBCTransaction(dbCon)) {
setUserTeams(dbCon, userId, teamIds, grantorId);
txn.commit();
if (containsAllUsers(teamIds)) {
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
setUserTeams(dbCon, userId, teamIds, grantorId);
txn.commit();
} else {
throw new DBCException(application.getAppConfiguration().getDefaultUserTeam() + " role not editable");
}
}
} catch (SQLException e) {
throw new DBCException("Error saving user teams in database", e);
}
addSubjectPermissionsUpdateEvent(userId, SMSubjectType.user);
}

private boolean containsAllUsers(String[] array) {
for (String element : array) {
if (application.getAppConfiguration().getDefaultUserTeam().equals(element)) {
return true;
}
}
return false;
}


public void setUserTeams(@NotNull Connection dbCon, String userId, String[] teamIds, String grantorId)
throws SQLException {
JDBCUtils.executeStatement(
Expand Down Expand Up @@ -2202,7 +2217,12 @@ private String findOrCreateExternalUserByCredentials(
}
Object reverseProxyUserTeams = sessionParameters.get(SMConstants.SESSION_PARAM_TRUSTED_USER_TEAMS);
if (reverseProxyUserTeams instanceof List) {
setUserTeams(userId, ((List<?>) reverseProxyUserTeams).stream().map(Object::toString).toArray(String[]::new), userId);
List<String> reverseProxyUserTeamsList = (List<String>) reverseProxyUserTeams;
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
String defaultUserTeam = application.getAppConfiguration().getDefaultUserTeam();
if (!reverseProxyUserTeamsList.contains(defaultUserTeam)) {
reverseProxyUserTeamsList.add(defaultUserTeam);
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
}
setUserTeams(userId, reverseProxyUserTeamsList.toArray(new String[0]), userId);
}
}
return userId;
Expand Down
Loading