Project

General

Profile

« Previous | Next » 

Revision 10000

Added by Jing Tao over 7 years ago

Add the guid information in the sax exception when users try to update the access part but they don't have all permission.

View differences:

Eml200SAXHandler.java
300 300
        + "when they don't have write permission!";
301 301

  
302 302
    private static final String UPDATEACCESSERROR = "User tried to update an "
303
        + "access module when they don't have \"ALL\" permission!";
303
        + "access module when they don't have \"ALL\" permission on the object ";
304 304

  
305 305
    public static final String TOPLEVEL = "top";
306 306

  
......
356 356
                // we need to check if user update access subtree
357 357
            	if ( !control.hasPermission(user, groups, AccessControlInterface.ALLSTRING)
358 358
            			&& !control.hasPermission(user, groups, AccessControlInterface.CHMODSTRING)
359
                        && !AuthUtil.isAdministrator(user, groups)) {
359
                        && !AuthUtil.isAdministrator(user, groups) && writeAccessRules) {
360 360
                		
361 361
                    needToCheckAccessModule = true;
362 362
                    topAccessSubTreeFromDB = getTopAccessSubTreeFromDB();
......
1717 1717
     * topLevel, additionalLevel(data access) and referenced access module*/
1718 1718
    private void compareAllAccessModules() throws SAXException
1719 1719
    {
1720
        String guid = docid+"."+revision;
1721
        try {
1722
            guid = IdentifierManager.getInstance().getGUID(docid, Integer.valueOf(revision));
1723
        } catch (Exception e) {
1724
            logMetacat.warn("Eml200SAXHandler.compareAllAccessModules - we can't get object identifier for metacat id "+guid);
1725
        }
1720 1726
      //compare top level
1721
      compareAccessSubtree(topAccessSubTreeFromDB, topAccessSection);
1727
      compareAccessSubtree(topAccessSubTreeFromDB, topAccessSection, guid);
1722 1728

  
1723 1729
      //compare additional level
1724 1730
      int oldSize = additionalAccessSubTreeListFromDB.size();
1725 1731
      int newSize = additionalAccessVector.size();
1732
     
1733
      
1726 1734
      // if size is different, use deleted or added rules, so throw a exception
1727 1735
      if (oldSize != newSize)
1728 1736
      {
1729
        throw new SAXException(UPDATEACCESSERROR);
1737
        throw new SAXException(UPDATEACCESSERROR+guid);
1730 1738
      }
1731 1739
      //because access modules are both ordered in ASC in vectors, so we can
1732 1740
      // compare one bye one
......
1736 1744
                          additionalAccessSubTreeListFromDB.elementAt(i);
1737 1745
        AccessSection fromParser = (AccessSection)
1738 1746
                                additionalAccessVector.elementAt(i);
1739
        compareAccessSubtree(fromDB, fromParser);
1747
        compareAccessSubtree(fromDB, fromParser, guid);
1740 1748
      }
1741 1749

  
1742 1750
      //compare referenced level
......
1748 1756
                               referencedAccessSubTreeListFromDB.get(id);
1749 1757
        AccessSection fromParser = (AccessSection)
1750 1758
                               possibleReferencedAccessHash.get(id);
1751
        compareAccessSubtree(fromDB, fromParser);
1759
        compareAccessSubtree(fromDB, fromParser, guid);
1752 1760
      }
1753 1761
    }
1754 1762

  
......
1757 1765
     * compare the parsed result
1758 1766
     */
1759 1767
    private void compareAccessSubtree(AccessSection fromDBTable,
1760
                                       AccessSection fromParser)
1768
                                       AccessSection fromParser, String identifier)
1761 1769
                                      throws SAXException
1762 1770
    {
1763 1771
       if (fromDBTable == null || fromParser == null)
1764 1772
       {
1765
         throw new SAXException(UPDATEACCESSERROR);
1773
         throw new SAXException(UPDATEACCESSERROR+identifier);
1766 1774
       }
1767 1775
       Stack nodeStackFromDBTable = fromDBTable.getSubTreeNodeStack();
1768 1776
       Stack nodeStackFromParser  = fromParser.getStoredTmpNodeStack();
......
1771 1779
       while(!nodeStackFromDBTable.isEmpty()){
1772 1780
           tempStack.push(nodeStackFromDBTable.pop());
1773 1781
       }
1774
       comparingNodeStacks(tempStack, nodeStackFromParser);
1782
       comparingNodeStacks(tempStack, nodeStackFromParser, identifier);
1775 1783
    }
1776 1784

  
1777 1785
    /* Compare two node stacks to see if they are same */
1778
  private void comparingNodeStacks(Stack stack1, Stack stack2)
1786
  private void comparingNodeStacks(Stack stack1, Stack stack2, String identifier)
1779 1787
          throws SAXException
1780 1788
  {
1781 1789
      // make sure stack1 and stack2 are not empty
1782 1790
      if (stack1.isEmpty() || stack2.isEmpty()) {
1783 1791
          logMetacat.info("Because stack is empty!");
1784
          throw new SAXException(UPDATEACCESSERROR);
1792
          throw new SAXException(UPDATEACCESSERROR+identifier);
1785 1793
      }
1786 1794
      // go throw two stacks and compare every element
1787 1795
      while (!stack1.isEmpty()) {
......
1796 1804

  
1797 1805
              logMetacat.error(
1798 1806
                      "Node stack2 is empty but stack1 isn't!");
1799
              throw new SAXException(UPDATEACCESSERROR);
1807
              throw new SAXException(UPDATEACCESSERROR+identifier);
1800 1808
          }
1801 1809
          // if two records are not same throw a exception
1802 1810
          if (!record1.contentEquals(record2)) {
1803 1811
              logMetacat.info("Two records from new and old stack are not "
1804 1812
                                      + "same!" + record1 + "--" +record2);
1805
              throw new SAXException(UPDATEACCESSERROR);
1813
              throw new SAXException(UPDATEACCESSERROR+identifier);
1806 1814
          }//if
1807 1815
      }//while
1808 1816

  
......
1812 1820
          logMetacat.info(
1813 1821
                  "stack2 still have some elements while stack1 "
1814 1822
                          + "is empty! ");
1815
          throw new SAXException(UPDATEACCESSERROR);
1823
          throw new SAXException(UPDATEACCESSERROR+identifier);
1816 1824
      }//if
1817 1825
  }//comparingNodeStacks
1818 1826

  

Also available in: Unified diff