Skip to content

Commit

Permalink
Implementation of seung-00 recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
Reamer committed Oct 28, 2024
1 parent a86966f commit 87694a0
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.inject.Inject;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand All @@ -44,6 +45,12 @@ public class AuthorizationService {
private final ZeppelinConfiguration zConf;
private final ConfigStorage configStorage;

private static final Set<ZeppelinConfiguration.ConfVars> VALID_ROLES_CONF_VARS = EnumSet.of(
ZeppelinConfiguration.ConfVars.ZEPPELIN_OWNER_ROLES,
ZeppelinConfiguration.ConfVars.ZEPPELIN_WRITER_ROLES,
ZeppelinConfiguration.ConfVars.ZEPPELIN_READER_ROLES,
ZeppelinConfiguration.ConfVars.ZEPPELIN_RUNNER_ROLES);

// contains roles for each user (username --> roles)
private Map<String, Set<String>> userRoles = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -107,9 +114,9 @@ public void removeNoteAuth(String noteId) {
private Set<String> normalizeUsers(Set<String> users) {
Set<String> returnUser = new HashSet<>();
for (String user : users) {
String trimedUser = user.trim();
if (!trimedUser.isEmpty()) {
returnUser.add(trimedUser);
String trimmedUser = user.trim();
if (!trimmedUser.isEmpty()) {
returnUser.add(trimmedUser);
}
}
return returnUser;
Expand Down Expand Up @@ -298,19 +305,12 @@ private Set<String> getDefaultRunners() {
}

private Set<String> getDefaultRoles(ZeppelinConfiguration.ConfVars confvar) {
Set<String> defaultRoles = new HashSet<>();
String defaultRolesConf = null;
switch (confvar) {
case ZEPPELIN_OWNER_ROLES:
case ZEPPELIN_WRITER_ROLES:
case ZEPPELIN_READER_ROLES:
case ZEPPELIN_RUNNER_ROLES:
defaultRolesConf = zConf.getString(confvar);
break;
default:
LOGGER.warn("getDefaultRoles is used with {}, which is not valid", confvar);
break;
if (!VALID_ROLES_CONF_VARS.contains(confvar)) {
LOGGER.warn("getDefaultRoles is used with {}, which is not valid", confvar);
return Collections.emptySet();
}
Set<String> defaultRoles = new HashSet<>();
String defaultRolesConf = zConf.getString(confvar);
if (StringUtils.isNotBlank(defaultRolesConf)) {
Collections.addAll(defaultRoles, StringUtils.split(defaultRolesConf, ','));
}
Expand Down

0 comments on commit 87694a0

Please sign in to comment.