Project

General

Profile

« Previous | Next » 

Revision 1408

Added by Jing Tao almost 22 years ago

Access control for documents level works.

View differences:

src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
86 86
     super(conn, action, docid, user, groups, pub, serverCode);
87 87
   }
88 88
   
89
    /** Construct an instance of the handler class
90
    * In this constructor, user can specify the version need to upadate
91
    *
92
    * @param conn the JDBC connection to which information is written
93
    * @param action - "INSERT" or "UPDATE"
94
    * @param docid to be inserted or updated into JDBC connection
95
    * @param revision, the user specified the revision need to be update
96
    * @param user the user connected to MetaCat servlet and owns the document
97
    * @param groups the groups to which user belongs
98
    * @param pub flag for public "read" access on document
99
    * @param serverCode the serverid from xml_replication on which this document
100
    *        resides.
101
    *
102
    */
103
   public EmlSAXHandler(DBConnection conn, String action, String docid,
104
     String revision, String user, String[] groups, String pub, int serverCode)
105
   {
106
     super(conn, action, docid, revision, user, groups, pub, serverCode);
107
   }
108
   
89 109
   /** SAX Handler that is called at the start of each XML element */
90 110
   public void startElement(String uri, String localName,
91 111
                            String qName, Attributes atts)
......
224 244
         
225 245
       }
226 246
     }
227
     
247
   
228 248
     // handle access stuff
229 249
     if (localName.equals(ACCESS))
230 250
     {
......
241 261
       }
242 262
       // create access object 
243 263
        accessObject = new AccessSection();
244
     }
245
     
246
     // Set up accesssection object permorder and id
247
     if ( currentNode.getTagName().equals(ACCESS) ) 
248
     {
249
       // set permission order
264
         // set permission order
250 265
       String permOrder = currentNode.getAttribute(ORDER);
251 266
       accessObject.setPermissionOrder(permOrder);
252 267
       // set access id
......
255 270
       
256 271
     }
257 272
     
273
    
258 274
     // Set up a access rule
259
     if (parentNode.getTagName().equals(ACCESS) && 
260
         currentNode.getTagName().equals(ALLOW))
275
     if (parentNode.getTagName() != null && 
276
       (parentNode.getTagName()).equals(ACCESS) && localName.equals(ALLOW))
261 277
     {
262
       accessRule = new AccessRule();
278
      
279
       accessRule = new AccessRule(); 
280
      
263 281
       //set permission type "allow"
264 282
       accessRule.setPermissionType(ALLOW);
283
      
265 284
     }
266 285
     
267 286
     // set up an access rule
268
     if (parentNode.getTagName().equals(ACCESS) && 
269
         currentNode.getTagName().equals(DENY))
287
     if (parentNode.getTagName() != null 
288
       && (parentNode.getTagName()).equals(ACCESS) && localName.equals(DENY))
270 289
     {
271 290
       accessRule = new AccessRule();
272 291
       //set permission type "allow"
273 292
       accessRule.setPermissionType(DENY);
274 293
     }
275 294
       
276
     
295
  
277 296
     // Add the node to the stack, so that any text data can be
278 297
     // added as it is encountered
279 298
     nodeStack.push(currentNode);
......
286 305
  public void characters(char[] cbuf, int start, int len) throws SAXException 
287 306
  {
288 307
     super.characters(cbuf, start, len);
308
    
289 309
     // access stuff
290 310
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
291 311
     String currentTag = currentNode.getTagName();
......
392 412
    // for top document level
393 413
    AccessSection accessSection = (AccessSection)
394 414
                                          topLevelAccessControlMap.get(docid);
415
    // if accessSection is null stop it
416
    if( accessSection == null)
417
    {
418
      return;
419
    }
395 420
    String permOrder = accessSection.getPermissionOrder();
396 421
    String sql = "INSERT INTO xml_access (docid, principal_name, permission, "+
397 422
                 "perm_type, perm_order, accessfileid) VALUES " +

Also available in: Unified diff