コード例 #1
0
        /// <summary>
        /// Checks the user privilege.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <returns></returns>
        public string CheckUserPrivilege(string username, IStatisticsCollection statCollection)
        {
            bool   isAuthenticated = false;
            bool   isAdmin         = false;
            string AdminUsers      = string.Empty;

            try
            {
                logger.Debug("ConfigConnectionManager : CheckUserPrivilege Method: Entry");

                CfgAccessGroupQuery queryAccessGroup = null;
                CfgAccessGroup      accessGroup      = null;
                CfgPersonQuery      queryPerson      = null;
                CfgPerson           Person           = null;

                if (statCollection.ApplicationContainer.UserGroupName != null && !isAdmin)
                {
                    queryAccessGroup      = new CfgAccessGroupQuery();
                    queryAccessGroup.Name = statCollection.ApplicationContainer.UserGroupName;
                    accessGroup           = StatisticsSetting.GetInstance().confObject.RetrieveObject <CfgAccessGroup>(queryAccessGroup);

                    queryPerson          = new CfgPersonQuery();
                    queryPerson.UserName = username;
                    Person = StatisticsSetting.GetInstance().confObject.RetrieveObject <CfgPerson>(queryPerson);

                    if (accessGroup != null)
                    {
                        foreach (CfgID memberID in accessGroup.MemberIDs)
                        {
                            int id = memberID.DBID;
                            if (memberID.Type == CfgObjectType.CFGPerson)
                            {
                                if (id == Person.DBID)
                                {
                                    isAuthenticated = true;
                                    StatisticsSetting.GetInstance().isAdmin = false;
                                }
                            }
                        }
                    }

                    queryPerson = new CfgPersonQuery();
                    ICollection <CfgPerson> Persons = StatisticsSetting.GetInstance().confObject.RetrieveMultipleObjects <CfgPerson>(queryPerson);

                    if (Persons != null)
                    {
                        foreach (CfgPerson agent in Persons)
                        {
                            if (accessGroup != null)
                            {
                                foreach (CfgID memberID in accessGroup.MemberIDs)
                                {
                                    int id = memberID.DBID;
                                    if (memberID.Type == CfgObjectType.CFGPerson)
                                    {
                                        if (id == agent.DBID)
                                        {
                                            StatisticsSetting.GetInstance().LstAgentUNames.Add(agent.UserName);
                                            StatisticsSetting.GetInstance().LstPersons.Add(agent);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (statCollection.AdminValues.AdminUsers.Count != 0)
                {
                    if (statCollection.AdminValues.AdminUsers.Contains(username))
                    {
                        isAdmin = true;
                        StatisticsSetting.GetInstance().isAdmin = true;
                    }
                }
            }
            catch (Exception generalException)
            {
                logger.Error("ConfigConnectionManager : CheckUserPrivilege Method: " + generalException.Message.ToString());
            }
            finally
            {
                logger.Debug("ConfigConnectionManager : CheckUserPrevilege Method: Exit");
                GC.Collect();
            }
            return(isAuthenticated.ToString() + "," + isAdmin.ToString());
        }
コード例 #2
0
        private void confserv()
        {
            try
            {
                IAgent agent = container.Resolve <IAgent>();
                #region ADDP settings
                PropertyConfiguration config = new PropertyConfiguration();
                config.UseAddp           = true;
                config.AddpServerTimeout = 30;
                config.AddpClientTimeout = 90;
                //config.AddpTrace = "both";
                config.AddpTraceMode = AddpTraceMode.Both;
                #endregion
                Endpoint           endpoint     = new Endpoint("10.220.57.1", 2020);
                ConfServerProtocol confProtocol = new ConfServerProtocol(endpoint);
                confProtocol.ClientApplicationType = (int)CfgAppType.CFGSCE;
                confProtocol.ClientName            = "default";
                confProtocol.UserName     = agent.UserName;
                confProtocol.UserPassword = agent.Password;
                try
                {
                    confProtocol.BeginOpen();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                IConfService confservice = (ConfService)ConfServiceFactory.CreateConfService(confProtocol);

                CfgPersonQuery query = new CfgPersonQuery();
                query.UserName = agent.UserName;
                CfgPerson person = confservice.RetrieveObject <CfgPerson>(query);
                //MessageBox.Show(person.ToString());
                CfgAccessGroupQuery querys = new CfgAccessGroupQuery();
                querys.PersonDbid = person.DBID;
                querys.TenantDbid = 101;
                ICollection <CfgAccessGroup> accessGroups = confservice.RetrieveMultipleObjects <CfgAccessGroup>(querys);
                foreach (CfgAccessGroup accessGroup in accessGroups)
                {
                    agentProfile = accessGroup.GroupInfo.Name.ToString();
                    MessageBox.Show(agentProfile);

                    if (agentProfile.Equals("Azf_Nar"))
                    {
                        agentProfile = "Azf_Nar";
                        MessageBox.Show(agentProfile);
                        break;
                    }
                    else if (agentProfile.Equals("Azf_Fixed"))
                    {
                        agentProfile = "Azf_Fixed";
                        MessageBox.Show(agentProfile);
                        break;
                    }
                    else if (agentProfile.Equals("Backcell"))
                    {
                        agentProfile = "Backcell";
                        MessageBox.Show(agentProfile);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }