예제 #1
0
 public void UnregisterSubject(Guid guid, bool remove)
 {
     using (SC.Utility.Lock l = new SC.Utility.Lock(secLock, SC.Utility.Lock.LockType.ForReading))
     {
         try
         {
             SecuritySubject subject = acls[guid];
             acls.Remove(guid);
             if (remove)
             {
                 l.UpgradeToWriterLock();
                 subjects.Remove(subject.Name);
                 l.DowngradeToReaderLock();
             }
         }
         catch (KeyNotFoundException)
         {
             Logger.Error("Tried unregistering subject that never registered.");
             throw;
         }
         catch (Exception e)
         {
             Logger.Error("An unexpected error occurred during unregistering of a subject.", e);
             throw;
         }
     }
     SaveSettings();
 }
예제 #2
0
        private void FixAdministrator()
        {
            using (SC.Utility.Lock l = new SC.Utility.Lock(secLock, SC.Utility.Lock.LockType.ForReading))
            {
                if (users.Count == 0)
                {
                    Logger.Warn("No users found, adding Administrator account with default password");

                    l.UpgradeToWriterLock();
                    UserInfo adminInfo = new UserInfo("Administrator", "ServerChecker4");
                    users.Add(adminInfo.Username, adminInfo);
                    l.DowngradeToReaderLock();
                }

                SecuritySubject me = acls[securityGuid];
                System.Collections.Specialized.StringCollection permissions = new System.Collections.Specialized.StringCollection();
                permissions.AddRange(me.GetPermissions());

                if (permissions.Count == 0)
                {
                    Logger.Warn("No permissions found for SecurityManager. Adding permission for Administrator account");

                    l.UpgradeToWriterLock();
                    me.AddPermission("Administrator");
                    l.DowngradeToReaderLock();
                }
            }
        }
예제 #3
0
        private Guid RegisterSubject(string name, string[] additionalOperations, string username)
        {
            Logger.Debug("Registered subject " + name);

            using (SC.Utility.Lock l = new SC.Utility.Lock(secLock, SC.Utility.Lock.LockType.ForWriting))
            {
                SecuritySubject subject;
                if (!subjects.ContainsKey(name))
                {
                    if (username == null)
                    {
                        subjects[name] = new SecuritySubject(name);
                    }
                    else
                    {
                        subjects[name] = new SecuritySubject(name, username);
                    }
                }

                subject = subjects[name];

                Guid guid = Guid.NewGuid();

                while (acls.ContainsKey(guid))
                {
                    guid = Guid.NewGuid();
                }

                acls.Add(guid, subject);

                if (additionalOperations != null)
                {
                    Logger.Debug("Additional operations " + string.Join(", ", additionalOperations));
                    System.Collections.Specialized.StringCollection operations = new System.Collections.Specialized.StringCollection();
                    operations.AddRange(additionalOperations);

                    foreach (string op in operations)
                    {
                        if (!subject.HaveOperation(op))
                        {
                            subject.AddOperation(op);
                        }
                    }
                    operations.Add(Operation.DEFAULT_OPERATION);
                    foreach (string op in subject.GetOperations())
                    {
                        if (!operations.Contains(op))
                        {
                            subject.RemoveOperation(op);
                        }
                    }
                }
                return(guid);
            }
        }
예제 #4
0
        private Guid RegisterSubject(string name, string[] additionalOperations, string username)
        {
            Logger.Debug("Registered subject " + name);

            using (SC.Utility.Lock l = new SC.Utility.Lock(secLock, SC.Utility.Lock.LockType.ForWriting))
            {
                SecuritySubject subject;
                if (!subjects.ContainsKey(name))
                {
                    if (username == null)
                        subjects[name] = new SecuritySubject(name);
                    else
                        subjects[name] = new SecuritySubject(name, username);
                }

                subject = subjects[name];

                Guid guid = Guid.NewGuid();

                while (acls.ContainsKey(guid))
                    guid = Guid.NewGuid();

                acls.Add(guid, subject);

                if (additionalOperations != null)
                {
                    Logger.Debug("Additional operations " + string.Join(", ", additionalOperations));
                    System.Collections.Specialized.StringCollection operations = new System.Collections.Specialized.StringCollection();
                    operations.AddRange(additionalOperations);

                    foreach (string op in operations)
                    {
                        if (!subject.HaveOperation(op))
                            subject.AddOperation(op);
                    }
                    operations.Add(Operation.DEFAULT_OPERATION);
                    foreach (string op in subject.GetOperations())
                    {
                        if (!operations.Contains(op))
                            subject.RemoveOperation(op);
                    }
                }
                return guid;
            }
        }