コード例 #1
0
        /// <summary>
        /// Obtiene la informacion de un usuario y junto a sus roles
        /// </summary>
        /// <param name="userName">Nombre de usuario</param>
        /// <param name="providerName">Nombre del proveedor de membership</param>
        /// <returns></returns>
        public static User GetUserAnRoles(String userName, string providerName)
        {
            User    wUser     = FwkMembership.GetUser(userName, providerName);
            RolList userRoles = FwkMembership.GetRolesForUser(userName, providerName);

            wUser.Roles = userRoles.GetArrayNames();
            return(wUser);
        }
コード例 #2
0
        /// <summary>
        /// Crea un usuario
        /// Si el usuario existe lanza una (System.Web.Security.MembershipCreateUserException ex)
        /// </summary>
        /// <param name="userName">Usuario</param>
        /// <param name="password">Clave</param>
        /// <param name="email">Email</param>
        /// <param name="providerName">Nombre del proveedor de membership</param>
        public static void CreateUser(string userName, string password, string email, string providerName)
        {
            MembershipCreateStatus status;

            //wProvider.CreateUser(userName, password, email, string.Empty, string.Empty, true, status);
            FwkMembership.CreateUser(userName, password, email, null, null, true, out status, providerName);
            if (status != MembershipCreateStatus.Success)
            {
                Fwk.Exceptions.TechnicalException te = new TechnicalException(string.Concat("Fwk Membership error", GetErrorMessage(status)));
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4005";
                throw te;
            }
        }
コード例 #3
0
        /// <summary>
        /// Crea una regla
        /// </summary>
        /// <param name="rule"></param>
        /// <param name="applicationName">Nombre de la aplicacion. Coincide con CompanyId en la arquitectura</param>
        /// <param name="connectionStringName">Nombre de cadena de coneccion del archivo de configuracion.-</param>
        public static void CreateRule(FwkAuthorizationRule rule, string applicationName, string connectionStringName)
        {
            //Verificar si ya existe
            if (FwkMembership.ExistRule(rule.Name, applicationName, connectionStringName))
            {
                TechnicalException te = new TechnicalException(string.Format(Resource.Rule_ExistError, rule.Name));
                te.ErrorId = "4004";
                throw te;
            }

            try
            {
                Guid wApplicationId = GetApplication(applicationName, connectionStringName);


                StringBuilder str = new StringBuilder(FwkMembershipScripts.Rule_i);
                str.Replace("[ApplicationId]", wApplicationId.ToString());
                str.Replace("[rulename]", rule.Name.Trim());
                str.Replace("[expression]", rule.Expression);

                if (!String.IsNullOrEmpty(rule.Description))
                {
                    str.Replace("[description]", rule.Description.Trim());
                }
                else
                {
                    str.Replace("[description]", string.Empty);
                }
                using (SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString))
                    using (SqlCommand cmd = new SqlCommand(str.ToString(), cnn))
                    {
                        cmd.CommandType = CommandType.Text;

                        cmd.ExecuteNonQuery();
                    }
            }
            catch (TechnicalException tx)
            { throw tx; }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(string.Format(Resource.Rule_Crate_Error, rule.Name), ex);
                te.ErrorId = "4005";
                Fwk.Exceptions.ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                throw te;
            }
        }
コード例 #4
0
        /// <summary>
        /// UpdateRule
        /// </summary>
        /// <param name="rule"></param>
        /// <param name="applicationName">Nombre de la aplicacion. Coincide con CompanyId en la arquitectura</param>
        /// <param name="connectionStringName">Nombre de cadena de coneccion del archivo de configuracion.-</param>
        private static void UpdateRule(FwkAuthorizationRule rule, string newRuleName, string applicationName, string connectionStringName)
        {
            //Verificar si existe
            if (!FwkMembership.ExistRule(rule.Name.Trim(), applicationName, connectionStringName))
            {
                TechnicalException te = new TechnicalException(string.Format(Resource.Rule_NotExist, rule.Name));
                te.ErrorId = "4004";
                throw te;
            }


            try
            {
                Guid wApplicationId = GetApplication(applicationName, connectionStringName);


                using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString))
                {
                    var ruleToUpdate = dc.aspnet_Rules.Where(p => p.Id.Equals(rule.Id)).FirstOrDefault();

                    if (!string.IsNullOrEmpty(newRuleName))
                    {
                        ruleToUpdate.name = newRuleName;
                    }

                    ruleToUpdate.expression  = rule.Expression;
                    ruleToUpdate.Description = rule.Description;

                    dc.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(Fwk.Security.Properties.Resource.MembershipSecurityGenericError, ex);
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4000";
                throw te;
            }
        }
コード例 #5
0
        /// <summary>
        /// Obtiene una lista de usuarios con sus detalles pertenecientes a un determinado rol
        /// </summary>
        /// <param name="roleName">Nombre del rol</param>
        /// <param name="providerName">Nombre del proveedor de membership</param>
        /// <returns>lista de <see cref="User"/> </returns>
        public static List <User> GetUsersDetailedInRole(String roleName, string providerName)
        {
            User wUserByApp;
            SqlMembershipProvider wProvider  = GetSqlMembershipProvider(providerName);
            List <User>           wUsersList = new List <User>();

            try
            {
                foreach (string userName in Roles.Providers[wProvider.Name].GetUsersInRole(roleName))
                {
                    wUserByApp = FwkMembership.GetUser(userName, providerName);
                    wUsersList.Add(wUserByApp);
                }
            }
            catch (Exception ex)
            {
                Fwk.Exceptions.TechnicalException te = new TechnicalException(Fwk.Security.Properties.Resource.MembershipSecurityGenericError, ex);
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4000";
                throw te;
            }

            return(wUsersList);
        }
コード例 #6
0
        /// <summary>
        /// Esta sobrecarga obtiene las reglas atravez de la base de datos.
        /// Para obtener el origen de datos utiliza la configuracion del membership provider configurado
        /// </summary>
        /// <param name="proividerName">Nombre del membership provider</param>
        public FwkAuthorizationRuleProvider(string proividerName)
        {
            List <FwkAuthorizationRule> authorizationRules = FwkMembership.GetRules(proividerName);

            this.authorizationRules = CreateRulesDictionary <FwkAuthorizationRule>(authorizationRules);
        }