예제 #1
0
        public static PublishedFolder Create(PublishingUrl publishingUrl)
        {
            Util.ThrowOnNullArgument(publishingUrl, "publishingUrl");
            PublishedFolder.SleepIfNecessary();
            SharingAnonymousIdentityCache      instance = SharingAnonymousIdentityCache.Instance;
            SharingAnonymousIdentityCacheKey   key      = publishingUrl.CreateKey();
            SharingAnonymousIdentityCacheValue sharingAnonymousIdentityCacheValue = instance.Get(key);

            if (!sharingAnonymousIdentityCacheValue.IsAccessAllowed)
            {
                ExTraceGlobals.SharingTracer.TraceError <PublishingUrl, Type>(0L, "PublishedFolder.Create(PublishingUrl): Cannot find access allowed folder from the request url: path = {0}, type = {1}.", publishingUrl, publishingUrl.GetType());
                throw new PublishedFolderAccessDeniedException();
            }
            ExTraceGlobals.SharingTracer.TraceDebug <SecurityIdentifier, string, string>(0L, "PublishedFolder.Create(PublishingUrl): User {0} has Sharing Anonymous identity {1}. The corresponding folder identity is {2}.", sharingAnonymousIdentityCacheValue.Sid, publishingUrl.Identity, sharingAnonymousIdentityCacheValue.FolderId);
            StoreObjectId storeObjectId = null;

            try
            {
                storeObjectId = StoreObjectId.Deserialize(sharingAnonymousIdentityCacheValue.FolderId);
            }
            catch (CorruptDataException innerException)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>(0L, "PublishedFolder.Create(PublishingUrl): The folder identity '{0}' is invalid.", sharingAnonymousIdentityCacheValue.FolderId);
                throw new PublishedFolderAccessDeniedException(innerException);
            }
            if (publishingUrl.DataType == SharingDataType.ReachCalendar || publishingUrl.DataType == SharingDataType.Calendar)
            {
                ObscureUrl obscureUrl = publishingUrl as ObscureUrl;
                return(new PublishedCalendar(publishingUrl.Domain, sharingAnonymousIdentityCacheValue.Sid, storeObjectId, (obscureUrl == null) ? null : new ObscureKind?(obscureUrl.ObscureKind), (obscureUrl == null) ? null : obscureUrl.ReachUserSid));
            }
            throw new NotSupportedException();
        }
예제 #2
0
        public static ObscureUrl CreatePublishReachCalendarUrl(string externalUrl, Guid mailboxGuid, string domain, string existingIdentity, SecurityIdentifier reachUserSid)
        {
            Util.ThrowOnNullOrEmptyArgument(externalUrl, "externalUrl");
            Util.ThrowOnNullOrEmptyArgument(domain, "domain");
            Util.ThrowOnNullArgument(reachUserSid, "reachUserSid");
            if (!ExternalUser.IsValidReachSid(reachUserSid))
            {
                throw new ArgumentException("Not an valid reach user sid.", "reachUserSid");
            }
            SharingDataType reachCalendar = SharingDataType.ReachCalendar;
            string          text          = string.IsNullOrEmpty(existingIdentity) ? Guid.NewGuid().ToString("N") : ObscureUrl.ParseGuidIdentity(reachCalendar, existingIdentity).ToString("N");
            string          text2         = ObscureUrl.CalculateHashString(ObscureKind.Normal, text);
            string          uriString     = string.Format("{0}/{1}/{2}@{3}/{4}{5}/{6}/{7}", new object[]
            {
                externalUrl.TrimEnd(new char[]
                {
                    '/'
                }),
                reachCalendar.ExternalName,
                mailboxGuid.ToString("N"),
                domain,
                text,
                text2,
                reachUserSid.ToString(),
                reachCalendar.PublishResourceName
            });
            ObscureUrl obscureUrl = new ObscureUrl(new Uri(uriString, UriKind.Absolute), reachCalendar, mailboxGuid, domain, text, ObscureKind.Normal, reachUserSid);

            ExTraceGlobals.SharingTracer.TraceDebug <ObscureUrl, string>(0L, "ObscureUrl.CreatePublishReachCalendarUrl(): Created an instance of ObscureUrl: {0} - {1}.", obscureUrl, obscureUrl.TraceInfo);
            return(obscureUrl);
        }
예제 #3
0
 internal ObscureUrlKey(ObscureUrl url) : base(ObscureUrlKey.GetHashCode(url))
 {
     Util.ThrowOnNullArgument(url, "url");
     this.mailboxGuid = url.MailboxGuid;
     this.urlId       = url.Identity;
     this.domain      = url.Domain;
 }
