Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
            }
        }