Exemplo n.º 1
0
        public void RemoveACEs(string userUri, List <ACEItem> aceItemList)
        {
            userEndpoint.InitializeUserEndpoint(userUri);
            userEndpoint.SubscribeToContainerMemberships();

            Dictionary <int, ContainerUpdateOperation> operations = new Dictionary <int, ContainerUpdateOperation>();

            foreach (ACEItem aceItem in aceItemList)
            {
                switch (aceItem.ACEType)
                {
                case ACEType.User:
                    operations = CreateDeleteUserACEOperation(operations, aceItem);
                    break;

                case ACEType.Company:
                    // Company should always be in a Container Membership - Default is Colleagues
                    operations = CreateDeleteSourceNetworkACEOperation(operations, SourceNetwork.SameEnterprise);

                    // Company ACE is added to the Colleagues container. It does equals to reset it to default
                    ACEItem colleaguesACEItem = new ACEItem(ACEType.Company, "", PresenceRelationshipLevel.Colleagues);
                    operations = CreateAddSourceNetworkACEOperation(operations, SourceNetwork.SameEnterprise, colleaguesACEItem);
                    break;

                case ACEType.Domain:
                    operations = CreateDeleteDomainACEOperation(operations, aceItem);
                    break;

                case ACEType.FederatedDomains:
                    // Company should always be in a Container Membership - Default is External
                    operations = CreateDeleteSourceNetworkACEOperation(operations, SourceNetwork.Federated);

                    // Federated ACE is added to the External container. It does equals to reset it to default
                    ACEItem externalACEItem = new ACEItem(ACEType.FederatedDomains, "", PresenceRelationshipLevel.External);
                    operations = CreateAddSourceNetworkACEOperation(operations, SourceNetwork.Federated, externalACEItem);
                    break;

                case ACEType.PublicDomains:
                    operations = CreateDeleteSourceNetworkACEOperation(operations, SourceNetwork.PublicCloud);
                    break;

                default:
                    // Should never happen
                    break;
                }
            }

            if (operations.Count > 0)
            {
                if (userEndpoint.User.LocalOwnerPresence.CurrentState == CollaborationSubscriptionState.Subscribed)
                {
                    userEndpoint.User.LocalOwnerPresence.EndUpdateContainerMembership(userEndpoint.User.LocalOwnerPresence.BeginUpdateContainerMembership(operations.Values, null, null));
                }
                else
                {
                    throw new Exception("Collaboration subscription state is not subscribed");
                }
            }
        }
Exemplo n.º 2
0
        public static List <ACEItem> GetACLFileData(string aclFilePath)
        {
            List <ACEItem> aceList = new List <ACEItem>();

            TextReader aclFile;

            aclFile = new StreamReader(aclFilePath);

            string  aceLine;
            ACEItem aceItem = null;

            int line = 1;

            while ((aceLine = aclFile.ReadLine()) != null)
            {
                aceLine = aceLine.Trim();

                if (aceLine.Trim().Length > 0)
                {
                    string[] aceDetails = aceLine.Split(' ');

                    if ((aceDetails.Length == 2) || (aceDetails.Length == 3))
                    {
                        string  userOrDomainValue = "";
                        ACEType aceType;
                        PresenceRelationshipLevel presenceRelationshipLevel;

                        switch (aceDetails[0].ToLowerInvariant())
                        {
                        case "user":
                            if (aceDetails.Length != 3)
                            {
                                throw new Exception(String.Format("Error at line {0}: an ACE with type User must have 3 values.", line));
                            }
                            aceType = ACEType.User;

                            if (IsValidUserEntry(aceDetails[2]))
                            {
                                userOrDomainValue = aceDetails[2];
                            }
                            else
                            {
                                throw new Exception(String.Format("ACL file content is incorrect at line {0}. Only SIP: entries are supported for ACE of type User.", line));
                            }

                            break;

                        case "domain":
                            if (aceDetails.Length != 3)
                            {
                                throw new Exception(String.Format("Error at line {0}: an ACE with type Domain must have 3 values.", line));
                            }

                            if (IsValidDomainEntry(aceDetails[2]))
                            {
                                userOrDomainValue = aceDetails[2];
                            }
                            else
                            {
                                throw new Exception(String.Format("ACL file content is incorrect at line {0}. Invalid value for ACE of type Domain.", line));
                            }

                            aceType = ACEType.Domain;
                            break;

                        case "company":
                            if (aceDetails.Length != 2)
                            {
                                throw new Exception(String.Format("Error at line {0}: an ACE with type Company must have 2 values.", line));
                            }
                            aceType = ACEType.Company;
                            break;

                        case "publicdomains":
                            if (aceDetails.Length != 2)
                            {
                                throw new Exception(String.Format("Error at line {0}: an ACE with type PublicDomains must have 2 values.", line));
                            }
                            aceType = ACEType.PublicDomains;
                            break;

                        case "federateddomains":
                            if (aceDetails.Length != 2)
                            {
                                throw new Exception(String.Format("Error at line {0}: an ACE with type FederatedDomains must have 2 values.", line));
                            }
                            aceType = ACEType.FederatedDomains;
                            break;

                        default:
                            throw new Exception(String.Format("Error at line {0}: incorrect value for ACE type. Value can be User, Domain, Company, FederatedDomains or PublicDomains.", line));
                        }

                        switch (aceDetails[1].ToLowerInvariant())
                        {
                        case "personal":
                            presenceRelationshipLevel = PresenceRelationshipLevel.Personal;
                            break;

                        case "workgroup":
                            presenceRelationshipLevel = PresenceRelationshipLevel.Workgroup;
                            break;

                        case "colleagues":
                            presenceRelationshipLevel = PresenceRelationshipLevel.Colleagues;
                            break;

                        case "external":
                            presenceRelationshipLevel = PresenceRelationshipLevel.External;
                            break;

                        case "blocked":
                            presenceRelationshipLevel = PresenceRelationshipLevel.Blocked;
                            break;

                        default:
                            throw new Exception(String.Format("Error at line {0}: incorrect value for Relationship Level. Value can be Personal, Workgroup, Colleagues, External or Blocked.", line));
                        }

                        // If here, it does mean values are correct because no Exception was thrown
                        aceItem = new ACEItem(aceType, userOrDomainValue, presenceRelationshipLevel);
                        aceList.Add(aceItem);
                    }
                    else
                    {
                        throw new Exception(String.Format("ACL file content is incorrect at line {0}. Every line must have 2 or 3 values.", line));
                    }
                }

                line++;
            }

            return(aceList);
        }