예제 #4
0
        protected override PerformInvitationResults InternalPerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator)
        {
            if (recipients.Length != 1)
            {
                throw new InvalidOperationException("Only single recipient is allowed.");
            }
            ValidRecipient    validRecipient     = recipients[0];
            string            folderId           = context.FolderId.ToBase64String();
            ExternalUser      externalUser       = this.ApplyPermission(mailboxSession, new SmtpAddress(validRecipient.SmtpAddress), context);
            IRecipientSession adrecipientSession = mailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent);
            ADUser            aduser             = (ADUser)adrecipientSession.Read(mailboxSession.MailboxOwner.ObjectId);
            string            text         = aduser.SharingAnonymousIdentities.FindExistingUrlId(SharingDataType.ReachCalendar.PublishResourceName, folderId);
            Uri         owaVdirUrl         = OwaAnonymousVdirLocater.Instance.GetOwaVdirUrl(mailboxSession.MailboxOwner, frontEndLocator);
            SmtpAddress primarySmtpAddress = mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress;
            ObscureUrl  obscureUrl         = ObscureUrl.CreatePublishReachCalendarUrl(owaVdirUrl.ToString(), mailboxSession.MailboxGuid, primarySmtpAddress.Domain, text, externalUser.Sid);

            if (string.IsNullOrEmpty(text))
            {
                aduser.SharingAnonymousIdentities.AddOrUpdate(SharingDataType.ReachCalendar.PublishResourceName, obscureUrl.Identity, folderId);
                adrecipientSession.Save(aduser);
            }
            context.BrowseUrl = obscureUrl.ToString() + ".html";
            context.ICalUrl   = obscureUrl.ToString() + ".ics";
            return(new PerformInvitationResults(recipients));
        }
예제 #5
0
        internal ObscureUrl ChangeToKind(ObscureKind obscureKind)
        {
            if (base.DataType == SharingDataType.ReachCalendar || this.ObscureKind == obscureKind)
            {
                return(this);
            }
            string str            = ObscureUrl.CalculateHashString(this.ObscureKind, this.GuidIdentity);
            string str2           = ObscureUrl.CalculateHashString(obscureKind, this.GuidIdentity);
            string originalString = base.Uri.OriginalString;
            string uriString      = originalString.Replace(this.GuidIdentity + str, this.GuidIdentity + str2);

            return(new ObscureUrl(new Uri(uriString, UriKind.Absolute), base.DataType, this.MailboxGuid, this.Domain, this.GuidIdentity, obscureKind, this.ReachUserSid));
        }
예제 #6
0
        public static ObscureUrl CreatePublishCalendarUrl(string externalUrl, Guid mailboxGuid, string domain)
        {
            Util.ThrowOnNullOrEmptyArgument(externalUrl, "externalUrl");
            Util.ThrowOnNullOrEmptyArgument(domain, "domain");
            SharingDataType calendar = SharingDataType.Calendar;
            int             num      = 1;
            string          text;
            string          text2;

            for (;;)
            {
                text  = Guid.NewGuid().ToString("N");
                text2 = ObscureUrl.CalculateHashString(ObscureKind.Restricted, text);
                if (!StringComparer.Ordinal.Equals(text2, ObscureUrl.CalculateHashString(ObscureKind.Normal, text)))
                {
                    goto IL_7D;
                }
                if (++num > 5)
                {
                    break;
                }
                ExTraceGlobals.SharingTracer.TraceDebug <string, int>(0L, "ObscureUrl.CreatePublishCalendarUrl(): Hash strings are identical for GUID {0} - Generating the GUID. Tried times = {1}.", text, num);
            }
            throw new TransientException(ServerStrings.ExTooManyObjects("ObscureUrl", num, 5));
IL_7D:
            string uriString = string.Format("{0}/{1}/{2}@{3}/{4}{5}/{6}", new object[]
            {
                externalUrl.TrimEnd(new char[]
                {
                    '/'
                }),
                calendar.ExternalName,
                mailboxGuid.ToString("N"),
                domain,
                text,
                text2,
                calendar.PublishResourceName
            });
            ObscureUrl obscureUrl = new ObscureUrl(new Uri(uriString, UriKind.Absolute), calendar, mailboxGuid, domain, text, ObscureKind.Restricted, null);

            ExTraceGlobals.SharingTracer.TraceDebug <ObscureUrl, string>(0L, "ObscureUrl.CreatePublishCalendarUrl(): Created an instance of ObscureUrl: {0} - {1}.", obscureUrl, obscureUrl.TraceInfo);
            return(obscureUrl);
        }
예제 #7
0
        public static PublishingUrl Create(string url)
        {
            Util.ThrowOnNullOrEmptyArgument(url, "url");
            ObscureUrl result = null;

            if (ObscureUrl.TryParse(url, out result))
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "PublishingUrl.Create(): Get ObscureUrl from url {0}.", url);
                return(result);
            }
            PublicUrl result2 = null;

            if (PublicUrl.TryParse(url, out result2))
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "PublishingUrl.Create(): Get PublicUrl from url {0}.", url);
                return(result2);
            }
            ExTraceGlobals.SharingTracer.TraceError <string>(0L, "PublishingUrl.Create(): Cannot parse url {0} for PublishingUrl", url);
            throw new ArgumentException("Url is not valid: " + url);
        }
