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"); }
public void removePrivilege(TablePermission tp) { TablePermission tpToDelete = tablePermissions.Find(tper => tper.getTableName() == tp.getTableName()); if (tp.samePrivileges(tpToDelete)) { tablePermissions.Remove(tpToDelete); } }
public Boolean samePrivileges(TablePermission tp) { Boolean samePrivileges = true; foreach (Privileges p in privileges) { if (!tp.getPrivileges().Contains(p)) { samePrivileges = false; } } return(samePrivileges); }
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"); }
public void addTablePermission(TablePermission tp) { tablePermissions.Add(tp); }