예제 #1
0
        public Framework.Rbac AddOrUpdate(Framework.Rbac rbac)
        {
            Rbac dbRbac = null;

            try
            {
                using (var ctx = new Entities(ConnectionString))
                {
                    dbRbac = ctx.Rbacs.Where(r => r.RbacId == rbac.RbacId).SingleOrDefault();
                    if (dbRbac == null) //try with name
                    {
                        dbRbac = ctx.Rbacs.Where(r => r.Name.Equals(rbac.Name, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
                    }

                    if (dbRbac == null)
                    {
                        Rbac newRbac = Assign(rbac);
                        newRbac.Password = GetEncryptedString("password");  //default, user supposed to change immediately
                        newRbac.Version  = 1;
                        dbRbac           = ctx.Rbacs.Add(newRbac);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(rbac.Name))
                        {
                            dbRbac.Name = rbac.Name;
                        }

                        if (!string.IsNullOrEmpty(rbac.Description))
                        {
                            dbRbac.Description = rbac.Description;
                        }

                        if (!string.IsNullOrEmpty(rbac.ConnectionString))
                        {
                            dbRbac.ConnectionString = GetEncryptedString(rbac.ConnectionString);
                        }

                        if (!string.IsNullOrEmpty(rbac.MetaDataRbac))
                        {
                            dbRbac.MetaDataRbac = GetEncryptedString(rbac.MetaDataRbac);
                        }

                        if (!string.IsNullOrEmpty(rbac.MetaDataEntitlements))
                        {
                            dbRbac.MetaDataEntitlements = GetEncryptedString(rbac.MetaDataEntitlements);
                        }
                        dbRbac.Version = rbac.Version + 1;
                    }

                    ctx.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                RaiseError(e);
            }

            return(Assign(dbRbac));
        }
예제 #2
0
        public bool ChangePasswordRbac(string rbacName, string newPassword)
        {
            byte[] bNewPassword = GetEncryptedString(newPassword);

            try
            {
                using (var ctx = new Entities(ConnectionString))
                {
                    Rbac dbRbac = ctx.Rbacs.Where(r => r.Name.Equals(rbacName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
                    if (dbRbac != null)
                    {
                        dbRbac.Password = bNewPassword;
                        ctx.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (DbUpdateException dbe)
            {
                RaiseError(dbe);
            }
            catch (DbEntityValidationException e)
            {
                RaiseError(e);
            }
            return(false);
        }
예제 #3
0
        public bool Authenticate(int rbactId, string password)
        {
            byte[] bPassword = GetEncryptedString(password);

            using (var ctx = new Entities(ConnectionString))
            {
                Rbac dbRbac = ctx.Rbacs.AsEnumerable().Where(r => ((r.RbacId == rbactId) && (r.Password.SequenceEqual(bPassword)))).SingleOrDefault();

                if (dbRbac != null)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
파일: Manager.cs 프로젝트: crazyants/aarbac
        private Rbac Assign(Framework.Rbac rbac)
        {
            if (rbac == null)
            {
                return(null);
            }

            Rbac newRbac = new Rbac();

            newRbac.RbacId               = rbac.RbacId;
            newRbac.Name                 = rbac.Name;
            newRbac.Description          = rbac.Description;
            newRbac.ConnectionString     = GetEncryptedString(rbac.ConnectionString);
            newRbac.MetaDataRbac         = GetEncryptedString(rbac.MetaDataRbac);
            newRbac.MetaDataEntitlements = GetEncryptedString(rbac.MetaDataEntitlements);
            newRbac.Version              = rbac.Version;
            return(newRbac);
        }
예제 #5
0
 public Framework.Rbac GetRbac(string name)
 {
     Framework.Rbac rbac = null;
     try
     {
         using (var ctx = new Entities(ConnectionString))
         {
             Rbac dbRbac = ctx.Rbacs.Where(r => r.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
             if (dbRbac != null)
             {
                 rbac = Assign(dbRbac);
             }
         }
     }
     catch (Exception ex)
     {
         RaiseError(ex);
     }
     return(rbac);
 }
예제 #6
0
 public Framework.Rbac GetRbac(int rbacId)
 {
     Framework.Rbac rbac = null;
     try
     {
         using (var ctx = new Entities(ConnectionString))
         {
             Rbac dbRbac = ctx.Rbacs.Where(r => r.RbacId == rbacId).SingleOrDefault();
             if (dbRbac != null)
             {
                 rbac = Assign(dbRbac);
             }
         }
     }
     catch (Exception ex)
     {
         RaiseError(ex);
     }
     return(rbac);
 }
예제 #7
0
파일: Manager.cs 프로젝트: crazyants/aarbac
        private Framework.Rbac Assign(Rbac rbac)
        {
            if (rbac == null)
            {
                return(null);
            }

            Framework.Rbac newRbac = new Framework.Rbac();
            newRbac.RbacId      = rbac.RbacId;
            newRbac.Name        = rbac.Name;
            newRbac.Description = rbac.Description;
            if (!HideSensitiveData)
            {
                newRbac.ConnectionString     = GetDecryptedString(rbac.ConnectionString);
                newRbac.MetaDataRbac         = GetDecryptedString(rbac.MetaDataRbac);
                newRbac.MetaDataEntitlements = GetDecryptedString(rbac.MetaDataEntitlements);
            }
            newRbac.Version = rbac.Version;

            return(newRbac);
        }