예제 #8
0
 private static int GetHashCode(ObscureUrl url)
 {
     Util.ThrowOnNullArgument(url, "url");
     return((url.MailboxGuid.ToString() + url.Identity).GetHashCode());
 }
예제 #9
0
        internal static bool TryParse(string url, out ObscureUrl obscureUrl)
        {
            obscureUrl = null;
            if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                ExTraceGlobals.SharingTracer.TraceError <string>(0L, "ObscureUrl.TryParse(): The string '{0}' is not an Absolute Uri.", url);
                return(false);
            }
            Uri    uri       = new Uri(url, UriKind.Absolute);
            string localPath = uri.LocalPath;

            ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Get path of url: {0}", localPath);
            Match match = ObscureUrl.ObscureUrlRegex.Match(localPath);

            if (!match.Success)
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): The string '{0}' is not desired ObscureUrl. ", url);
                return(false);
            }
            SharingDataType sharingDataType = SharingDataType.FromPublishResourceName(match.Result("${datatype}"));
            Guid            guid            = Guid.Empty;
            Exception       ex = null;

            try
            {
                guid = new Guid(match.Result("${mailboxguid}"));
            }
            catch (FormatException ex2)
            {
                ex = ex2;
            }
            catch (OverflowException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string, Exception>(0L, "ObscureUrl.TryParse(): The string '{0}' is not desired ObscureUrl. Exception = {1}.", url, ex);
                return(false);
            }
            string             text = match.Result("${guid}");
            string             x    = match.Result("${hash}");
            SecurityIdentifier securityIdentifier = null;
            string             text2 = match.Result("${sid}");

            if (sharingDataType == SharingDataType.ReachCalendar)
            {
                if (!StringComparer.Ordinal.Equals(x, ObscureUrl.CalculateHashString(ObscureKind.Normal, text)))
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Incorrect hash value for reachUrl:'{0}'", url);
                    return(false);
                }
                if (string.IsNullOrEmpty(text2))
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): sid value missing for reachUrl:'{0}'", url);
                    return(false);
                }
                securityIdentifier = new SecurityIdentifier(text2);
                if (!ExternalUser.IsValidReachSid(securityIdentifier))
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Not a valid reach sid:'{0}'", url);
                    return(false);
                }
                obscureUrl = new ObscureUrl(uri, sharingDataType, guid, match.Result("${domain}"), text, ObscureKind.Normal, securityIdentifier);
                ExTraceGlobals.SharingTracer.TraceDebug <string, string>(0L, "ObscureUrl.TryParse(): The url {0} is parsed as ReachCalendar ObscureUrl {1}.", url, obscureUrl.TraceInfo);
                return(true);
            }
            else
            {
                if (sharingDataType != SharingDataType.Calendar)
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <SharingDataType>(0L, "ObscureUrl.TryParse(): Sharing Datatype:{0} is not supported ", sharingDataType);
                    return(false);
                }
                if (!string.IsNullOrEmpty(text2))
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): SID is not applicable for published calendar url:'{0}'", url);
                    return(false);
                }
                foreach (object obj in Enum.GetValues(typeof(ObscureKind)))
                {
                    ObscureKind obscureKind = (ObscureKind)obj;
                    if (StringComparer.Ordinal.Equals(x, ObscureUrl.CalculateHashString(obscureKind, text)))
                    {
                        obscureUrl = new ObscureUrl(uri, sharingDataType, guid, match.Result("${domain}"), text, obscureKind, securityIdentifier);
                        ExTraceGlobals.SharingTracer.TraceDebug <string, string>(0L, "ObscureUrl.TryParse(): The url {0} is parsed as Calendar ObscureUrl {1}.", url, obscureUrl.TraceInfo);
                        return(true);
                    }
                }
                ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Incorrect hash value for Calendar url:{0}", url);
                return(false);
            }
        }
예제 #10
0
 private ObscureUrl(Uri uri, SharingDataType dataType, Guid mailboxGuid, string domain, string guidIdentity, ObscureKind obscureKind, SecurityIdentifier reachUserSid) : base(uri, dataType, ObscureUrl.CalculateIdentity(dataType, guidIdentity))
 {
     Util.ThrowOnNullOrEmptyArgument(domain, "domain");
     Util.ThrowOnNullOrEmptyArgument(guidIdentity, "guidIdentity");
     this.ReachUserSid = reachUserSid;
     this.mailboxGuid  = mailboxGuid;
     this.domain       = domain;
     this.guidIdentity = guidIdentity;
     this.obscureKind  = obscureKind;
 }