}
public static void ensurePrivilege(String login, String privilege) {
if (null == login)
throw new APIException(Status.ERROR_LOGIN_REQUIRED,
"User not logged in");
if (isSuperUser(login))
return;
UserProp userProp = UserRepository.getUser(login);
if (null == userProp)
throw new APIException(Status.ERROR_INVALID_USER,
"User [" + login + "] in invalid");
privilege = privilege.toUpperCase();
if (userProp.privileges == null)
throw new APIException(Status.ERROR_INSUFFICIENT_PERMISSION,
"User [" + login + "] does not have privilege [" + privilege + "]");
if ((userProp.privileges != null) &&
(userProp.privileges.contains(privilege)))
return;
for (RoleProp roleProp : userProp.roles) {
if ((roleProp.privileges != null) &&
roleProp.privileges.contains(privilege))
return;
}
throw new APIException(Status.ERROR_INSUFFICIENT_PERMISSION,
"User [" + login + "] does not have privilege [" + privilege + "]");
}