Пример #1
0
        protected override void BeginProcessing()
        {
            RemoteConfigurationManager remoteSession = new RemoteConfigurationManager();

            remoteSession.Initilize(MiscUtil.CLUSTERED, Server, Port, new ClientConfigurationFormatter(), ConfigurationConnection.Current.ClientCredential);
            IList <IUser> loginList   = remoteSession.GetLogins();
            string        currentUser = ConfigurationConnection.Current.ClientCredential.UserName;

            if (!string.IsNullOrEmpty(ConfigurationConnection.Current.ClientCredential.UserName) && !UserExist(loginList, ConfigurationConnection.Current.ClientCredential.UserName))
            {
                try
                {
                    SafeTokenHandle tokenHandle;
                    bool            isLogon = SSPIUtility.LogonUser(Username, Password, out tokenHandle);
                    if (isLogon)
                    {
                        using (WindowsIdentity.Impersonate(tokenHandle.DangerousGetHandle()))
                        {
                            remoteSession = new RemoteConfigurationManager();
                            remoteSession.Initilize(MiscUtil.CLUSTERED, Server, Port, new ClientConfigurationFormatter(), ConfigurationConnection.Current.ClientCredential);
                            IUser user;
                            user = new User(currentUser);

                            try
                            {
                                if (remoteSession.CreateUser(user))
                                {
                                    remoteSession.Grant(true, new ResourceId()
                                    {
                                        Name = Alachisoft.NosDB.Common.MiscUtil.NOSDB_CLUSTER_SERVER, ResourceType = Alachisoft.NosDB.Common.Security.Impl.Enums.ResourceType.System
                                    }, user.Username, ServerRole.sysadmin.ToString());
                                }
                            }
                            catch (SecurityException exc)
                            {
                                if (exc.ErrorCode.Equals(ErrorCodes.Security.USER_ALREADY_EXIST))
                                {
                                    remoteSession.Grant(true, new ResourceId()
                                    {
                                        Name = Alachisoft.NosDB.Common.MiscUtil.NOSDB_CLUSTER_SERVER, ResourceType = Alachisoft.NosDB.Common.Security.Impl.Enums.ResourceType.System
                                    }, user.Username, ServerRole.sysadmin.ToString());
                                }
                            }
                        }
                        tokenHandle.Release();
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Пример #2
0
        protected override void BeginProcessing()
        {
            if (string.IsNullOrEmpty(Server))
            {
                Server = ProviderUtil.GetLocalAddress();
            }

            var rcm = new RemoteConfigurationManager();

            rcm.Initilize(StandAlone?MiscUtil.LOCAL:MiscUtil.CLUSTERED, Server, Port, new ConfigurationChannelFormatter(), new SSPIClientAuthenticationCredential());

            if (!_standAlone)
            {
                if (rcm.VerifyConfigurationCluster())
                {
                    ConfigurationConnection.ConfigCluster        = rcm.GetConfigurationClusterConfiguration();
                    ConfigurationConnection.ClusterConfiguration = rcm.GetDatabaseClusterConfig(true);
                    ConfigurationConnection.Current = rcm;
                    ConfigurationConnection.UpdateDatabaseClusterInfo();
                }
                else
                {
                    throw new Exception("Database cluster does not exist on the specified server.");
                }
            }
            else
            {
                var localConfig = rcm.GetDatabaseClusterConfig(false);
                if (localConfig != null)
                {
                    var configCluster = new ConfigServerConfiguration
                    {
                        Name    = MiscUtil.STAND_ALONE,
                        Port    = Port,
                        Servers = new ServerNodes()
                    };
                    configCluster.Servers.AddNode(new ServerNode {
                        Name = Server, Priority = 1
                    });
                    ConfigurationConnection.ConfigCluster        = configCluster;
                    ConfigurationConnection.ClusterConfiguration = localConfig;
                    ConfigurationConnection.Current = rcm;
                    ConfigurationConnection.UpdateClusterConfiguration();
                    ConfigurationConnection.UpdateDatabaseClusterInfo();
                }
                else
                {
                    throw new Exception("Standalone database does not exist on the specified server.");
                }
            }
        }
Пример #3
0
        private static RemoteConfigurationManager InitializeRemoteConfigurationManager(ManagementInfo managementInfo)
        {
            if (managementInfo.ConfigServerIp == null)
            {
                managementInfo.ConfigServerIp = NetworkUtil.GetLocalIPAddress().ToString();
            }

            if (managementInfo.ConfigServerPort == 0)
            {
                managementInfo.ConfigServerPort = NetworkUtil.DEFAULT_CS_HOST_PORT;
            }

            IClientAuthenticationCredential clientAuthenticationCredential = new SSPIClientAuthenticationCredential();

            var remoteConfigurationManager = new RemoteConfigurationManager();

            remoteConfigurationManager.Initilize(MiscUtil.CLUSTERED, managementInfo.ConfigServerIp, managementInfo.ConfigServerPort, new ConfigurationChannelFormatter(), clientAuthenticationCredential);

            return(remoteConfigurationManager);
        }
Пример #4
0
        private static void VerifyPrimeryNode()
        {
            if (_configClusterInfo == null)
            {
                throw new Exception("Kindly connect database cluster to continue");
            }
            if (ConfigCluster.Name.Equals(MiscUtil.CLUSTERED) || ConfigCluster.Name.Equals("standalone", StringComparison.InvariantCultureIgnoreCase))
            {
                if (activeRcm != null)
                {
                    if (ConfigCluster.Name.Equals("standalone", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return;
                    }

                    try
                    {
                        if (activeRcm.VerifyConfigurationClusterPrimery(_configClusterInfo.Name))
                        {
                            return;
                        }
                    }
                    catch
                    {
                    }
                }
                if (activeRcm == null)
                {
                    activeRcm = new RemoteConfigurationManager();
                }
                try
                {
                    if (!activeRcm.IsInitialised)
                    {
                        var configServer = ConfigCluster.Servers.Nodes.First(p => p.Value.Priority == 1);
                        ActiveConfigServerIp = configServer.Value.Name;
                        activeRcm.Initilize(ConfigCluster.Name, configServer.Value.Name, _configClusterInfo.Port, new ConfigurationChannelFormatter(), new SSPIClientAuthenticationCredential());
                    }
                    if (activeRcm.VerifyConfigurationClusterPrimery(_configClusterInfo.Name))
                    {
                        return;
                    }
                    activeRcm.Dispose();
                }
                catch
                {
                    try
                    {
                        var configServer = ConfigCluster.Servers.Nodes.First(p => p.Value.Priority == 2);
                        ActiveConfigServerIp = configServer.Value.Name;
                        activeRcm.Initilize(ConfigCluster.Name, configServer.Value.Name, _configClusterInfo.Port, new ConfigurationChannelFormatter(), new SSPIClientAuthenticationCredential());
                        if (activeRcm.VerifyConfigurationClusterPrimery(_configClusterInfo.Name))
                        {
                            return;
                        }
                        activeRcm.Dispose();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            throw new Exception("Cann't connect to any of the servers in database cluster ");
        }