Exemplo n.º 3
0
        private Dictionary <int, ContainerUpdateOperation> CreateAddSourceNetworkACEOperation(Dictionary <int, ContainerUpdateOperation> operations, SourceNetwork sourceNetwork, ACEItem aceItem)
        {
            foreach (ContainerMembership container in userEndpoint.UserContainerMemberships)
            {
                if (container.ContainerId == (Int32)aceItem.PresenceRelationshipLevel)
                {
                    bool itemFound = false;

                    if (((Int32)container.AllowedSourceNetworks & (Int32)sourceNetwork) == (Int32)sourceNetwork)
                    {
                        itemFound = true;
                    }

                    if (!itemFound)
                    {
                        if (operations.ContainsKey(container.ContainerId))
                        {
                            operations[container.ContainerId].AddSourceNetwork(sourceNetwork);
                        }
                        else
                        {
                            ContainerUpdateOperation operation = new ContainerUpdateOperation(container.ContainerId);
                            operation.AddSourceNetwork(sourceNetwork);
                            operations.Add(container.ContainerId, operation);
                        }
                    }

                    break;
                }
            }

            return(operations);
        }
Exemplo n.º 4
0
        private Dictionary <int, ContainerUpdateOperation> CreateDeleteDomainACEOperation(Dictionary <int, ContainerUpdateOperation> operations, ACEItem aceItem)
        {
            foreach (ContainerMembership container in userEndpoint.UserContainerMemberships)
            {
                bool aceFound = false;

                foreach (string domain in container.AllowedSipDomains)
                {
                    if (domain.ToLowerInvariant() == aceItem.ItemValue.ToLowerInvariant())
                    {
                        aceFound = true;
                        break;
                    }
                }

                if (aceFound)
                {
                    if (operations.ContainsKey(container.ContainerId))
                    {
                        operations[container.ContainerId].DeleteDomain(aceItem.ItemValue);
                    }
                    else
                    {
                        ContainerUpdateOperation operation = new ContainerUpdateOperation(container.ContainerId);
                        operation.DeleteDomain(aceItem.ItemValue);
                        operations.Add(container.ContainerId, operation);
                    }
                    break;
                }
            }

            return(operations);
        }
Exemplo n.º 5
0
        private Dictionary <int, ContainerUpdateOperation> CreateAddUserACEOperation(Dictionary <int, ContainerUpdateOperation> operations, ACEItem aceItem)
        {
            foreach (ContainerMembership container in userEndpoint.UserContainerMemberships)
            {
                if (container.ContainerId == (Int32)aceItem.PresenceRelationshipLevel)
                {
                    bool aceFound = false;

                    foreach (RealTimeAddress user in container.AllowedSubscribers)
                    {
                        if (user.Uri.ToLowerInvariant() == aceItem.ItemValue.ToLowerInvariant())
                        {
                            aceFound = true;
                            break;
                        }
                    }

                    if (!aceFound)
                    {
                        if (operations.ContainsKey(container.ContainerId))
                        {
                            operations[container.ContainerId].AddUri(aceItem.ItemValue);
                        }
                        else
                        {
                            ContainerUpdateOperation operation = new ContainerUpdateOperation(container.ContainerId);
                            operation.AddUri(aceItem.ItemValue);
                            operations.Add(container.ContainerId, operation);
                        }
                    }

                    break;
                }
            }

            return(operations);
        }