private Domain CreateEnterpriseDomain() { Domain domain = new Domain( store, "iFolder Test Domain", NewID, "iFolder Enterprise Test Domain", SyncRoles.Master, Domain.ConfigurationType.ClientServer); domain.SetType(domain, "Enterprise"); Identity identity = store.CurrentUser; Member owner = new Member(identity.Name, identity.ID, Access.Rights.Admin); owner.IsOwner = true; domain.Commit(new Node[] { domain, owner }); store.AddDomainIdentity(domain.ID, owner.UserID, null, CredentialType.None); LocalDatabase ldb = store.GetDatabaseObject(); ldb.DefaultDomain = domain.ID; return(domain); }
/// <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(); } }
/// <summary> /// Method to get the Simias Enterprise server domain /// If the the domain does not exist and the create flag is true /// the domain will be created. If create == false, ownerName is ignored /// </summary> internal Simias.Storage.Domain GetServerDomain(bool Create) { // Check if the Server domain exists in the store Simias.Storage.Domain enterpriseDomain = null; bool master = true; try { Collection collection = store.GetSingleCollectionByType("Enterprise"); if (collection != null) { enterpriseDomain = store.GetDomain(collection.ID); if (enterpriseDomain != null) { this.domainName = enterpriseDomain.Name; this.id = enterpriseDomain.ID; // For backwards compatibility, if the report collection does not // exist because the store was created with a previous version of // simias, check and create it here. // Don't create this directory on a slave server. //TODO : Check with migration !! Report.CreateReportCollection(store, enterpriseDomain); } } if (enterpriseDomain == null && Create == true) { // Bootstrap the domain from the Simias.config file Simias.Configuration config = Store.Config; string cfgValue = config.Get("EnterpriseDomain", "SystemName"); if (cfgValue != null && cfgValue != String.Empty) { this.domainName = cfgValue; } cfgValue = config.Get("EnterpriseDomain", "Description"); if (cfgValue != null && cfgValue != String.Empty) { this.description = cfgValue; } cfgValue = config.Get("EnterpriseDomain", "AdminName"); if (cfgValue != null && cfgValue != String.Empty) { this.admin = cfgValue; } cfgValue = config.Get("Server", "MasterAddress"); if (cfgValue != null && cfgValue != String.Empty) { master = false; } /* * cfgValue = config.Get( "EnterpriseDomain", "AdminPassword" ); * if ( cfgValue != null && cfgValue != "" ) * { * this.adminPassword = cfgValue; * } */ if (master == true) { cfgValue = config.Get("EnterpriseDomain", "DomainID"); if (cfgValue != null && cfgValue != String.Empty) { this.id = cfgValue; } else { this.id = Guid.NewGuid().ToString(); } // Create the enterprise server domain. enterpriseDomain = new Simias.Storage.Domain( store, this.domainName, this.id, this.description, Simias.Sync.SyncRoles.Master, Simias.Storage.Domain.ConfigurationType.ClientServer); // This needs to be added to allow the enterprise location provider // to be able to resolve this domain. enterpriseDomain.SetType(enterpriseDomain, "Enterprise"); // Create the owner member for the domain. string provider = null; cfgValue = config.Get("Identity", "Assembly"); if (cfgValue != null && cfgValue != String.Empty) { provider = cfgValue; } this.admin = ParseUserName(this.admin, provider); Member member = new Member(this.admin, Guid.NewGuid().ToString(), Access.Rights.Admin); member.IsOwner = true; enterpriseDomain.SetType(member as Node, "User"); // Marker so we know this member was created internally // and not through an external identity sync. enterpriseDomain.SetType(member as Node, "Internal"); enterpriseDomain.Commit(new Node[] { enterpriseDomain, member }); // Set the domain default store.DefaultDomain = enterpriseDomain.ID; // Create the name mapping. store.AddDomainIdentity(enterpriseDomain.ID, member.UserID); } else { // Slave host so create the proxy domain and owner. enterpriseDomain = Simias.Host.SlaveSetup.GetDomain(Store.StorePath); store.DefaultDomain = enterpriseDomain.ID; enterpriseDomain.Role = Simias.Sync.SyncRoles.Slave; Member owner = Simias.Host.SlaveSetup.GetOwner(Store.StorePath); enterpriseDomain.SetType(enterpriseDomain, "Enterprise"); enterpriseDomain.Proxy = true; owner.Proxy = true; enterpriseDomain.Commit(new Node[] { enterpriseDomain, owner }); } Report.CreateReportCollection(store, enterpriseDomain); } } catch (Exception gssd) { log.Error(gssd.Message); log.Error(gssd.StackTrace); } return(enterpriseDomain); }