Beispiel #1
0
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="app">An HttpApplication that provides access to the methods,
        /// properties, and events common to all application objects within an ASP.NET
        /// application </param>
        public void Init(HttpApplication app)
        {
            // Register for the interesting events in the HTTP life-cycle.
            app.BeginRequest        += new EventHandler(OnBeginRequest);
            app.AuthenticateRequest += new EventHandler(OnAuthenticateRequest);
            app.AcquireRequestState += new EventHandler(OnAcquireRequestState);

            // Get the application settings from the Simias.config.
            string setting = Store.Config.Get("Authentication", "SimiasRequireSSL");

            if (setting != null)
            {
                if (String.Compare(setting, "no", true) == 0)
                {
                    sslRequired = false;
                }
            }

            // Get the ssl port setting.
            setting = Store.Config.Get("Authentication", "SimiasSSLPort");
            if (setting != null)
            {
                sslPort = Convert.ToInt32(setting);
            }

            // Get the services that do not need authentication.
            setting = Store.Config.Get("Authentication", "SimiasAuthNotRequired");
            if (setting != null)
            {
                ParseAuthNotRequiredServices(setting);
            }

            // Get all the addresses that this host is known by.
            string[] addresses = MyDns.GetHostAddresses();
            foreach (string s in addresses)
            {
                localAddresses[s.ToLower()] = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Construct a Host domain.
        /// </summary>
        /// <param name="domain">The enterprise domain.</param>
        public HostProvider(Domain domain)
        {
            hostDomain = domain;

            // Check if this is the master server.
            bool master = (hostDomain.Role == SyncRoles.Master) ? true : false;

            // Get the HostDomain
            // If the HostNode does not exist create it.
            lock (typeof(HostProvider))
            {
                // Check if the host node exists.
                string hName = Store.Config.Get(ServerSection, ServerNameKey);

                // Make sure a master host can run without any pre-configured settings
                // so if the public address wasn't configured get a non-loopback local
                // address and configure the public address with it.
                string publicAddress = Store.Config.Get(ServerSection, PublicAddressKey);
                if (publicAddress == null || publicAddress == String.Empty)
                {
                    // Get the first non-localhost address
                    string[] addresses = MyDns.GetHostAddresses();
                    foreach (string addr in addresses)
                    {
                        if (IPAddress.IsLoopback(IPAddress.Parse(addr)) == false)
                        {
                            publicAddress = addr;
                            break;
                        }
                    }
                }

                string privateAddress = Store.Config.Get(ServerSection, PrivateAddressKey);
                if (privateAddress == null || privateAddress == String.Empty)
                {
                    if (publicAddress != null)
                    {
                        privateAddress = publicAddress;
                    }
                }

                string masterAddress = Store.Config.Get(ServerSection, MasterAddressKey);
                Member mNode         = hostDomain.GetMemberByName(hName);
                host = (mNode == null) ? null : new HostNode(mNode);
                if (host == null)
                {
                    Console.Error.WriteLine("Checking if the host node exists.");
                    HostNode hn = HostNode.GetLocalHost();
                    if (hn == null)
                    {
                        Console.Error.WriteLine("Host node is null.");
                    }
                    else
                    {
                        Console.Error.WriteLine("Host node ID is: {0} and public url is: {1}", hn.ID, hn.PublicUrl);
                    }
                    host = hn;
                }

                if (host == null)
                {
                    Console.Error.WriteLine("Host node is null. Creating the host node.");
                    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                    if (master == true)
                    {
                        host              = new HostNode(hName, System.Guid.NewGuid().ToString(), publicAddress, privateAddress, rsa);
                        host.Rights       = Simias.Storage.Access.Rights.Admin;
                        host.IsMasterHost = true;
                    }
                    else
                    {
                        host       = SlaveSetup.GetHost(Store.StorePath);
                        host.Proxy = true;
                        rsa        = SlaveSetup.GetKeys(Store.StorePath);
                        // TODO remove
                        Property p = new Property(PropertyTags.HostAddress, new Uri(masterAddress));
                        p.LocalProperty = true;
                        hostDomain.Properties.AddNodeProperty(p);
                        // END TODO
                    }

                    host.IsLocalHost = true;
                    hostDomain.Commit(new Node[] { hostDomain, host });

                    // Now Associate this host with the local identity.
                    store.AddDomainIdentity(hostDomain.ID, host.UserID, rsa.ToXmlString(true), Simias.Storage.CredentialType.PPK);
                    SlaveSetup.DeleteTempSetupFiles(Store.StorePath);
                }
                else
                {
                    Console.Error.WriteLine("Host is not null. Updating the host node.");
                    if (host.IsMasterHost == true)
                    {
                        // Make sure the address has not changed.
                        bool hostChanged = false;
                        if (host.PublicUrl != publicAddress)
                        {
                            host.PublicUrl = publicAddress;
                            hostChanged    = true;
                        }
                        if (host.PrivateUrl != privateAddress)
                        {
                            host.PrivateUrl = privateAddress;
                            hostChanged     = true;
                        }

                        if (hostChanged == true)
                        {
                            hostDomain.Commit(host);
                        }
                    }
                }
            }

            if (master == true)
            {
                // Register the ProvisionUser Provider.
                ProvisionService.RegisterProvider(new LoadBalanceProvisionUserProvider());
                //ProvisionService.RegisterProvider( new MasterHostProvisionProvider() );
            }
            else
            {
                // Now start the sync process for the domain.
                Thread syncThread = new Thread(new ThreadStart(SyncDomain));
                syncThread.IsBackground = true;
                syncThread.Name         = "Domain Sync Thread";
                syncThread.Start();
            }
        }