private RoleBE GetRoleFromUrl(bool mustExist) { RoleBE r; string roleid = DreamContext.Current.GetParam("roleid"); // Double decoding of name is done to work around a mod_proxy issue that strips out slashes roleid = XUri.Decode(roleid); if (roleid.StartsWith("=")) { string name = roleid.Substring(1); r = PermissionsBL.GetRoleByName(name); if (r == null && mustExist) { throw new SiteRoleNameNotFoundException(name); } } else { uint roleIdInt; if (!uint.TryParse(roleid, out roleIdInt)) { throw new SiteRoleIdInvalidArgumentException(); } r = PermissionsBL.GetRoleById(roleIdInt); if (r == null && mustExist) { throw new SiteRoleIdNotFoundException(roleIdInt); } } return(r); }
private static void ParseGroupXml(XDoc groupDoc, out uint?id, out string name, out ServiceBE authService, out RoleBE role, out UserBE[] userList) { name = groupDoc["groupname"].AsText ?? groupDoc["name"].AsText; string authserviceidstr = groupDoc["service.authentication/@id"].AsText; string rolestr = groupDoc["permissions.group/role"].AsText; authService = null; role = null; id = null; if (!groupDoc["@id"].IsEmpty) { uint id_temp; if (!uint.TryParse(groupDoc["@id"].Contents, out id_temp)) { throw new GroupIdAttributeInvalidArgumentException(); } id = id_temp; } if (!string.IsNullOrEmpty(authserviceidstr)) { uint serviceid; if (!uint.TryParse(authserviceidstr, out serviceid)) { throw new ServiceAuthIdAttrInvalidArgumentException(); } authService = ServiceBL.GetServiceById(serviceid); if (authService == null) { throw new ServiceDoesNotExistInvalidArgumentException(serviceid); } } if (!string.IsNullOrEmpty(rolestr)) { role = PermissionsBL.GetRoleByName(rolestr); if (role == null) { throw new RoleDoesNotExistInvalidArgumentException(rolestr); } } else { role = PermissionsBL.RetrieveDefaultRoleForNewAccounts(); } if (!groupDoc["users"].IsEmpty) { userList = ReadUserListXml(groupDoc["users"]); } else { userList = new UserBE[] { } }; }
private static void ParseUserXml(XDoc userDoc, out uint?id, out string username, out string email, out string fullname, out ServiceBE authService, out RoleBE role, out bool?active, out string language, out string timezone) { username = userDoc["username"].AsText; email = userDoc["email"].AsText; fullname = userDoc["fullname"].AsText; language = userDoc["language"].AsText; timezone = userDoc["timezone"].AsText; string authserviceidstr = userDoc["service.authentication/@id"].AsText; string rolestr = userDoc["permissions.user/role"].AsText; string statusStr = userDoc["status"].AsText; authService = null; role = null; id = null; if (!userDoc["@id"].IsEmpty) { uint id_temp; if (!uint.TryParse(userDoc["@id"].Contents, out id_temp)) { throw new UserIdAttrInvalidArgumentException(); } id = id_temp; } if (!string.IsNullOrEmpty(authserviceidstr)) { uint serviceid; if (!uint.TryParse(authserviceidstr, out serviceid)) { throw new ServiceAuthIdAttrInvalidArgumentException(); } authService = ServiceBL.GetServiceById(serviceid); if (authService == null) { throw new ServiceDoesNotExistInvalidArgumentException(serviceid); } } if (!string.IsNullOrEmpty(rolestr)) { role = PermissionsBL.GetRoleByName(rolestr); if (role == null) { throw new RoleDoesNotExistInvalidArgumentException(rolestr); } } if (!string.IsNullOrEmpty(statusStr)) { switch (statusStr.ToLowerInvariant()) { case "active": active = true; break; case "inactive": active = false; break; default: throw new UserStatusAttrInvalidArgumentException(); } } else { active = null; } if (!string.IsNullOrEmpty(timezone)) { if (!timeZoneRegex.Match(timezone).Success) { throw new UserTimezoneInvalidArgumentException(); } } if (!string.IsNullOrEmpty(language)) { string[] validLanguages = DekiContext.Current.Instance.Languages.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string tempLanguage = language; if (!Array.Exists(validLanguages, delegate(string temp) { return(temp.EqualsInvariantIgnoreCase(tempLanguage)); })) { throw new UserInvalidLanguageException(); } } }