void AddChildren(IReadOnlyCollection <string> folders, AccessPrivilege accessPrivilege) { foreach (var folder in folders) { AddChild(folder, accessPrivilege); } }
public ActionResult Edit(User item) { if (!ModelState.IsValid) { return(View(item)); } using (var scope = new TransactionScope()) { var user = Model.User.Find(item.UserName); user.Employee = Employee.Find(item.EmployeeId); user.Email = item.Email; user.IsAdministrator = item.IsAdministrator; foreach (var i in Enum.GetValues(typeof(SystemObjects))) { var obj = (SystemObjects)i; string prefix = Enum.GetName(typeof(SystemObjects), i); var privilege = user.Privileges.SingleOrDefault(x => x.Object == obj); if (privilege == null) { privilege = new AccessPrivilege { User = user, Object = obj }; } foreach (var j in Enum.GetValues(typeof(AccessRight))) { AccessRight right = (AccessRight)j; string name = prefix + Enum.GetName(typeof(AccessRight), j); string value = Request.Params [name]; if (value == null) { continue; } if (value.Contains("true")) { privilege.Privileges |= right; } else { privilege.Privileges &= ~right; } } privilege.Save(); } user.UpdateAndFlush(); } return(RedirectToAction("Index")); }
public TreeBuilder WithFolders(IEnumerable <string> folders, AccessPrivilege accessPrivilege) { if (!foldersByTypes.ContainsKey(accessPrivilege)) { foldersByTypes.Add(accessPrivilege, new List <string>(folders)); } else { foldersByTypes[accessPrivilege].AddRange(folders); } return(this); }
/// <summary> /// Constructs a user access control that matches the address for the /// given protocol. /// </summary> /// <param name="userName">The name of the user holding the control.</param> /// <param name="protocol">The name of the protocol to control access to /// the database for a given user.</param> /// <param name="address">The specific address to which to apply this control.</param> /// <param name="privilege">The kind of access to provide to the user for the /// protocol given.</param> /// <seealso cref="AnyAddress"/> public UserProtocolAccess(string userName, string protocol, string address, AccessPrivilege privilege) { if (String.IsNullOrEmpty(userName)) throw new ArgumentNullException("userName"); if (String.IsNullOrEmpty(protocol)) throw new ArgumentNullException("protocol"); UserName = userName; Protocol = protocol; Address = address; Privilege = privilege; }
void AddChild(string relativePath, AccessPrivilege accessPrivilege) { var pathSegments = relativePath.Split(pathSeparators, StringSplitOptions.RemoveEmptyEntries); var lastIndex = pathSegments.Length - 1; var node = root; for (int i = 0; i < lastIndex; i++) { node = node.AddChild(pathSegments[i], AccessPrivilege.None); } node.AddChild(pathSegments[lastIndex], accessPrivilege); }
internal AccessCacheEntry(string hostAddr, AccessPrivilege access, long expirationTime ) { // only support IPv4 now // Hostnames are composed of series of 'labels' concatenated with dots. // Labels can be between 1-63 characters long, and can only take // letters, digits & hyphens. They cannot start and end with hyphens. For // more details, refer RFC-1123 & http://en.wikipedia.org/wiki/Hostname Preconditions.CheckArgument(hostAddr != null); this.hostAddr = hostAddr; this.access = access; this.expirationTime = expirationTime; }
/// <summary> /// You can create a new playlist for the user. /// </summary> /// <param name="name">The name of the playlist. Min Length: 1 character. Max Length: 100 characters.</param> /// <param name="description">The description of the playlist. Min Length: 0 characters. Max Length: 100 characters</param> /// <param name="accessPrivilege">Specifies whether the playlist is publicly or privately available. </param> /// <returns>Returns the newly created PlaylistData</returns> public async Task<SingleRootObject<PlaylistData>> CreatePlaylist(string name, string description, AccessPrivilege accessPrivilege = AccessPrivilege.Public) { ValidetaNameAndDescription(name, description); var dataParams = new Dictionary<string, string> { {"name", name}, {"description", description}, {"access", ParamValueAttributeHelper.GetParamValueOfEnumAttribute<AccessPrivilege>(accessPrivilege)} }; return await BeatsMusicManager.PostData<PlaylistData>("playlists", dataParams.ToList()); }
public override XDR Mnt(XDR xdr, XDR @out, int xid, IPAddress client) { if (hostsMatcher == null) { return(MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null)); } AccessPrivilege accessPrivilege = hostsMatcher.GetAccessPrivilege(client); if (accessPrivilege == AccessPrivilege.None) { return(MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null)); } string path = xdr.ReadString(); if (Log.IsDebugEnabled()) { Log.Debug("MOUNT MNT path: " + path + " client: " + client); } string host = client.GetHostName(); if (Log.IsDebugEnabled()) { Log.Debug("Got host: " + host + " path: " + path); } if (!exports.Contains(path)) { Log.Info("Path " + path + " is not shared."); MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errNoent, @out, xid, null); return(@out); } FileHandle handle = null; try { HdfsFileStatus exFileStatus = dfsClient.GetFileInfo(path); handle = new FileHandle(exFileStatus.GetFileId()); } catch (IOException e) { Log.Error("Can't get handle for export:" + path, e); MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errNoent, @out, xid, null); return(@out); } System.Diagnostics.Debug.Assert((handle != null)); Log.Info("Giving handle (fileId:" + handle.GetFileId() + ") to client for export " + path); mounts.AddItem(new MountEntry(host, path)); MountResponse.WriteMNTResponse(Nfs3Status.Nfs3Ok, @out, xid, handle.GetContent()); return(@out); }
/// <summary> /// Constructs a user access control that matches the address for the /// given protocol. /// </summary> /// <param name="userName">The name of the user holding the control.</param> /// <param name="protocol">The name of the protocol to control access to /// the database for a given user.</param> /// <param name="address">The specific address to which to apply this control.</param> /// <param name="privilege">The kind of access to provide to the user for the /// protocol given.</param> /// <seealso cref="AnyAddress"/> public UserProtocolAccess(string userName, string protocol, string address, AccessPrivilege privilege) { if (String.IsNullOrEmpty(userName)) { throw new ArgumentNullException("userName"); } if (String.IsNullOrEmpty(protocol)) { throw new ArgumentNullException("protocol"); } UserName = userName; Protocol = protocol; Address = address; Privilege = privilege; }
internal TreeItem AddChild(string name, AccessPrivilege accessPrivilege) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException($"Value required", nameof(name)); } if (!childrenInternal.TryGetValue(name, out var child)) { child = new TreeItem(this, name, accessPrivilege); childrenInternal.Add(child); } else { child.AccessPrivilege |= accessPrivilege; } return(child); }
private ExactMatch(AccessPrivilege accessPrivilege, string ipOrHost) : base(accessPrivilege) { this.ipOrHost = ipOrHost; }
/// <summary> /// Constructs a user access control that matches all the addresses /// for the given protocol. /// </summary> /// <param name="userName">The name of the user holding the control.</param> /// <param name="protocol">The name of the protocol to control access to /// the database for a given user.</param> /// <param name="privilege">The kind of access to provide to the user for the /// protocol given.</param> /// <seealso cref="AnyAddress"/> public UserProtocolAccess(string userName, string protocol, AccessPrivilege privilege) : this(userName, protocol, AnyAddress, privilege) { }
public ActionResult Edit(User item) { if (!ModelState.IsValid) { return View (item); } using (var scope = new TransactionScope ()) { var user = Model.User.Find (item.UserName); user.Employee = Employee.Find (item.EmployeeId); user.Email = item.Email; user.IsAdministrator = item.IsAdministrator; foreach (var i in Enum.GetValues (typeof (SystemObjects))) { var obj = (SystemObjects) i; string prefix = Enum.GetName (typeof (SystemObjects), i); var privilege = user.Privileges.SingleOrDefault (x => x.Object == obj); if (privilege == null) { privilege = new AccessPrivilege { User = user, Object = obj }; } foreach (var j in Enum.GetValues (typeof (AccessRight))) { AccessRight right = (AccessRight) j; string name = prefix + Enum.GetName (typeof (AccessRight), j); string value = Request.Params [name]; if (value == null) continue; if (value.Contains ("true")) privilege.Privileges |= right; else privilege.Privileges &= ~right; } privilege.Save (); } user.UpdateAndFlush (); } return RedirectToAction ("Index"); }
private Match(AccessPrivilege accessPrivilege) { this.accessPrivilege = accessPrivilege; }
/// <summary>Loading a matcher from a string.</summary> /// <remarks> /// Loading a matcher from a string. The default access privilege is read-only. /// The string contains 1 or 2 parts, separated by whitespace characters, where /// the first part specifies the client hosts, and the second part (if /// existent) specifies the access privilege of the client hosts. I.e., /// "client-hosts [access-privilege]" /// </remarks> private static NfsExports.Match GetMatch(string line) { string[] parts = line.Split("\\s+"); string host; AccessPrivilege privilege = AccessPrivilege.ReadOnly; switch (parts.Length) { case 1: { host = StringUtils.ToLowerCase(parts[0]).Trim(); break; } case 2: { host = StringUtils.ToLowerCase(parts[0]).Trim(); string option = parts[1].Trim(); if (Runtime.EqualsIgnoreCase("rw", option)) { privilege = AccessPrivilege.ReadWrite; } break; } default: { throw new ArgumentException("Incorrectly formatted line '" + line + "'"); } } if (host.Equals("*")) { if (Log.IsDebugEnabled()) { Log.Debug("Using match all for '" + host + "' and " + privilege); } return(new NfsExports.AnonymousMatch(privilege)); } else { if (CidrFormatShort.Matcher(host).Matches()) { if (Log.IsDebugEnabled()) { Log.Debug("Using CIDR match for '" + host + "' and " + privilege); } return(new NfsExports.CIDRMatch(privilege, new SubnetUtils(host).GetInfo())); } else { if (CidrFormatLong.Matcher(host).Matches()) { if (Log.IsDebugEnabled()) { Log.Debug("Using CIDR match for '" + host + "' and " + privilege); } string[] pair = host.Split("/"); return(new NfsExports.CIDRMatch(privilege, new SubnetUtils(pair[0], pair[1]).GetInfo ())); } else { if (host.Contains("*") || host.Contains("?") || host.Contains("[") || host.Contains ("]") || host.Contains("(") || host.Contains(")")) { if (Log.IsDebugEnabled()) { Log.Debug("Using Regex match for '" + host + "' and " + privilege); } return(new NfsExports.RegexMatch(privilege, host)); } else { if (HostnameFormat.Matcher(host).Matches()) { if (Log.IsDebugEnabled()) { Log.Debug("Using exact match for '" + host + "' and " + privilege); } return(new NfsExports.ExactMatch(privilege, host)); } else { throw new ArgumentException("Invalid hostname provided '" + host + "'"); } } } } } }
/// <summary> /// You can update an existing playlist for the user. /// </summary> /// <param name="playlistId">The unique ID for the playlist.</param> /// <param name="name">The name the of playlist. Min Length: 1 character. Max Length: 100 characters.</param> /// <param name="description">The description of the playlist. Min Length: 0 characters. Max Length: 100 characters.</param> /// <param name="access">Specifies whether the playlist is publicly or privately available. Default: public</param> /// <returns>The updated playlist as PlaylistData</returns> public async Task<SingleRootObject<PlaylistData>> UpdatePlaylist(string playlistId, string name = "", string description = "", AccessPrivilege accessPrivilege = AccessPrivilege.Public) { Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(playlistId), "playlistId field is null"); ValidetaNameAndDescription(name, description); var paramsToUpdate = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("access", ParamValueAttributeHelper.GetParamValueOfEnumAttribute<AccessPrivilege>(accessPrivilege)) }; if (name != string.Empty) { paramsToUpdate.Add(new KeyValuePair<string, string>("name", name)); } if (description != string.Empty) { paramsToUpdate.Add(new KeyValuePair<string, string>("description", description)); } return await BeatsMusicManager.PutData<PlaylistData>("playlists/" + playlistId, paramsToUpdate.ToList()); }
private CIDRMatch(AccessPrivilege accessPrivilege, SubnetUtils.SubnetInfo subnetInfo ) : base(accessPrivilege) { this.subnetInfo = subnetInfo; }
private AnonymousMatch(AccessPrivilege accessPrivilege) : base(accessPrivilege) { }
private RegexMatch(AccessPrivilege accessPrivilege, string wildcard) : base(accessPrivilege) { this.pattern = Pattern.Compile(wildcard, Pattern.CaseInsensitive); }
public TreeItem(TreeItem parent, string name, AccessPrivilege accessPrivilege) { Parent = parent; Name = name; AccessPrivilege = accessPrivilege; }