internal static string GetErrorText()
 {
     if (s_errMsg == null)
     {
         lock (s_Lock)
         {
             if (s_errMsg != null)
             {
                 return s_errMsg;
             }
             s_errMsg = new AuthStoreErrorFormatter().GetErrorMessage();
         }
     }
     return s_errMsg;
 }
Esempio n. 2
0
        internal static String GetErrorText()
        {
            if (s_errMsg != null)
            {
                return(s_errMsg);
            }

            lock ( s_Lock )
            {
                if (s_errMsg != null)
                {
                    return(s_errMsg);
                }

                AuthStoreErrorFormatter errFormatter = new AuthStoreErrorFormatter();

                s_errMsg = errFormatter.GetErrorMessage();
            }

            return(s_errMsg);
        }
 private void InitApp()
 {
     try
     {
         using (new ApplicationImpersonationContext())
         {
             if (this._InitAppDone)
             {
                 if (DateTime.Now > this._LastUpdateCacheDate.AddMinutes((double)this.CacheRefreshInterval))
                 {
                     this._LastUpdateCacheDate = DateTime.Now;
                     this.CallMethod(this._ObjAzAuthorizationStoreClass, "UpdateCache", null);
                 }
             }
             else
             {
                 lock (this)
                 {
                     if (!this._InitAppDone)
                     {
                         if (this._ConnectionString.ToLower(CultureInfo.InvariantCulture).StartsWith("msxml://", StringComparison.Ordinal))
                         {
                             if (this._ConnectionString.Contains("/~/"))
                             {
                                 string newValue = null;
                                 if (HostingEnvironment.IsHosted)
                                 {
                                     newValue = HttpRuntime.AppDomainAppPath;
                                 }
                                 else
                                 {
                                     Process       currentProcess = Process.GetCurrentProcess();
                                     ProcessModule module         = (currentProcess != null) ? currentProcess.MainModule : null;
                                     string        str2           = (module != null) ? module.FileName : null;
                                     if (str2 != null)
                                     {
                                         newValue = Path.GetDirectoryName(str2);
                                     }
                                     if ((newValue == null) || (newValue.Length < 1))
                                     {
                                         newValue = Environment.CurrentDirectory;
                                     }
                                 }
                                 newValue = newValue.Replace('\\', '/');
                                 this._ConnectionString = this._ConnectionString.Replace("~", newValue);
                             }
                             string path = this._ConnectionString.Substring("msxml://".Length).Replace('/', '\\');
                             if (HostingEnvironment.IsHosted)
                             {
                                 HttpRuntime.CheckFilePermission(path, false);
                             }
                             if (!System.Web.Util.FileUtil.FileExists(path))
                             {
                                 throw new FileNotFoundException(System.Web.SR.GetString("AuthStore_policy_file_not_found", new object[] { HttpRuntime.GetSafePath(path) }));
                             }
                             this._XmlFileName = path;
                         }
                         Type type = null;
                         try
                         {
                             this._NewAuthInterface = true;
                             type = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", false);
                             if (type == null)
                             {
                                 type = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", false);
                             }
                             if (type == null)
                             {
                                 this._NewAuthInterface = false;
                                 type = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", true);
                             }
                         }
                         catch (FileNotFoundException exception)
                         {
                             HttpContext current = HttpContext.Current;
                             if (current == null)
                             {
                                 throw new ProviderException(System.Web.SR.GetString("AuthStoreNotInstalled_Title"), exception);
                             }
                             current.Response.Clear();
                             current.Response.StatusCode = 500;
                             current.Response.Write(AuthStoreErrorFormatter.GetErrorText());
                             current.Response.End();
                         }
                         if (HostingEnvironment.IsHosted && (this._XmlFileName != null))
                         {
                             InternalSecurityPermissions.Unrestricted.Assert();
                         }
                         this._ObjAzAuthorizationStoreClass = Activator.CreateInstance(type);
                         object[] objArray3 = new object[3];
                         objArray3[0] = 0;
                         objArray3[1] = this._ConnectionString;
                         object[] args = objArray3;
                         this.CallMethod(this._ObjAzAuthorizationStoreClass, "Initialize", args);
                         args = new object[] { this._AppName, null };
                         if (this._NewAuthInterface)
                         {
                             this._ObjAzApplication = this.CallMethod(this._ObjAzAuthorizationStoreClass, "OpenApplication2", args);
                         }
                         else
                         {
                             this._ObjAzApplication = this.CallMethod(this._ObjAzAuthorizationStoreClass, "OpenApplication", args);
                         }
                         if (this._ObjAzApplication == null)
                         {
                             throw new ProviderException(System.Web.SR.GetString("AuthStore_Application_not_found"));
                         }
                         this._ObjAzScope = null;
                         if (!string.IsNullOrEmpty(this._ScopeName))
                         {
                             args[0]          = this._ScopeName;
                             args[1]          = null;
                             this._ObjAzScope = this.CallMethod(this._ObjAzApplication, "OpenScope", args);
                             if (this._ObjAzScope == null)
                             {
                                 throw new ProviderException(System.Web.SR.GetString("AuthStore_Scope_not_found"));
                             }
                         }
                         this._LastUpdateCacheDate = DateTime.Now;
                         this._InitAppDone         = true;
                     }
                 }
             }
         }
     }
     catch
     {
         throw;
     }
 }
        internal static String GetErrorText()
        {
            if( s_errMsg != null )
            {
                return s_errMsg;
            }

            lock( s_Lock )
            {
                if( s_errMsg != null )
                {
                    return s_errMsg;
                }

                AuthStoreErrorFormatter errFormatter = new AuthStoreErrorFormatter();

                s_errMsg = errFormatter.GetErrorMessage();
            }

            return s_errMsg;
        }
