Changeset 265

Show
Ignore:
Timestamp:
01/06/08 00:10:44 (1 year ago)
Author:
chris
Message:

Fix access control when updating and deleting objects by monad range.

Add convenience method to get object monad set by type and ID.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/src/com/qwirx/lex/emdros/EmdrosDatabase.java

    r259 r265  
    322322        try 
    323323        { 
    324             if (!canWriteTo(objectType, id_ds)) 
    325             { 
    326                 throw new DatabaseException("You do not have permission "+ 
    327                     "to modify this object", changeType + " " + objectType + 
    328                     " " + objectIds); 
     324            if (changeType != EmdrosChange.CREATE) 
     325            { 
     326                if (id_ds != null && !canWriteTo(objectType, id_ds)) 
     327                { 
     328                    throw new DatabaseException("You do not have permission "+ 
     329                        "to modify this object", changeType + " " + objectType + 
     330                        " " + objectIds); 
     331                } 
     332                // must check access to monads later 
    329333            } 
    330334        } 
     
    452456    } 
    453457     
    454     public boolean canWriteTo(String objectType, int[] objectIds) 
    455     throws DatabaseException, EmdrosException 
     458    public SetOfMonads getObjectMonads(String type, int [] objectIds) 
     459    throws DatabaseException 
    456460    { 
    457461        String query = "GET MONADS FROM OBJECTS WITH ID_DS = "; 
     
    466470        } 
    467471         
    468         Table table = getTable(query + " ["+objectType+"]"); 
     472        Table table = getTable(query + " ["+type+"]"); 
    469473 
    470474        TableIterator rows = table.iterator(); 
     
    481485            } 
    482486        } 
    483         catch (TableException e) 
     487        catch (EmdrosException e) 
    484488        { 
    485489            throw new DatabaseException("Failed to get monads from object",  
     
    487491        } 
    488492         
    489         return canWriteTo(monads); 
    490     } 
    491  
    492     private boolean canWriteTo(SetOfMonads monads) 
     493        return monads; 
     494    } 
     495     
     496    public boolean canWriteTo(String objectType, int[] objectIds) 
     497    throws DatabaseException 
     498    { 
     499        return canWriteTo(getObjectMonads(objectType, objectIds)); 
     500    } 
     501 
     502    public boolean canWriteTo(SetOfMonads monads) 
    493503    throws DatabaseException 
    494504    { 
     
    497507         
    498508        String query = "SELECT Monad_First, Monad_Last " + 
    499         "FROM   user_text_access " + 
    500         "WHERE  (User_Name = ? OR User_Name = 'anonymous') " + 
    501         "AND    Write_Access = '1'"; 
     509            "FROM   user_text_access " + 
     510            "WHERE  (User_Name = ? OR User_Name = 'anonymous') " + 
     511            "AND    Write_Access = '1'"; 
    502512         
    503513        try 
     
    515525        int first = 0; 
    516526        int last  = 0; 
     527         
     528        SetOfMonads copy = new SetOfMonads(monads); 
    517529 
    518530        try 
     
    523535                last  = rs.getInt(2); 
    524536                MonadSetElement mse = new MonadSetElement(first, last); 
    525                 monads.removeMSE(mse); 
     537                copy.removeMSE(mse); 
    526538            } 
    527539 
     
    540552        } 
    541553         
    542         return monads.isEmpty(); 
     554        return copy.isEmpty(); 
    543555    } 
    544556