2727import javax .inject .Inject ;
2828import java .io .IOException ;
2929import java .util .Collections ;
30+ import java .util .EnumSet ;
3031import java .util .HashSet ;
3132import java .util .Map ;
3233import java .util .Set ;
@@ -44,6 +45,12 @@ public class AuthorizationService {
4445 private final ZeppelinConfiguration zConf ;
4546 private final ConfigStorage configStorage ;
4647
48+ private static final Set <ZeppelinConfiguration .ConfVars > VALID_ROLES_CONF_VARS = EnumSet .of (
49+ ZeppelinConfiguration .ConfVars .ZEPPELIN_OWNER_ROLES ,
50+ ZeppelinConfiguration .ConfVars .ZEPPELIN_WRITER_ROLES ,
51+ ZeppelinConfiguration .ConfVars .ZEPPELIN_READER_ROLES ,
52+ ZeppelinConfiguration .ConfVars .ZEPPELIN_RUNNER_ROLES );
53+
4754 // contains roles for each user (username --> roles)
4855 private Map <String , Set <String >> userRoles = new ConcurrentHashMap <>();
4956
@@ -107,9 +114,9 @@ public void removeNoteAuth(String noteId) {
107114 private Set <String > normalizeUsers (Set <String > users ) {
108115 Set <String > returnUser = new HashSet <>();
109116 for (String user : users ) {
110- String trimedUser = user .trim ();
111- if (!trimedUser .isEmpty ()) {
112- returnUser .add (trimedUser );
117+ String trimmedUser = user .trim ();
118+ if (!trimmedUser .isEmpty ()) {
119+ returnUser .add (trimmedUser );
113120 }
114121 }
115122 return returnUser ;
@@ -298,19 +305,12 @@ private Set<String> getDefaultRunners() {
298305 }
299306
300307 private Set <String > getDefaultRoles (ZeppelinConfiguration .ConfVars confvar ) {
301- Set <String > defaultRoles = new HashSet <>();
302- String defaultRolesConf = null ;
303- switch (confvar ) {
304- case ZEPPELIN_OWNER_ROLES :
305- case ZEPPELIN_WRITER_ROLES :
306- case ZEPPELIN_READER_ROLES :
307- case ZEPPELIN_RUNNER_ROLES :
308- defaultRolesConf = zConf .getString (confvar );
309- break ;
310- default :
311- LOGGER .warn ("getDefaultRoles is used with {}, which is not valid" , confvar );
312- break ;
308+ if (!VALID_ROLES_CONF_VARS .contains (confvar )) {
309+ LOGGER .warn ("getDefaultRoles is used with {}, which is not valid" , confvar );
310+ return Collections .emptySet ();
313311 }
312+ Set <String > defaultRoles = new HashSet <>();
313+ String defaultRolesConf = zConf .getString (confvar );
314314 if (StringUtils .isNotBlank (defaultRolesConf )) {
315315 Collections .addAll (defaultRoles , StringUtils .split (defaultRolesConf , ',' ));
316316 }
0 commit comments