//-------------------------------------------

        protected virtual void savePermissions()
        {
            StringBuilder sb = new StringBuilder();

            // 默认使用 SiteRole
            IList roles = GetRoles();

            foreach (IRole role in roles)
            {
                IList roleActions = GetActionsByRole(role);

                //SecurityString ss = new SecurityString( role.TypeFullName, role.TypeId, roleActions );
                SecurityString ss = new SecurityString(role.Role.GetType().FullName, role.Role.Id, roleActions);

                sb.Append(ss.ToString());
                sb.Append(SecurityString.roleSeperator);
            }

            _securityString = sb.ToString();
            if (strUtil.HasText(_securityString))
            {
                _securityString = _securityString.TrimEnd(SecurityString.roleSeperator);
            }
            _objSecurity.Security = _securityString;

            _objSecurity.update();
        }
        //-------------------------------------------

        public virtual void SaveActionAll(string[] actionIds)
        {
            Hashtable results = new Hashtable();

            foreach (String actionId in actionIds)
            {
                string[] arrItem = actionId.Split('_');
                if (arrItem.Length != 3)
                {
                    continue;
                }

                String typeFullName = arrItem[0];
                int    roleId       = cvt.ToInt(arrItem[1]);
                int    aid          = cvt.ToInt(arrItem[2]);
                if (roleId < 0 || aid <= 0)
                {
                    continue;
                }
                if (Entity.GetType(typeFullName) == null)
                {
                    continue;
                }

                String rkey = SecurityString.GetRoleKey(typeFullName, roleId);
                addActionToRole(results, rkey, aid);
            }

            _roleActionsAll = results;

            savePermissions();
        }
 public IList GetActionsByRole(IRole role)
 {
     if (role == null)
     {
         return(new ArrayList());
     }
     return(getActionsByKey(SecurityString.GetRoleKey(role.Role.GetType().FullName, role.Role.Id)));
 }
Exemple #4
0
        private bool VerificaLogin()
        {
            Boolean result = false;

            try
            {
                SecurityString SecurityS    = new SecurityString();
                string         SENHAUSUARIO = SecurityS.encrypt(txtSenha.Text);

                USUARIOProvider USUARIOP = new USUARIOProvider();

                RowsFiltroCollection RowRelatorio = new RowsFiltroCollection();
                RowRelatorio.Add(new RowsFiltro("NOMEUSUARIO", "System.String", "=", txtNome.Text, "and"));
                RowRelatorio.Add(new RowsFiltro("SENHAUSUARIO", "System.String", "=", SENHAUSUARIO, "and"));
                RowRelatorio.Add(new RowsFiltro("FLAGATIVO", "System.String", "=", "S"));

                USUARIOCollection USUARIOColl = new USUARIOCollection();
                USUARIOColl = USUARIOP.ReadCollectionByParameter(RowRelatorio);

                if (USUARIOColl.Count > 0)
                {
                    _IdUsuario = USUARIOColl[0].IDUSUARIO;
                    _IdNivel   = Convert.ToInt32(USUARIOColl[0].IDNIVELUSUARIO);
                    result     = true;
                }
                else
                {
                    result = false;
                }

                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível acessar o Banco de Dados!",
                                "IMEX Sistemas",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);

                MessageBox.Show("Erro técnico: " + ex.Message);

                RestaurarConfig();

                result = false;

                return(result);
            }
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(value.ToString()))
                {
                    return(null);
                }

                validationContext
                .ObjectType
                .GetProperty(validationContext.MemberName)
                .SetValue(validationContext.ObjectInstance, SecurityString.Hash(value.ToString()), null);

                return(null);
            }
            catch (System.Exception)
            {
                return(null);
            }
        }
        public virtual IDictionary GetRoleActionsAll()
        {
            if (_roleActionsAll != null)
            {
                return(_roleActionsAll);
            }
            if (strUtil.IsNullOrEmpty(_securityString))
            {
                return(new Hashtable());
            }

            _roleActionsAll = new Hashtable();
            IList actions = GetActionAll();

            string[] arrRolePermission = _securityString.Split(SecurityString.roleSeperator);

            if (arrRolePermission.Length > 0)
            {
                for (int i = 0; i < arrRolePermission.Length; i++)
                {
                    if (strUtil.IsNullOrEmpty(arrRolePermission[i]))
                    {
                        continue;
                    }

                    SecurityString ss = new SecurityString(arrRolePermission[i]);
                    if (ss.IsError())
                    {
                        continue;
                    }

                    _roleActionsAll.Add(ss.GetKey(), ss.GetActions(actions));
                }
            }

            return(_roleActionsAll);
        }