Set<TSentryRole> allowedRoles) throws SentryUserException {
// if unset, then we choose the default of ALL
if (name.isEmpty()) {
return ActiveRoleSet.ALL;
} else if (AccessConstants.NONE_ROLE.equalsIgnoreCase(name)) {
return new ActiveRoleSet(new HashSet<String>());
} else if (AccessConstants.ALL_ROLE.equalsIgnoreCase(name)) {
return ActiveRoleSet.ALL;
} else if (AccessConstants.RESERVED_ROLE_NAMES.contains(name.toUpperCase())) {
String msg = "Role " + name + " is reserved";
throw new IllegalArgumentException(msg);
} else {
if (allowedRoles != null) {
// check if the user has been granted the role
boolean foundRole = false;
for (TSentryRole role : allowedRoles) {
if (role.getRoleName().equalsIgnoreCase(name)) {
foundRole = true;
break;
}
}
if (!foundRole) {
throw new SentryUserException("Not authorized to set role " + name);
}
}
return new ActiveRoleSet(Sets.newHashSet(ROLE_SET_SPLITTER.split(name)));
}
}