示例#1
0
        public string grant(string privilege, string table, string profile)
        {
            TablePermission tb = new TablePermission(table);

            if (privilege.Equals("INSERT"))
            {
                tb.addPrivilege(Privileges.INSERT);
            }
            else if (privilege.Equals("SELECT"))
            {
                tb.addPrivilege(Privileges.SELECT);
            }
            else if (privilege.Equals("UPDATE"))
            {
                tb.addPrivilege(Privileges.UPDATE);
            }
            else if (privilege.Equals("DELETE"))
            {
                tb.addPrivilege(Privileges.DELETE);
            }

            foreach (Profile pr in profiles)
            {
                if (profile.Equals(pr.getName()))
                {
                    pr.addTablePermission(tb);
                }
            }
            return("Privileges granted");
        }
示例#2
0
        public void removePrivilege(TablePermission tp)
        {
            TablePermission tpToDelete = tablePermissions.Find(tper => tper.getTableName() == tp.getTableName());

            if (tp.samePrivileges(tpToDelete))
            {
                tablePermissions.Remove(tpToDelete);
            }
        }
示例#3
0
        public Boolean samePrivileges(TablePermission tp)
        {
            Boolean samePrivileges = true;

            foreach (Privileges p in privileges)
            {
                if (!tp.getPrivileges().Contains(p))
                {
                    samePrivileges = false;
                }
            }

            return(samePrivileges);
        }
示例#4
0
        public string revoke(string privilege, string table, string profile)
        {
            Profile toDelete = null;



            toDelete = profiles.Find(pr => pr.getName() == profile);
            Profile aux = toDelete;


            profiles.Remove(toDelete);

            TablePermission tb = new TablePermission(table);

            if (privilege.Equals("INSERT"))
            {
                tb.removePrivilege(Privileges.INSERT);
            }
            else if (privilege.Equals("SELECT"))
            {
                tb.removePrivilege(Privileges.SELECT);
            }
            else if (privilege.Equals("UPDATE"))
            {
                tb.removePrivilege(Privileges.UPDATE);
            }
            else if (privilege.Equals("DELETE"))
            {
                tb.removePrivilege(Privileges.DELETE);
            }

            if (aux != null)
            {
                aux.removePrivilege(tb);
                profiles.Add(aux);
            }
            return("Privileges revoked");
        }
示例#5
0
 public void addTablePermission(TablePermission tp)
 {
     tablePermissions.Add(tp);
 }