Esempio n. 5
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        private void InitApp()
        {
            try {
                using (new ApplicationImpersonationContext()) {
                    if (_InitAppDone)
                    {
                        if (DateTime.Now > _LastUpdateCacheDate.AddMinutes(CacheRefreshInterval))
                        {
                            _LastUpdateCacheDate = DateTime.Now;
                            CallMethod(_ObjAzAuthorizationStoreClass, "UpdateCache", null);
                        }
                        return;
                    }
                    lock (this) {
                        if (_InitAppDone)
                        {
                            return;
                        }
                        if (_ConnectionString.ToLower(CultureInfo.InvariantCulture).StartsWith("msxml://", StringComparison.Ordinal))
                        {
                            if (_ConnectionString.Contains("/~/"))
                            {
                                string appPath = null;
                                if (HostingEnvironment.IsHosted)
                                {
                                    appPath = HttpRuntime.AppDomainAppPath;
                                }
                                else
                                {
    #if !FEATURE_PAL // FEATURE_PAL does not enable the ProcessModule class
                                    Process       p       = Process.GetCurrentProcess();
                                    ProcessModule pm      = (p != null ? p.MainModule : null);
                                    string        exeName = (pm != null ? pm.FileName : null);
                                    if (exeName != null)
                                    {
                                        appPath = System.IO.Path.GetDirectoryName(exeName);
                                    }
    #endif // !FEATURE_PAL
                                    if (appPath == null || appPath.Length < 1)
                                    {
                                        appPath = Environment.CurrentDirectory;
                                    }
                                }
                                appPath           = appPath.Replace('\\', '/');
                                _ConnectionString = _ConnectionString.Replace("~", appPath);
                            }
                            string fileName = _ConnectionString.Substring("msxml://".Length).Replace('/', '\\');

                            if (HostingEnvironment.IsHosted)
                            {
                                HttpRuntime.CheckFilePermission(fileName, false);
                            }

                            if (!FileUtil.FileExists(fileName))
                            {
                                throw new FileNotFoundException(SR.GetString(SR.AuthStore_policy_file_not_found,
                                                                             HttpRuntime.GetSafePath(fileName)));
                            }

                            _XmlFileName = fileName;
                        }

                        Type typeAzAuthorizationStoreClass = null;
                        try {
                            _NewAuthInterface             = true;
                            typeAzAuthorizationStoreClass = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                                                                         false /*throwOnError*/);
                            if (typeAzAuthorizationStoreClass == null)
                            {
                                typeAzAuthorizationStoreClass = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                                                                             false /*throwOnError*/);
                            }
                            if (typeAzAuthorizationStoreClass == null)
                            {
                                _NewAuthInterface             = false;
                                typeAzAuthorizationStoreClass = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                                                                             true /*throwOnError*/);
                            }
                        }
                        catch (FileNotFoundException e) {
                            HttpContext context = HttpContext.Current;
                            if (context == null)
                            {
                                throw new ProviderException(SR.GetString(SR.AuthStoreNotInstalled_Title), e);
                            }

                            context.Response.Clear();
                            context.Response.StatusCode = 500;
                            context.Response.Write(AuthStoreErrorFormatter.GetErrorText());
                            context.Response.End();
                        }

                        if (HostingEnvironment.IsHosted && _XmlFileName != null)
                        {
                            InternalSecurityPermissions.Unrestricted.Assert();
                        }

                        _ObjAzAuthorizationStoreClass = Activator.CreateInstance(typeAzAuthorizationStoreClass);
                        object[] args = new object[] { 0, _ConnectionString, null };

                        CallMethod(_ObjAzAuthorizationStoreClass, "Initialize", args);

                        args    = new object[2];
                        args[0] = _AppName;
                        args[1] = null;
                        if (_NewAuthInterface)
                        {
                            _ObjAzApplication = CallMethod(_ObjAzAuthorizationStoreClass, "OpenApplication2", args);
                        }
                        else
                        {
                            _ObjAzApplication = CallMethod(_ObjAzAuthorizationStoreClass, "OpenApplication", args);
                        }
                        if (_ObjAzApplication == null)
                        {
                            throw new ProviderException(SR.GetString(SR.AuthStore_Application_not_found));
                        }
                        _ObjAzScope = null;
                        if (!string.IsNullOrEmpty(_ScopeName))
                        {
                            args[0]     = _ScopeName;
                            args[1]     = null;
                            _ObjAzScope = CallMethod(_ObjAzApplication, "OpenScope", args);
                            if (_ObjAzScope == null)
                            {
                                throw new ProviderException(SR.GetString(SR.AuthStore_Scope_not_found));
                            }
                        }
                        _LastUpdateCacheDate = DateTime.Now;
                        _InitAppDone         = true;
                    }
                }
            } catch {
                throw;
            }
        }