private PermissionSet getPermissionSet(AGIScriptMappingElement scriptMapping)
        {
            PermissionSet permission = null;

            switch (scriptMapping.PermissionSet)
            {
            case ScriptPermissionSet.FullTrust:
                permission = PolicyLevel.CreateAppDomainLevel().GetNamedPermissionSet("FullTrust");
                break;

            case ScriptPermissionSet.Internet:
                permission = PolicyLevel.CreateAppDomainLevel().GetNamedPermissionSet("Internet");
                break;

            case ScriptPermissionSet.Intranet:
                permission = PolicyLevel.CreateAppDomainLevel().GetNamedPermissionSet("Intranet");
                break;

            case ScriptPermissionSet.Host:
                permission = AppDomain.CurrentDomain.ApplicationTrust.DefaultGrantSet.PermissionSet;
                break;

            case ScriptPermissionSet.Custom:
                permission = new PermissionSet(PermissionState.None);
                permission.FromXml(scriptMapping.CustomPermissionSet.SecurityElement);
                break;
            }

            return(permission);
        }
示例#2
0
        public static Dictionary <string, string> GetConfigurationSource()
        {
            if (_scriptMappings == null)
            {
                _scriptMappings = new Dictionary <string, string>();

                for (int i = 0; i < AGIScriptHostConfiguration.AGIScriptMappings.Count; i++)
                {
                    AGIScriptMappingElement scriptMapping = AGIScriptHostConfiguration.AGIScriptMappings[i];

                    _scriptMappings.Add(scriptMapping.Name, scriptMapping.ScriptManagerName);
                }
            }

            //Return a copy of the mappings
            return(new Dictionary <string, string>(_scriptMappings));
        }
        private AddInSecurityLevel getAddinSecurityLevel(AGIScriptMappingElement scriptMapping)
        {
            switch (scriptMapping.PermissionSet)
            {
            case ScriptPermissionSet.FullTrust:
                return(AddInSecurityLevel.FullTrust);

            case ScriptPermissionSet.Internet:
                return(AddInSecurityLevel.Internet);

            case ScriptPermissionSet.Intranet:
                return(AddInSecurityLevel.Intranet);

            case ScriptPermissionSet.Host:
                return(AddInSecurityLevel.Host);
            }

            return(AddInSecurityLevel.Internet);
        }
        private IRemoteScriptManager getRequestToken(AGIRequestInfo requestInfo)
        {
            Uri uri = new Uri(requestInfo.Request);

            IRemoteScriptManager manager = null;

            if (_scriptMappings.ContainsKey(uri.AbsolutePath))
            {
                AGIScriptMappingElement scriptMapping = ScriptHostRuntime.AGIScriptHostConfiguration.AGIScriptMappings[uri.AbsolutePath];

                AddInToken remoteManagerToken = getRemoteScriptManagerToken(scriptMapping.ScriptManagerName);

                AppDomain targetDomain = AppDomain.CurrentDomain;

                if (scriptMapping.IsolationMode == ScriptIsolationMode.AppDomain)
                {
                    PermissionSet grantPermissionSet = getPermissionSet(scriptMapping);

                    AppDomainSetup setup = new AppDomainSetup();
                    setup.ShadowCopyFiles = "true";
                    setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;

                    targetDomain = AppDomain.CreateDomain(uri.AbsolutePath, null, setup, grantPermissionSet);
                    manager      = remoteManagerToken.Activate <IRemoteScriptManager>(targetDomain);
                }
                else if (scriptMapping.IsolationMode == ScriptIsolationMode.Process)
                {
                    manager = remoteManagerToken.Activate <IRemoteScriptManager>(new AddInProcess(), getPermissionSet(scriptMapping));
                }
                else
                {
                    manager = remoteManagerToken.Activate <IRemoteScriptManager>(targetDomain);
                }
            }

            return(manager);
        }