Ejemplo n.º 1
0
        //add a new user to the policy database
        internal void AddUser(UserInfo userInfo)
        {
           lock (this)
            {
               //recursively add this user as belonging to all parent groups 
               //we start with the user itself, as each user belongs to its own group

                UserGroupInfo ancestor = userInfo;
                
                while (ancestor != null)
                {
                    UserGroupMembershipFact fact = new UserGroupMembershipFact(new StringPrincipal("usr:"******"grp:" + ancestor.Name));
                    groupMembershipFacts.Add(fact);
                    policyAssertions.Add(new Assertion(localAuthority, new Claim(fact)));

                    ancestor = ancestor.Parent;
                }
            }
        }
Ejemplo n.º 2
0
        //add a new user to the policy database
        internal void RemoveUser(UserInfo userInfo)
        {
            lock (this)
            {
                List<Assertion> asserstionsToRemove = new List<Assertion>();
                foreach (var assertion in policyAssertions)
                {
                    if (assertion.Claim.Fact is UserGroupMembershipFact)
                    {
                        UserGroupMembershipFact fact = (UserGroupMembershipFact)assertion.Claim.Fact;

                        if (fact.User.Name.Equals("usr:"******"grp:" + userInfo.Name))
                            asserstionsToRemove.Add(assertion);
                    }
                    else
                    {
                        throw new Exception("Unknown fact type!");
                    }
                }

                foreach (var assertion in asserstionsToRemove)
                {
                    policyAssertions.Remove(assertion);
                }
            }

            //PrintPolicies();
        }
Ejemplo n.º 3
0
        private void ReadUserSubTree(XmlElement xmlParent, UserGroupInfo parent)
        {
            foreach (XmlElement xmlChild in xmlParent.ChildNodes)
            {

                UserGroupInfo child;

                //names are case insensitive
                string name = xmlChild.GetAttribute("Name").ToLower();

                if (allGroups.ContainsKey(name))
                    throw new Exception("duplicate usergroup name " + name);

                switch (xmlChild.Name)
                {
                    case "Group":
                        {
                            child = new UserGroupInfo(nextUserOrGroupId, name);
                        }
                        break;
                    case "User":
                        {
                            string password = xmlChild.GetAttribute("Password");
                            string liveId = xmlChild.GetAttribute("LiveId");
                            string LiveIdUniqueUserToken = xmlChild.GetAttribute("LiveIdUniqueUserToken");
                            DateTime activeFrom = DateTime.Parse(xmlChild.GetAttribute("ActiveFrom"));
                            DateTime activeUntil = DateTime.Parse(xmlChild.GetAttribute("ActiveUntil"));

                            child = new UserInfo(nextUserOrGroupId, name, password, activeFrom, activeUntil, liveId, LiveIdUniqueUserToken);

                            if (xmlChild.ChildNodes.Count != 0)
                                throw new Exception("User " + name + " has children");
                        }
                        break;
                    default:
                        throw new Exception("bad node name in users file " + xmlChild.Name);
                }

                AddUserGroup(child, parent, false);
                nextUserOrGroupId++;

                ReadUserSubTree(xmlChild, child);

            }
        }
Ejemplo n.º 4
0
        public Tuple<UserInfo, string> AddLiveIdUser(string userName, string parentGroup, string liveId, string liveIdToken)
        {
            lock (allGroups)
            {
                if (allGroups.ContainsKey(userName.ToLower()))
                    return new Tuple<UserInfo, string> (null, "Attempt to add a user with duplicate username");

                if (!allGroups.ContainsKey(parentGroup.ToLower()))
                    return new Tuple<UserInfo, string> (null, "Parent group does not exist");

                //check for the uniqueness of LiveId and LiveIdUniqueUserToken 
                foreach (var userGroupInfo in allGroups.Values)
                {
                    var userInfo = userGroupInfo as UserInfo;

                    if (userInfo == null) continue;

                    if (userInfo.LiveIdUniqueUserToken.Equals(liveIdToken, StringComparison.CurrentCultureIgnoreCase))
                    {
                        return new Tuple<UserInfo, string>(null, "Duplicate liveIdUniqueUserToken");
                    }
                     if (userInfo.LiveId.Equals(liveId, StringComparison.CurrentCultureIgnoreCase))
                    {
                        return new Tuple<UserInfo, string>(null, "Duplicate liveId");
                    }
                }

                UserGroupInfo parent = allGroups[parentGroup];

                UserInfo user = new UserInfo(nextUserOrGroupId, userName, "", DateTime.MinValue, DateTime.MaxValue, liveId, liveIdToken);

                AddUserGroup(user, parent);

                nextUserOrGroupId++;

                return new Tuple<UserInfo,string> (user, "");
            }
        }