コード例 #1
0
 public static bool AssignMemberRight(MailboxSession mailboxSession, List <PermissionEntry> permissionEntries, DefaultFolderType defaultFolderType, out int foldersModified)
 {
     foldersModified = 0;
     try
     {
         using (Folder folder = Folder.Bind(mailboxSession, defaultFolderType))
         {
             bool          flag          = false;
             PermissionSet permissionSet = folder.GetPermissionSet();
             foreach (PermissionEntry permissionEntry in permissionEntries)
             {
                 if (permissionEntry.UserSecurityPrincipal != null && GroupMailboxPermissionHandler.ModifyPermission(permissionSet, permissionEntry.UserSecurityPrincipal, permissionEntry.UserRights))
                 {
                     flag = true;
                     foldersModified++;
                 }
             }
             if (flag)
             {
                 folder.Save();
             }
             return(true);
         }
     }
     catch (CorruptDataException arg)
     {
         GroupMailboxPermissionHandler.Tracer.TraceDebug <DefaultFolderType, CorruptDataException>(1L, "Member rights already configured for folder {0}. Exception: {1}", defaultFolderType, arg);
     }
     catch (ObjectNotFoundException ex)
     {
         GroupMailboxPermissionHandler.Tracer.TraceError(1L, (ex.InnerException != null) ? ex.InnerException.ToString() : ex.ToString());
     }
     return(false);
 }
コード例 #2
0
        private void CreateDefaultFolders()
        {
            int num = 0;

            foreach (DefaultFolderType defaultFolderType in this.mailboxSession.DefaultFolders)
            {
                if (!GroupMailboxPermissionHandler.IsFolderToBeIgnored(defaultFolderType))
                {
                    this.TraceDebug("Getting DefaultFolderId, DefaultFolderType={0}", new object[]
                    {
                        defaultFolderType
                    });
                    if (this.mailboxSession.GetDefaultFolderId(defaultFolderType) == null)
                    {
                        this.TraceDebug("Creating Folder {0}", new object[]
                        {
                            defaultFolderType
                        });
                        this.mailboxSession.CreateDefaultFolder(defaultFolderType);
                        num++;
                    }
                }
            }
            this.report.FoldersCreatedCount = num;
        }
コード例 #3
0
        private void SetFolderPermissions()
        {
            ExternalUser externalUser  = ExternalUser.CreateExternalUserForGroupMailbox(this.MailboxPrincipal.MailboxInfo.DisplayName, "Member@local", this.MailboxPrincipal.MailboxInfo.MailboxGuid, SecurityIdentity.GroupMailboxMemberType.Member);
            ExternalUser externalUser2 = ExternalUser.CreateExternalUserForGroupMailbox(this.MailboxPrincipal.MailboxInfo.DisplayName, "Owner@local", this.MailboxPrincipal.MailboxInfo.MailboxGuid, SecurityIdentity.GroupMailboxMemberType.Owner);

            using (ExternalUserCollection externalUsers = this.mailboxSession.GetExternalUsers())
            {
                if (!externalUsers.Contains(externalUser))
                {
                    externalUsers.Add(externalUser);
                }
                if (!externalUsers.Contains(externalUser2))
                {
                    externalUsers.Add(externalUser2);
                }
                externalUsers.Save();
                if (!externalUsers.Contains(externalUser))
                {
                    throw new GroupMailboxFailedToAddExternalUserException(Strings.ErrorUnableToAddExternalUser(externalUser.Name));
                }
                if (!externalUsers.Contains(externalUser2))
                {
                    throw new GroupMailboxFailedToAddExternalUserException(Strings.ErrorUnableToAddExternalUser(externalUser2.Name));
                }
                this.TraceDebug("Added external member user {0} to external user collection", new object[]
                {
                    externalUser.Name
                });
                this.TraceDebug("Added external owner user {0} to external user collection", new object[]
                {
                    externalUser2.Name
                });
            }
            PermissionSecurityPrincipal userSecurityPrincipal  = new PermissionSecurityPrincipal(externalUser);
            PermissionSecurityPrincipal userSecurityPrincipal2 = new PermissionSecurityPrincipal(externalUser2);
            int num = 0;
            List <PermissionEntry> list = new List <PermissionEntry>(3);
            var array = new < > f__AnonymousType0 <DefaultFolderType, MemberRights, MemberRights>[]
            {
                new
                {
                    Folder           = DefaultFolderType.MailboxAssociation,
                    OwnerPermission  = GroupMailboxPermissionHandler.MailboxAssociationPermission,
                    MemberPermission = GroupMailboxPermissionHandler.MailboxAssociationPermission
                },
                new
                {
                    Folder           = DefaultFolderType.SearchFolders,
                    OwnerPermission  = (GroupMailboxPermissionHandler.SearchFolderPermission | GroupMailboxPermissionHandler.OwnerSpecificPermission),
                    MemberPermission = GroupMailboxPermissionHandler.SearchFolderPermission
                },
                new
                {
                    Folder           = DefaultFolderType.Calendar,
                    OwnerPermission  = GroupMailboxPermissionHandler.CalendarFolderPermission,
                    MemberPermission = GroupMailboxPermissionHandler.CalendarFolderPermission
                }
            };

            list.Add(new PermissionEntry(userSecurityPrincipal2, GroupMailboxPermissionHandler.ConfigurationFolderPermission));
            int num2;

            GroupMailboxPermissionHandler.AssignMemberRight(this.mailboxSession, list, DefaultFolderType.Configuration, out num2);
            num += num2;
            var array2 = array;

            for (int i = 0; i < array2.Length; i++)
            {
                var <> f__AnonymousType = array2[i];
                list.Clear();
                list.Add(new PermissionEntry(userSecurityPrincipal2, <> f__AnonymousType.OwnerPermission));
                list.Add(new PermissionEntry(userSecurityPrincipal, <> f__AnonymousType.MemberPermission));
                if (!GroupMailboxPermissionHandler.AssignMemberRight(this.mailboxSession, list, <> f__AnonymousType.Folder, out num2))
                {
                    throw new GroupMailboxFailedToConfigureMailboxException(Strings.ErrorUnableToConfigureMailbox(< > f__AnonymousType.Folder.ToString(), this.MailboxPrincipal.MailboxInfo.DisplayName));
                }
                num += num2;
            }
            this.report.FoldersPrivilegedCount = num;
            this.mailboxSession.Mailbox[MailboxSchema.GroupMailboxPermissionsVersion] = GroupMailboxPermissionHandler.GroupMailboxPermissionVersion;
            this.mailboxSession.Mailbox.Save();
            this.mailboxSession.Mailbox.Load();
        }
