private MapiAclTableRestriction.ExternalUserPermission TryGetExternalUserPermission(AclTableEntry aclTableEntry, MapiAclTableAdapter mapiAclTableAdapter, ref ExternalUserCollection externalUsers) { Util.ThrowOnNullArgument(aclTableEntry, "aclTableEntry"); Util.ThrowOnNullArgument(mapiAclTableAdapter, "mapiAclTableAdapter"); MailboxSession mailboxSession = this.session as MailboxSession; if (mailboxSession == null) { return(null); } byte[] memberEntryId = aclTableEntry.MemberEntryId; MemberRights memberRights = aclTableEntry.MemberRights; long memberId = aclTableEntry.MemberId; if (memberEntryId == null || memberEntryId.Length == 0) { if (memberId <= 0L) { return(null); } ExTraceGlobals.StorageTracer.TraceDebug <IExchangePrincipal, long>((long)this.GetHashCode(), "{0}: Getting memberEntryId from current ACL table for MemberId {1}.", mailboxSession.MailboxOwner, memberId); AclTableEntry byMemberId = mapiAclTableAdapter.GetByMemberId(memberId); if (byMemberId == null || byMemberId.MemberEntryId == null) { ExTraceGlobals.StorageTracer.TraceDebug <IExchangePrincipal, long>((long)this.GetHashCode(), "{0}: Not found memberEntryId from current ACL table for MemberId {1}. Skipped.", mailboxSession.MailboxOwner, memberId); return(null); } memberEntryId = byMemberId.MemberEntryId; } if (mapiAclTableAdapter.TryGetParticipantEntryId(memberEntryId) != null) { ExTraceGlobals.StorageTracer.TraceDebug <IExchangePrincipal>((long)this.GetHashCode(), "{0}: MemberEntryId indicates internal user. Skipped.", mailboxSession.MailboxOwner); return(null); } ExternalUser externalUser = mapiAclTableAdapter.TryGetExternalUser(memberEntryId, ref externalUsers); if (externalUser == null) { ExTraceGlobals.StorageTracer.TraceDebug <IExchangePrincipal>((long)this.GetHashCode(), "{0}: MemberEntryId is not external user. Skipped.", mailboxSession.MailboxOwner); return(null); } return(new MapiAclTableRestriction.ExternalUserPermission(externalUser, memberRights)); }
private void LoadFrom(MapiAclTableAdapter mapiAclTableAdapter) { IRecipientSession recipientSession = null; ExternalUserCollection disposable = null; AclTableEntry[] all = mapiAclTableAdapter.GetAll(); try { foreach (AclTableEntry aclTableEntry in all) { long memberId = aclTableEntry.MemberId; byte[] memberEntryId = aclTableEntry.MemberEntryId; string memberName = aclTableEntry.MemberName; MemberRights memberRights = aclTableEntry.MemberRights; if (memberId == 0L) { this.defaultMemberPermission = this.permissionSet.CreatePermission(new PermissionSecurityPrincipal(PermissionSecurityPrincipal.SpecialPrincipalType.Default), memberRights, memberId); } else if (memberId == -1L) { this.anonymousMemberPermission = this.permissionSet.CreatePermission(new PermissionSecurityPrincipal(PermissionSecurityPrincipal.SpecialPrincipalType.Anonymous), memberRights, memberId); } else if (memberEntryId != null) { ADParticipantEntryId adparticipantEntryId = mapiAclTableAdapter.TryGetParticipantEntryId(memberEntryId); if (adparticipantEntryId != null) { if (recipientSession == null) { recipientSession = mapiAclTableAdapter.Session.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid); } ADRecipient adrecipient = null; try { adrecipient = recipientSession.FindByLegacyExchangeDN(adparticipantEntryId.LegacyDN); } catch (DataValidationException) { ExTraceGlobals.StorageTracer.TraceDebug <string, string>(0L, "PermissionTable::PermissionTable. Caught exception from ADSesssion.FindByLegacyExchangeDN when trying to find a recipient from the ACL Table. Recipient name = {0}, LegDN = {1}.", memberName, adparticipantEntryId.LegacyDN); this.AddUnknownEntry(memberName, memberId, memberEntryId, memberRights); goto IL_17E; } if (adrecipient != null) { Permission permission = this.permissionSet.CreatePermission(new PermissionSecurityPrincipal(adrecipient), memberRights, memberId); this.AddPermissionEntry(permission.Principal, permission); } else { ExTraceGlobals.StorageTracer.TraceDebug <string, string>(0L, "PermissionTable::PermissionTable. Did not find the recipient from the ACL table in the AD. Recipient name = {0}, LegDN = {1}.", memberName, adparticipantEntryId.LegacyDN); this.AddUnknownEntry(memberName, memberId, memberEntryId, memberRights); } } else { this.AddNonADEntry(mapiAclTableAdapter, ref disposable, memberName, memberId, memberEntryId, memberRights); } } else { ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "PermissionTable::PermissionTable. Found a member in the ACL table (other than anonymous and default) without a member entry id. Recipient Name = {0}.", memberName); this.AddUnknownEntry(memberName, memberId, memberEntryId, memberRights); } IL_17E :; } } finally { Util.DisposeIfPresent(disposable); } }