Project

General

Profile

« Previous | Next » 

Revision 607

Added by bojilova about 24 years ago

problems with passing the connection between objects

View differences:

src/edu/ucsb/nceas/metacat/DBQuery.java
15 15
 * '$Revision$'
16 16
 */
17 17

  
18
package edu.ucsb.nceas.metacat; 
18
package edu.ucsb.nceas.metacat;
19 19

  
20 20
import java.io.*;
21 21
import java.util.Vector;
......
656 656
    }
657 657
    
658 658
    // Check for READ permission on @docid for @user and/or @group
659
    AccessControlList aclobj = new AccessControlList();
660
    boolean hasPermission = aclobj.hasPermission(conn,"READ",user,docid);
659
    AccessControlList aclobj = new AccessControlList(conn);
660
    boolean hasPermission = aclobj.hasPermission("READ",user,docid);
661 661
    if ( !hasPermission && group != null ) {
662
      hasPermission = aclobj.hasPermission(conn,"READ",group,docid);
662
      hasPermission = aclobj.hasPermission("READ",group,docid);
663 663
    }
664 664
    
665 665
    return hasPermission;
src/edu/ucsb/nceas/metacat/AccessControlList.java
62 62
  /**
63 63
   * Construct an instance of the AccessControlList class.
64 64
   * It is used by the permission check up from DBQuery and DocumentImpl
65
   */
66
  public AccessControlList () //throws SQLException, ClassNotFoundException
67
  {
68
    //MetaCatUtil util = new MetaCatUtil();
69
    //this.conn = util.openDBConnection();
70
  }
71

  
72
  /**
73
   * Construct an instance of the AccessControlList class.
74
   * It is used by the permission check up from DBQuery and DocumentImpl
75 65
   *
76 66
   * @param conn the JDBC connection where acl data are loaded
77 67
   */
78
  public AccessControlList ( Connection conn )
68
  public AccessControlList ( Connection conn ) throws SQLException
79 69
  {
80
    this.conn = conn;
70
    Connection dbconn = conn;
71
    if ( dbconn == null || dbconn.isClosed() ) {
72
      System.out.println("AccessControlList: " + 
73
                         "DB connection was closed. Open a new one");
74
      try {
75
        MetaCatUtil util = new MetaCatUtil();
76
        dbconn = util.openDBConnection();
77
      } catch (Exception e) {
78
        throw new SQLException(e.getMessage());
79
      }
80
    }
81
    this.conn = dbconn;
81 82
  }
82 83

  
83 84
  /**
......
343 344
  }
344 345

  
345 346
  /** Check for @permission for @principal on @resourceId from db connection */
346
  public boolean hasPermission ( Connection conn, String permission,
347
  public boolean hasPermission ( String permission,
347 348
                                 String principal, String resourceId )
348 349
                 throws SQLException
349 350
  {
350
    Connection dbconn = conn;
351
    
352
    if ( dbconn == null ) {
353
      System.out.println("AccessControlList.hasPermission(): " + 
354
                         "DB connection was closed. Open a new one");
355
      try {
356
        MetaCatUtil util = new MetaCatUtil();
357
        dbconn = util.openDBConnection();
358
      } catch (Exception e) {
359
        throw new SQLException(e.getMessage());
360
      }
361
    }
362
      
363 351
    PreparedStatement pstmt;
364 352
    // check public access to @resourceId from xml_documents table
365 353
    if ( permission.equals("READ") ) {
366 354
      try {
367
        pstmt = dbconn.prepareStatement(
355
        pstmt = conn.prepareStatement(
368 356
                "SELECT 'x' FROM xml_documents " +
369 357
                "WHERE docid LIKE ? AND public_access = 1");
370 358
        // Bind the values to the query
......
390 378
    // check if @principal is owner of @resourceId in xml_documents table
391 379
    if ( principal != null ) {
392 380
      try {
393
        pstmt = dbconn.prepareStatement(
381
        pstmt = conn.prepareStatement(
394 382
                "SELECT 'x' FROM xml_documents " +
395 383
                "WHERE docid LIKE ? AND user_owner LIKE ?");
396 384
        // Bind the values to the query
......
417 405
      int ticketCount = 0;
418 406
      String permOrder = "";
419 407
      try {
420
        pstmt = dbconn.prepareStatement(
408
        pstmt = conn.prepareStatement(
421 409
                "SELECT permission, perm_order, ticket_count " +
422 410
                "FROM xml_access " +
423 411
                "WHERE docid LIKE ? " + 

Also available in: Unified diff