コード例 #4
0
        private bool FolderMembershipUpdate()
        {
            ArgumentValidator.ThrowIfNull("previousExternalMemberUser", this.previousExternalMemberUser);
            ArgumentValidator.ThrowIfNull("currentExternalMemberUser", this.currentExternalMemberUser);
            ArgumentValidator.ThrowIfNull("currentExternalOwnerUser", this.currentExternalOwnerUser);
            PermissionSecurityPrincipal userSecurityPrincipal  = new PermissionSecurityPrincipal(this.previousExternalMemberUser);
            PermissionSecurityPrincipal userSecurityPrincipal2 = new PermissionSecurityPrincipal(this.currentExternalMemberUser);
            PermissionSecurityPrincipal userSecurityPrincipal3 = new PermissionSecurityPrincipal(this.currentExternalOwnerUser);
            List <PermissionEntry>      list = new List <PermissionEntry>(3);
            int  num    = 0;
            int  num2   = 0;
            bool result = true;

            foreach (DefaultFolderType defaultFolderType in this.mailboxSession.DefaultFolders)
            {
                list.Clear();
                if (!GroupMailboxPermissionHandler.IsFolderToBeIgnored(defaultFolderType) && defaultFolderType != DefaultFolderType.MailboxAssociation)
                {
                    if (this.mailboxSession.GetDefaultFolderId(defaultFolderType) != null)
                    {
                        DefaultFolderType defaultFolderType2 = defaultFolderType;
                        MemberRights      memberRights;
                        MemberRights      userRights;
                        if (defaultFolderType2 != DefaultFolderType.Calendar)
                        {
                            switch (defaultFolderType2)
                            {
                            case DefaultFolderType.Configuration:
                                memberRights = GroupMailboxPermissionHandler.DefaultFolderPermission;
                                userRights   = GroupMailboxPermissionHandler.ConfigurationFolderPermission;
                                break;

                            case DefaultFolderType.SearchFolders:
                                memberRights = GroupMailboxPermissionHandler.SearchFolderPermission;
                                userRights   = (memberRights | GroupMailboxPermissionHandler.OwnerSpecificPermission);
                                break;

                            default:
                                memberRights = GroupMailboxPermissionHandler.DefaultFolderPermission;
                                userRights   = (memberRights | GroupMailboxPermissionHandler.OwnerSpecificPermission);
                                break;
                            }
                        }
                        else
                        {
                            memberRights = GroupMailboxPermissionHandler.CalendarFolderPermission;
                            userRights   = GroupMailboxPermissionHandler.CalendarFolderPermission;
                        }
                        list.Add(new PermissionEntry(userSecurityPrincipal, MemberRights.None));
                        list.Add(new PermissionEntry(userSecurityPrincipal3, userRights));
                        list.Add(new PermissionEntry(userSecurityPrincipal2, memberRights));
                        if (defaultFolderType == DefaultFolderType.Calendar)
                        {
                            list.Add(new PermissionEntry(new PermissionSecurityPrincipal(PermissionSecurityPrincipal.SpecialPrincipalType.Default), MemberRights.FreeBusySimple));
                        }
                        else
                        {
                            list.Add(new PermissionEntry(new PermissionSecurityPrincipal(PermissionSecurityPrincipal.SpecialPrincipalType.Default), MemberRights.None));
                        }
                        if (!GroupMailboxPermissionHandler.AssignMemberRight(this.mailboxSession, list, defaultFolderType, out num2))
                        {
                            result = false;
                            break;
                        }
                        num += num2;
                    }
                    else
                    {
                        GroupMailboxMembershipUpdater.Tracer.TraceError <DefaultFolderType, string>((long)this.GetHashCode(), "MembershipUpdate: Found a folder {0} that is not in group mailbox {1}", defaultFolderType, this.mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString());
                    }
                }
            }
            GroupMailboxMembershipUpdater.Tracer.TraceDebug <int, string>((long)this.GetHashCode(), "MembershipUpdate: {0} folders had been modified for the group mailbox {1}", num, this.mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString());
            return(result);
        }