public virtual IList <AclEntry> GetAclPermission(bool includePermission) { string v = GetValue(); return(v != null ? AclEntry.ParseAclSpec(v, includePermission) : AclEntry.ParseAclSpec (Default, includePermission)); }
public virtual void TestMultipleAclSpecParsingWithoutPermissions() { IList <AclEntry> parsedList = AclEntry.ParseAclSpec("user::,user:user1:,group::,group:group1:,mask::,other::," + "default:user:user1::,default:mask::", false); AclEntry owner = new AclEntry.Builder().SetType(AclEntryType.User).Build(); AclEntry namedUser = new AclEntry.Builder().SetType(AclEntryType.User).SetName("user1" ).Build(); AclEntry group = new AclEntry.Builder().SetType(AclEntryType.Group).Build(); AclEntry namedGroup = new AclEntry.Builder().SetType(AclEntryType.Group).SetName( "group1").Build(); AclEntry mask = new AclEntry.Builder().SetType(AclEntryType.Mask).Build(); AclEntry other = new AclEntry.Builder().SetType(AclEntryType.Other).Build(); AclEntry defaultUser = new AclEntry.Builder().SetScope(AclEntryScope.Default).SetType (AclEntryType.User).SetName("user1").Build(); AclEntry defaultMask = new AclEntry.Builder().SetScope(AclEntryScope.Default).SetType (AclEntryType.Mask).Build(); IList <AclEntry> expectedList = new AList <AclEntry>(); expectedList.AddItem(owner); expectedList.AddItem(namedUser); expectedList.AddItem(group); expectedList.AddItem(namedGroup); expectedList.AddItem(mask); expectedList.AddItem(other); expectedList.AddItem(defaultUser); expectedList.AddItem(defaultMask); Assert.Equal("Parsed Acl not correct", expectedList, parsedList ); }
public void Constructor_InvalidResource_ShouldThrowArgumentException(string r) { Assert.Throws <ArgumentException>(() => { AclEntry entry = new AclEntry(r, "Action", "U.USer", Value.Grant); }); }
public EditableAclEntry(AclEntry acl) { Identity = acl.Identity; CanRead = acl.CanRead; CanWrite = acl.CanWrite; CanExecute = acl.CanExecute; }
/// <summary> /// Deletes some entries. /// </summary> /// <param name="entries">The entries to delete.</param> protected override void DeleteEntries(AclEntry[] entries) { lock (this) { AclEntry[] allEntries = LoadDataInternal( ); StringBuilder sb = new StringBuilder(10000); foreach (AclEntry originalEntry in allEntries) { // If the current entry is not contained in the entries array, then preserve it bool delete = false; foreach (AclEntry entryToDelete in entries) { if (AclEntry.Equals(originalEntry, entryToDelete)) { delete = true; break; } } if (!delete) { sb.Append(DumpAclEntry(originalEntry)); sb.Append("\r\n"); } } File.WriteAllText(_file, sb.ToString( )); } }
/// <summary> /// Deletes an ACL entry. /// </summary> /// <param name="resource">The controlled resource.</param> /// <param name="action">The action on the controlled resource.</param> /// <param name="subject">The subject whose access to the resource/action is controlled.</param> /// <returns><c>true</c> if the entry is deleted, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="resource" />, <paramref name="action" /> or /// <paramref name="subject" /> are <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// If <paramref name="resource" />, <paramref name="action" /> or /// <paramref name="subject" /> are empty. /// </exception> public bool DeleteEntry(string resource, string action, string subject) { if (resource == null) { throw new ArgumentNullException(nameof(resource)); } if (resource.Length == 0) { throw new ArgumentException("Resource cannot be empty", nameof(resource)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } if (action.Length == 0) { throw new ArgumentException("Action cannot be empty", nameof(action)); } if (subject == null) { throw new ArgumentNullException(nameof(subject)); } if (subject.Length == 0) { throw new ArgumentException("Subject cannot be empty", nameof(subject)); } var entry = new AclEntry(resource, action, subject, Value.Deny); return(_deleteEntries(new[] { entry })); }
public void Constructor_InvalidAction_ShouldThrowArgumentException(string a) { Assert.Throws <ArgumentException>(() => { AclEntry entry = new AclEntry("Res", a, "G.Group", Value.Deny); }); }
/// <summary>Simple acl tests on a directory: set a default acl, remove default acls. /// </summary> /// <exception cref="System.Exception"/> private void TestDirAcls() { if (IsLocalFS()) { return; } string defUser1 = "default:user:glarch:r-x"; FileSystem proxyFs = FileSystem.Get(GetProxiedFSConf()); FileSystem httpfs = GetHttpFSFileSystem(); Path dir = GetProxiedFSTestDir(); /* ACL Status on a directory */ AclStatus proxyAclStat = proxyFs.GetAclStatus(dir); AclStatus httpfsAclStat = httpfs.GetAclStatus(dir); AssertSameAcls(httpfsAclStat, proxyAclStat); /* Set a default ACL on the directory */ httpfs.SetAcl(dir, (AclEntry.ParseAclSpec(defUser1, true))); proxyAclStat = proxyFs.GetAclStatus(dir); httpfsAclStat = httpfs.GetAclStatus(dir); AssertSameAcls(httpfsAclStat, proxyAclStat); /* Remove the default ACL */ httpfs.RemoveDefaultAcl(dir); proxyAclStat = proxyFs.GetAclStatus(dir); httpfsAclStat = httpfs.GetAclStatus(dir); AssertSameAcls(httpfsAclStat, proxyAclStat); }
public void Constructor_InvalidSubject_ShouldThrowArgumentException(string s) { Assert.Throws <ArgumentException>(() => { AclEntry entry = new AclEntry("Res", "Action", s, Value.Grant); }); }
private void AssertAclEntriesAreEqual(AclEntry expected, AclEntry actual) { Assert.AreEqual(expected.Resource, actual.Resource, "Wrong resource"); Assert.AreEqual(expected.Action, actual.Action, "Wrong action"); Assert.AreEqual(expected.Subject, actual.Subject, "Wrong subject"); Assert.AreEqual(expected.Value, actual.Value, "Wrong value"); }
/// <summary> /// Inserimento, nella lista delle entries, di una permission basic /// </summary> /// <param name="entries"></param> /// <param name="accessor"></param> /// <param name="permitLevel"></param> public static void addBasicPermit(List <AclEntry> entries, string accessor, string permitLevel) { bool contains = false; // Verifica se la lista delle entries già contiene l'accessor fornito foreach (AclEntry entry in entries) { contains = (entry.accessor.Equals(accessor)); if (contains) { break; } } if (!contains) { AclEntry entry1 = new AclEntry(); entry1.accessor = accessor; // Creazione permission Permission p1 = new Permission(); p1.name = permitLevel; p1.type = PermissionType.BASIC; entry1.permission = p1; entries.Add(entry1); } }
public void Event_AclChanged_OverwriteEntry() { AclManagerBase manager = MockAclManager(); AclEntry entryOld = new AclEntry("Res", "Action", "U.User", Value.Deny); AclEntry entryNew = new AclEntry("Res", "Action", "U.User", Value.Grant); manager.StoreEntry(entryOld.Resource, entryOld.Action, entryOld.Subject, entryOld.Value); bool invokedStore = false; bool invokedDelete = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { if (e.Change == Change.EntryStored) { invokedStore = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entryNew, e.Entries[0]); Assert.AreEqual(Change.EntryStored, e.Change); } else { invokedDelete = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entryOld, e.Entries[0]); Assert.AreEqual(Change.EntryDeleted, e.Change); } }; manager.StoreEntry(entryNew.Resource, entryNew.Action, entryNew.Subject, entryNew.Value); Assert.IsTrue(invokedStore, "Store event not invoked"); Assert.IsTrue(invokedDelete, "Delete event not invoked"); }
internal static int ToInt(AclEntry aclEntry) { long aclEntryInt = 0; aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Scope.Bits .Combine((int)(aclEntry.GetScope()), aclEntryInt); aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Type.Bits .Combine((int)(aclEntry.GetType()), aclEntryInt); aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Permission .Bits.Combine((int)(aclEntry.GetPermission()), aclEntryInt); if (aclEntry.GetName() != null) { aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.NamedEntryCheck .Bits.Combine(1, aclEntryInt); if (aclEntry.GetType() == AclEntryType.User) { int userId = SerialNumberManager.Instance.GetUserSerialNumber(aclEntry.GetName()); aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Name.Bits .Combine(userId, aclEntryInt); } else { if (aclEntry.GetType() == AclEntryType.Group) { int groupId = SerialNumberManager.Instance.GetGroupSerialNumber(aclEntry.GetName( )); aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Name.Bits .Combine(groupId, aclEntryInt); } } } return((int)aclEntryInt); }
public async Task Acl_assign_permisssions_to_file_for_user() { string path = StoragePath.Combine(Filesystem, Guid.NewGuid().ToString()); string userId = _settings.AzureDataLakeGen2TestObjectId; //write something await _storage.WriteTextAsync(path, "perm?"); //check that user has no permissions AccessControl access = await _storage.GetAccessControlAsync(path); Assert.DoesNotContain(access.Acl, x => x.Identity == userId); //assign user a write permission access.Acl.Add(new AclEntry(ObjectType.User, userId, false, true, false)); await _storage.SetAccessControlAsync(path, access); //check user has permissions now access = await _storage.GetAccessControlAsync(path); AclEntry userAcl = access.Acl.First(e => e.Identity == userId); Assert.False(userAcl.CanRead); Assert.True(userAcl.CanWrite); Assert.False(userAcl.CanExecute); }
public async Task Acl_assign_default_permisssions_to_filesystem_for_user() { string filesystem = "acldefault"; string userId = _settings.AzureDataLakeGen2TestObjectId; //create filesystem await _storage.CreateFilesystemAsync(filesystem); //check that user has no permissions AccessControl access = await _storage.GetAccessControlAsync(filesystem); Assert.DoesNotContain(access.Acl, x => x.Identity == userId); //assign user a write permission access.DefaultAcl.Add(new AclEntry(ObjectType.User, userId, false, true, false)); await _storage.SetAccessControlAsync(filesystem, access); //check user has permissions now access = await _storage.GetAccessControlAsync(filesystem); //delete filesystem await _storage.DeleteFilesystemAsync(filesystem); AclEntry userAcl = access.DefaultAcl.First(e => e.Identity == userId); Assert.False(userAcl.CanRead); Assert.True(userAcl.CanWrite); Assert.False(userAcl.CanExecute); }
private void AssertAclEntriesAreEqual(AclEntry expected, AclEntry actual) { Assert.Equal(expected.Resource, actual.Resource); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Subject, actual.Subject); Assert.Equal(expected.Value, actual.Value); }
/// <summary>Convert a Json map to a AclStatus object.</summary> public static AclStatus ToAclStatus <_T0>(IDictionary <_T0> json) { if (json == null) { return(null); } IDictionary <object, object> m = (IDictionary <object, object>)json[typeof(AclStatus ).Name]; AclStatus.Builder aclStatusBuilder = new AclStatus.Builder(); aclStatusBuilder.Owner((string)m["owner"]); aclStatusBuilder.Group((string)m["group"]); aclStatusBuilder.StickyBit((bool)m["stickyBit"]); string permString = (string)m["permission"]; if (permString != null) { FsPermission permission = ToFsPermission(permString, (bool)m["aclBit"], (bool)m["encBit" ]); aclStatusBuilder.SetPermission(permission); } IList <object> entries = (IList <object>)m["entries"]; IList <AclEntry> aclEntryList = new AList <AclEntry>(); foreach (object entry in entries) { AclEntry aclEntry = AclEntry.ParseAclEntry((string)entry, true); aclEntryList.AddItem(aclEntry); } aclStatusBuilder.AddEntries(aclEntryList); return(aclStatusBuilder.Build()); }
/// <summary> /// Stores a new ACL entry. /// </summary> /// <param name="resource">The controlled resource.</param> /// <param name="action">The action on the controlled resource.</param> /// <param name="subject">The subject whose access to the resource/action is controlled.</param> /// <param name="value">The value of the entry.</param> /// <returns><c>true</c> if the entry is stored, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="resource" />, <paramref name="action" /> or /// <paramref name="subject" /> are <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// If <paramref name="resource" />, <paramref name="action" /> or /// <paramref name="subject" /> are empty. /// </exception> public bool StoreEntry(string resource, string action, string subject, Value value) { if (resource == null) { throw new ArgumentNullException(nameof(resource)); } if (resource.Length == 0) { throw new ArgumentException("Resource cannot be empty", nameof(resource)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } if (action.Length == 0) { throw new ArgumentException("Action cannot be empty", nameof(action)); } if (subject == null) { throw new ArgumentNullException(nameof(subject)); } if (subject.Length == 0) { throw new ArgumentException("Subject cannot be empty", nameof(subject)); } var entry = new AclEntry(resource, action, subject, value); return(_storeEntry(entry)); }
/// <summary> /// Loads data from storage. /// </summary> /// <returns>The loaded ACL entries.</returns> protected override AclEntry[] LoadDataInternal( ) { lock (this) { if (!File.Exists(_file)) { File.Create(_file).Close( ); return(new AclEntry[0]); } // Format // Resource|Action|Subject|(1|0) string[] lines = File.ReadAllLines(_file); AclEntry[] result = new AclEntry[lines.Length]; for (int i = 0; i < lines.Length; i++) { string[] fields = lines[i].Split('|'); result[i] = new AclEntry(fields[0], fields[1], fields[2], (fields[3] == "1" ? Value.Grant : Value.Deny)); } return(result); } }
public AclPackage UpdateAcl(AclIdentity aclIdentity, String userName) { List <AclIdentity> idList = new List <AclIdentity>(); idList.Add(aclIdentity); AclPackage aclPackage = accessControlService.Get(idList); AclEntry aclEntry = new AclEntry(); aclEntry.Accessor = userName; Permission basicDeletePermission = new Permission(); basicDeletePermission.Name = Permission.DELETE; basicDeletePermission.Type = PermissionType.BASIC; aclEntry.AccessType = AccessType.PERMIT; List <Permission> permissionList = new List <Permission>(); permissionList.Add(basicDeletePermission); aclEntry.Permissions = permissionList; Acl acl = aclPackage.Acls[0]; acl.Entries.Add(aclEntry); return(accessControlService.Update(aclPackage)); }
/// <summary> /// Updates a user to have new access permissions over a calendar. /// Note that this method will not run by default. /// </summary> /// <param name="entry">An existing AclEntry representing sharing permissions.</param> /// <param name="newRole">The new role (access permissions) for the user.</param> /// <returns>The updated AclEntry.</returns> static AclEntry UpdateEntry(AclEntry entry, AclRole newRole) { entry.Role = newRole; AclEntry updatedEntry = entry.Update() as AclEntry; Console.WriteLine("Updated {0} to have role {1}", updatedEntry.Scope.Value, entry.Role.Value); return(updatedEntry); }
public AclPackage CreateAcl(String repoName, String userName, String aclName) { AclIdentity aclIdentity = new AclIdentity(); aclIdentity.RepositoryName = repoName; aclIdentity.Domain = userName; aclIdentity.Name = aclName; Permission basicReadPermission = new Permission(); basicReadPermission.Name = Permission.READ; basicReadPermission.Type = PermissionType.BASIC; Permission basicDeletePermission = new Permission(); basicDeletePermission.Name = Permission.DELETE; basicDeletePermission.Type = PermissionType.BASIC; List <AclEntry> entryList = new List <AclEntry>(); AclEntry aclEntry = new AclEntry(); aclEntry.AccessType = AccessType.PERMIT; aclEntry.Accessor = "dm_world"; List <Permission> permissionList = new List <Permission>(); permissionList.Add(basicReadPermission); aclEntry.Permissions = permissionList; AclEntry aclEntry1 = new AclEntry(); aclEntry1.AccessType = AccessType.PERMIT; aclEntry1.Accessor = "dm_owner"; List <Permission> permissionList1 = new List <Permission>(); permissionList1.Add(basicDeletePermission); aclEntry1.Permissions = permissionList1; entryList.Add(aclEntry); entryList.Add(aclEntry1); Acl acl = new Acl(); acl.Identity = aclIdentity; acl.Description = "a test acl" + System.DateTime.Now.Ticks; // acl.setType(AclType.REGULAR); // defaults to REGULAR // acl.setVisibility(AclVisibility.PRIVATE); // defaults to PRIVATE acl.Entries = entryList; AclPackage aclPackage = new AclPackage(); List <Acl> aclList = new List <Acl>(); aclList.Add(acl); aclPackage.Acls = aclList; return(accessControlService.Create(aclPackage)); }
public AuthorizedNetworkModel(AclEntry acl, bool newNetwork = false) { _acl = acl; _newNetwork = newNetwork; _toBeDeleted = false; DeleteCommand = new ProtectedCommand(OnDeleteCommand); UndoDeleteCommand = new ProtectedCommand(OnUndoDeleteCommand); }
/// <summary> /// Builds the final list of ACL entries to return by trimming, sorting and /// validating the ACL entries that have been added. /// </summary> /// <param name="aclBuilder">ArrayList<AclEntry> containing entries to build</param> /// <returns>List<AclEntry> unmodifiable, sorted list of ACL entries</returns> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.AclException">if validation fails /// </exception> private static IList <AclEntry> BuildAndValidateAcl(AList <AclEntry> aclBuilder) { if (aclBuilder.Count > MaxEntries) { throw new AclException("Invalid ACL: ACL has " + aclBuilder.Count + " entries, which exceeds maximum of " + MaxEntries + "."); } aclBuilder.TrimToSize(); aclBuilder.Sort(AclEntryComparator); // Full iteration to check for duplicates and invalid named entries. AclEntry prevEntry = null; foreach (AclEntry entry in aclBuilder) { if (prevEntry != null && AclEntryComparator.Compare(prevEntry, entry) == 0) { throw new AclException("Invalid ACL: multiple entries with same scope, type and name." ); } if (entry.GetName() != null && (entry.GetType() == AclEntryType.Mask || entry.GetType () == AclEntryType.Other)) { throw new AclException("Invalid ACL: this entry type must not have a name: " + entry + "."); } prevEntry = entry; } // Search for the required base access entries. If there is a default ACL, // then do the same check on the default entries. ScopedAclEntries scopedEntries = new ScopedAclEntries(aclBuilder); foreach (AclEntryType type in EnumSet.Of(AclEntryType.User, AclEntryType.Group, AclEntryType .Other)) { AclEntry accessEntryKey = new AclEntry.Builder().SetScope(AclEntryScope.Access).SetType (type).Build(); if (Sharpen.Collections.BinarySearch(scopedEntries.GetAccessEntries(), accessEntryKey , AclEntryComparator) < 0) { throw new AclException("Invalid ACL: the user, group and other entries are required." ); } if (!scopedEntries.GetDefaultEntries().IsEmpty()) { AclEntry defaultEntryKey = new AclEntry.Builder().SetScope(AclEntryScope.Default) .SetType(type).Build(); if (Sharpen.Collections.BinarySearch(scopedEntries.GetDefaultEntries(), defaultEntryKey , AclEntryComparator) < 0) { throw new AclException("Invalid default ACL: the user, group and other entries are required." ); } } } return(Sharpen.Collections.UnmodifiableList(aclBuilder)); }
public static ImmutableList <AclEntry> ToAclEntries(int[] entries) { ImmutableList.Builder <AclEntry> b = new ImmutableList.Builder <AclEntry>(); foreach (int entry in entries) { AclEntry aclEntry = ToAclEntry(entry); b.Add(aclEntry); } return((ImmutableList <AclEntry>)b.Build()); }
internal DataLakeStoreItemAce(AclEntry entry) { Scope = (DataLakeStoreEnums.ScopeType)entry.Scope; Type = MapAclEntryType(entry.Type); Id = entry.UserOrGroupId; Permission = entry.Action.GetRwx(); Entry = $"{(Scope == DataLakeStoreEnums.ScopeType.Default ? "default:":string.Empty)}{Type}:{Id}:{Permission}"; NoPermissionEntry = $"{(Scope == DataLakeStoreEnums.ScopeType.Default ? "default:" : string.Empty)}{Type}:{Id}"; }
public void Equal() { AclEntry entry = new AclEntry("Res", "Action", "U.User", Value.Grant); Assert.False(entry.Equals(null), "Equals should return false (testing null)"); Assert.False(entry.Equals("blah"), "Equals should return false (testing a string)"); Assert.False(entry.Equals(new AclEntry("Res1", "Action", "U.User", Value.Grant)), "Equals should return false"); Assert.False(entry.Equals(new AclEntry("Res", "Action1", "U.User", Value.Grant)), "Equals should return false"); Assert.False(entry.Equals(new AclEntry("Res", "Action", "U.User1", Value.Grant)), "Equals should return false"); Assert.True(entry.Equals(new AclEntry("Res", "Action", "U.User", Value.Deny)), "Equals should return true"); Assert.True(entry.Equals(new AclEntry("Res", "Action", "U.User", Value.Grant)), "Equals should return true"); Assert.True(entry.Equals(entry), "Equals should return true"); }
public void Static_Equals() { AclEntry entry = new AclEntry("Res", "Action", "U.User", Value.Grant); Assert.IsFalse(AclEntry.Equals(entry, null), "Equals should return false (testing null)"); Assert.IsFalse(AclEntry.Equals(entry, "blah"), "Equals should return false (testing a string)"); Assert.IsFalse(AclEntry.Equals(entry, new AclEntry("Res1", "Action", "U.User", Value.Grant)), "Equals should return false"); Assert.IsFalse(AclEntry.Equals(entry, new AclEntry("Res", "Action1", "U.User", Value.Grant)), "Equals should return false"); Assert.IsFalse(AclEntry.Equals(entry, new AclEntry("Res", "Action", "U.User1", Value.Grant)), "Equals should return false"); Assert.IsTrue(AclEntry.Equals(entry, new AclEntry("Res", "Action", "U.User", Value.Deny)), "Equals should return true"); Assert.IsTrue(AclEntry.Equals(entry, new AclEntry("Res", "Action", "U.User", Value.Grant)), "Equals should return true"); Assert.IsTrue(AclEntry.Equals(entry, entry), "Equals should return true"); }
//static string user1name = ConfigurationManager.AppSettings["CalendarUser1"].ToString(); //static string user1pwd = ConfigurationManager.AppSettings["Calendarpass1"].ToString(); public static void AddEvent1(CalendarService service, string id, string title, string contents, string location, DateTime startTime, DateTime endTime, string calendarName, string emailId) { try { Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry(); // Set the title and content of the entry. entry.Title.Text = id + "-" + title; entry.Content.Content = contents; // Set a location for the event. Where eventLocation = new Where(); eventLocation.ValueString = location; entry.Locations.Add(eventLocation); When eventTime = new When(startTime, endTime); entry.Times.Add(eventTime); GoogleCalendar ggadmin = new GoogleCalendar(calendarName, AdminuserName, AdminuserPwd); // string CalendarId = ggadmin.GetCalendarId(); //CalendarService Calservice = new CalendarService("CalendarSampleApp"); AclEntry aclEntry = new AclEntry(); aclEntry.Scope = new AclScope(); aclEntry.Scope.Type = AclScope.SCOPE_USER; aclEntry.Scope.Value = emailId; aclEntry.Role = AclRole.ACL_CALENDAR_READ; // Uri postUri = new Uri("https://www.google.com/calendar/feeds/" + CalendarId + "/private/full"); Uri aclUri = new Uri(string.Format("https://www.google.com/calendar/feeds/{0}/acl/full", service.Credentials.Username.ToString())); GDataGAuthRequestFactory requestFactory = (GDataGAuthRequestFactory)service.RequestFactory; IWebProxy iProxy = WebRequest.GetSystemWebProxy(); WebProxy myProxy = new WebProxy(); // potentially, setup credentials on the proxy here myProxy.Credentials = CredentialCache.DefaultCredentials; myProxy.UseDefaultCredentials = false; // requestFactory.CreateRequest(GDataRequestType.Insert, postUri);// = myProxy; // Send the request and receive the response: //AtomEntry insertEntry = service.Insert(postUri, entry); AclEntry insertedEntry = service.Insert(aclUri, aclEntry) as AclEntry; } catch (Exception ex) { //LogManager.Instance.WriteToFlatFile(ex.Message); } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessOptions(List <string> args) { cf.Parse(args); SetRecursive(cf.GetOpt("R")); // Mix of remove and modify acl flags are not allowed bool bothRemoveOptions = cf.GetOpt("b") && cf.GetOpt("k"); bool bothModifyOptions = cf.GetOpt("m") && cf.GetOpt("x"); bool oneRemoveOption = cf.GetOpt("b") || cf.GetOpt("k"); bool oneModifyOption = cf.GetOpt("m") || cf.GetOpt("x"); bool setOption = cf.GetOpt("-set"); if ((bothRemoveOptions || bothModifyOptions) || (oneRemoveOption && oneModifyOption ) || (setOption && (oneRemoveOption || oneModifyOption))) { throw new HadoopIllegalArgumentException("Specified flags contains both remove and modify flags" ); } // Only -m, -x and --set expects <acl_spec> if (oneModifyOption || setOption) { if (args.Count < 2) { throw new HadoopIllegalArgumentException("<acl_spec> is missing"); } aclEntries = AclEntry.ParseAclSpec(args.RemoveFirst(), !cf.GetOpt("x")); } if (args.IsEmpty()) { throw new HadoopIllegalArgumentException("<path> is missing"); } if (args.Count > 1) { throw new HadoopIllegalArgumentException("Too many arguments"); } // In recursive mode, save a separate list of just the access ACL entries. // Only directories may have a default ACL. When a recursive operation // encounters a file under the specified path, it must pass only the // access ACL entries. if (IsRecursive() && (oneModifyOption || setOption)) { accessAclEntries = Lists.NewArrayList(); foreach (AclEntry entry in aclEntries) { if (entry.GetScope() == AclEntryScope.Access) { accessAclEntries.AddItem(entry); } } } }
public AclPackage CreateAcl(String repoName, String userName, String aclName) { AclIdentity aclIdentity = new AclIdentity(); aclIdentity.RepositoryName = repoName; aclIdentity.Domain = userName; aclIdentity.Name = aclName; Permission basicReadPermission = new Permission(); basicReadPermission.Name = Permission.READ; basicReadPermission.Type = PermissionType.BASIC; Permission basicDeletePermission = new Permission(); basicDeletePermission.Name = Permission.DELETE; basicDeletePermission.Type = PermissionType.BASIC; List<AclEntry> entryList = new List<AclEntry>(); AclEntry aclEntry = new AclEntry(); aclEntry.AccessType = AccessType.PERMIT; aclEntry.Accessor = "dm_world"; List<Permission> permissionList = new List<Permission>(); permissionList.Add(basicReadPermission); aclEntry.Permissions = permissionList; AclEntry aclEntry1 = new AclEntry(); aclEntry1.AccessType = AccessType.PERMIT; aclEntry1.Accessor = "dm_owner"; List<Permission> permissionList1 = new List<Permission>(); permissionList1.Add(basicDeletePermission); aclEntry1.Permissions = permissionList1; entryList.Add(aclEntry); entryList.Add(aclEntry1); Acl acl = new Acl(); acl.Identity = aclIdentity; acl.Description = "a test acl" + System.DateTime.Now.Ticks; // acl.setType(AclType.REGULAR); // defaults to REGULAR // acl.setVisibility(AclVisibility.PRIVATE); // defaults to PRIVATE acl.Entries = entryList; AclPackage aclPackage = new AclPackage(); List<Acl> aclList = new List<Acl>(); aclList.Add(acl); aclPackage.Acls = aclList; return accessControlService.Create(aclPackage); }
public void Constructor() { AclEntry entry = new AclEntry("Res", "Action", "U.User", Value.Grant); AclChangedEventArgs args = new AclChangedEventArgs(new AclEntry[] { entry }, Change.EntryStored); Assert.AreEqual(1, args.Entries.Length, "Wrong entry count"); Assert.AreSame(entry, args.Entries[0], "Wrong Entry instance"); Assert.AreEqual(Change.EntryStored, args.Change, "Wrong change"); args = new AclChangedEventArgs(new AclEntry[] { entry }, Change.EntryDeleted); Assert.AreEqual(1, args.Entries.Length, "Wrong entry count"); Assert.AreSame(entry, args.Entries[0], "Wrong Entry instance"); Assert.AreEqual(Change.EntryDeleted, args.Change, "Wrong change"); }
public void Constructor() { AclEntry entry = new AclEntry("Res", "Action", "U.User", Value.Grant); Assert.AreEqual("Res", entry.Resource, "Wrong resource"); Assert.AreEqual("Action", entry.Action, "Wrong action"); Assert.AreEqual("U.User", entry.Subject, "Wrong subject"); Assert.AreEqual(Value.Grant, entry.Value, "Wrong value"); entry = new AclEntry("Res", "Action", "G.Group", Value.Deny); Assert.AreEqual("Res", entry.Resource, "Wrong resource"); Assert.AreEqual("Action", entry.Action, "Wrong action"); Assert.AreEqual("G.Group", entry.Subject, "Wrong subject"); Assert.AreEqual(Value.Deny, entry.Value, "Wrong value"); }
public void Constructor_InvalidResource(string r) { AclEntry entry = new AclEntry(r, "Action", "U.USer", Value.Grant); }
public bool AddAccessRight(string identity, string accessString) { if (possibleAccessStrings.Contains(accessString)) { if (!accessList.ContainsKey(identity)) { accessList.Add(identity, new List<string>()); } accessList[identity].Add(accessString); var aclEntry = new AclEntry { AccessString = accessString, Identity = identity }; bot.MainBotData.AclEntries.InsertOnSubmit(aclEntry); bot.MainBotData.SubmitChanges(); return true; } return false; }
List<AclEntry> ListAclEntries() { MySqlConnection connection = ConnectionPool.Request(); MySqlCommand command = new MySqlCommand(_query_20, connection); MySqlDataReader reader = null; try { List<AclEntry> list = new List<AclEntry>(); reader = command.ExecuteReader(); uint i = 0; while (reader.Read()) { AclEntry info = new AclEntry(); info.RuleId = ++i; info.IP = reader.GetString(1); info.Mask = reader.GetString(2); info.Operation = reader.GetByte(3); list.Add(info); } reader.Close(); return list; } catch (Exception e) { __dbtracelog.WriteError("Database", e.Message); throw e; } finally { if (reader != null) reader.Close(); ConnectionPool.Release(connection); } }
public void Event_AclChanged_OverwriteEntry() { AclManagerBase manager = MockAclManager(); AclEntry entryOld = new AclEntry("Res", "Action", "U.User", Value.Deny); AclEntry entryNew = new AclEntry("Res", "Action", "U.User", Value.Grant); manager.StoreEntry(entryOld.Resource, entryOld.Action, entryOld.Subject, entryOld.Value); bool invokedStore = false; bool invokedDelete = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { if(e.Change == Change.EntryStored) { invokedStore = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entryNew, e.Entries[0]); Assert.AreEqual(Change.EntryStored, e.Change); } else { invokedDelete = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entryOld, e.Entries[0]); Assert.AreEqual(Change.EntryDeleted, e.Change); } }; manager.StoreEntry(entryNew.Resource, entryNew.Action, entryNew.Subject, entryNew.Value); Assert.IsTrue(invokedStore, "Store event not invoked"); Assert.IsTrue(invokedDelete, "Delete event not invoked"); }
public AclPackage UpdateAcl(AclIdentity aclIdentity, String userName) { List<AclIdentity> idList = new List<AclIdentity>(); idList.Add(aclIdentity); AclPackage aclPackage = accessControlService.Get(idList); AclEntry aclEntry = new AclEntry(); aclEntry.Accessor = userName; Permission basicDeletePermission = new Permission(); basicDeletePermission.Name = Permission.DELETE; basicDeletePermission.Type = PermissionType.BASIC; aclEntry.AccessType = AccessType.PERMIT; List<Permission> permissionList = new List<Permission>(); permissionList.Add(basicDeletePermission); aclEntry.Permissions = permissionList; Acl acl = aclPackage.Acls[0]; acl.Entries.Add(aclEntry); return accessControlService.Update(aclPackage); }
public void Event_AclChanged_StoreEntry() { AclManagerBase manager = MockAclManager(); AclEntry entry = new AclEntry("Res", "Action", "U.User", Value.Grant); bool invoked = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { invoked = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entry, e.Entries[0]); Assert.AreEqual(Change.EntryStored, e.Change); }; manager.StoreEntry(entry.Resource, entry.Action, entry.Subject, entry.Value); Assert.IsTrue(invoked, "Store event not invoked"); }
public void RenameResource() { AclManagerBase manager = MockAclManager(); Assert.IsFalse(manager.RenameResource("Res", "Res_Renamed"), "RenameResource should return false"); AclEntry entry1 = new AclEntry("Res", "Action", "U.User", Value.Grant); AclEntry newEntry1 = new AclEntry("Res_Renamed", "Action", "U.User", Value.Grant); AclEntry entry2 = new AclEntry("Res", "Action2", "U.User2", Value.Deny); AclEntry newEntry2 = new AclEntry("Res_Renamed", "Action2", "U.User", Value.Deny); manager.StoreEntry(entry1.Resource, entry1.Action, entry1.Subject, entry1.Value); manager.StoreEntry(entry2.Resource, entry2.Action, entry2.Subject, entry2.Value); manager.StoreEntry("Res2", "Action", "G.Group", Value.Deny); bool invokedDelete1 = false; bool invokedStore1 = false; bool invokedDelete2 = false; bool invokedStore2 = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { if(e.Change == Change.EntryDeleted) { Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); Assert.AreEqual("Res", e.Entries[0].Resource, "Wrong resource"); if(e.Entries[0].Action == entry1.Action) invokedDelete1 = true; if(e.Entries[0].Action == entry2.Action) invokedDelete2 = true; } else { Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); Assert.AreEqual("Res_Renamed", e.Entries[0].Resource, "Wrong resource"); if(e.Entries[0].Action == entry1.Action) invokedStore1 = true; if(e.Entries[0].Action == entry2.Action) invokedStore2 = true; } }; Assert.IsTrue(manager.RenameResource("Res", "Res_Renamed"), "RenameResource should return true"); Assert.IsTrue(invokedDelete1, "Delete event 1 not invoked"); Assert.IsTrue(invokedStore1, "Store event 1 not invoked"); Assert.IsTrue(invokedDelete2, "Delete event 2 not invoked"); Assert.IsTrue(invokedStore2, "Store event 2 not invoked"); AclEntry[] entries = manager.RetrieveAllEntries(); Assert.AreEqual(3, entries.Length, "Wrong entry count"); Array.Sort(entries, delegate(AclEntry x, AclEntry y) { return x.Resource.CompareTo(y.Resource); }); Assert.AreEqual("Res_Renamed", entries[0].Resource, "Wrong resource"); if(entries[0].Value == Value.Grant) { Assert.AreEqual("Action", entries[0].Action, "Wrong action"); Assert.AreEqual("U.User", entries[0].Subject, "Wrong subject"); } else { Assert.AreEqual("Action2", entries[0].Action, "Wrong action"); Assert.AreEqual("U.User2", entries[0].Subject, "Wrong subject"); } Assert.AreEqual("Res_Renamed", entries[1].Resource, "Wrong resource"); if(entries[1].Value == Value.Grant) { Assert.AreEqual("Action", entries[1].Action, "Wrong action"); Assert.AreEqual("U.User", entries[1].Subject, "Wrong subject"); } else { Assert.AreEqual("Action2", entries[1].Action, "Wrong action"); Assert.AreEqual("U.User2", entries[1].Subject, "Wrong subject"); } Assert.AreEqual("Res2", entries[2].Resource, "Wrong resource"); Assert.AreEqual("Action", entries[2].Action, "Wrong action"); Assert.AreEqual("G.Group", entries[2].Subject, "Wrong subject"); Assert.AreEqual(Value.Deny, entries[2].Value, "Wrong value"); }
public void Constructor_InvalidSubject(string s) { AclEntry entry = new AclEntry("Res", "Action", s, Value.Grant); }
public void Constructor_InvalidAction(string a) { AclEntry entry = new AclEntry("Res", a, "G.Group", Value.Deny); }