~ubuntu-branches/ubuntu/maverick/hsqldb/maverick

« back to all changes in this revision

Viewing changes to src/org/hsqldb/Grantee.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-09-26 11:47:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060926114749-3jd0utm7w21x1iqt
Tags: 1.8.0.5-2ubuntu1
* Synchronise with Debian unstable; remaining changes:
  - build using java-gcj-compat.
* libhsqldb-java: Add gij as alternative dependency.
* Build a libhsqldb-java-gcj package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2001-2005, The HSQL Development Group
2
 
 * All rights reserved.
3
 
 *
4
 
 * Redistribution and use in source and binary forms, with or without
5
 
 * modification, are permitted provided that the following conditions are met:
6
 
 *
7
 
 * Redistributions of source code must retain the above copyright notice, this
8
 
 * list of conditions and the following disclaimer.
9
 
 *
10
 
 * Redistributions in binary form must reproduce the above copyright notice,
11
 
 * this list of conditions and the following disclaimer in the documentation
12
 
 * and/or other materials provided with the distribution.
13
 
 *
14
 
 * Neither the name of the HSQL Development Group nor the names of its
15
 
 * contributors may be used to endorse or promote products derived from this
16
 
 * software without specific prior written permission.
17
 
 *
18
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
 
 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22
 
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
 
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 
 */
30
 
 
31
 
 
 
1
/* Copyright (c) 2001-2005, The HSQL Development Group
 
2
 * All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
7
 * Redistributions of source code must retain the above copyright notice, this
 
8
 * list of conditions and the following disclaimer.
 
9
 *
 
10
 * Redistributions in binary form must reproduce the above copyright notice,
 
11
 * this list of conditions and the following disclaimer in the documentation
 
12
 * and/or other materials provided with the distribution.
 
13
 *
 
14
 * Neither the name of the HSQL Development Group nor the names of its
 
15
 * contributors may be used to endorse or promote products derived from this
 
16
 * software without specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
 
22
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
28
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 */
 
30
 
 
31
 
32
32
package org.hsqldb;
33
33
 
34
34
import org.hsqldb.HsqlNameManager.HsqlName;
73
73
     * true if this grantee has database administrator priv directly
74
74
     *  (ie., not by membership in any role)
75
75
     */
76
 
    private boolean adminDirect = false;
 
76
    private boolean isAdminDirect = false;
77
77
 
78
78
    /** true if this grantee has database administrator priv by any means. */
79
 
    private boolean admin = false;
 
79
    private boolean isAdmin = false;
80
80
 
81
81
    /** contains righs granted direct, or via roles, expept those of PUBLIC */
82
82
    private IntValueHashMap fullRightsMap = new IntValueHashMap();
340
340
        rightsMap.clear();
341
341
        fullRightsMap.clear();
342
342
 
343
 
        adminDirect = false;
 
343
        isAdminDirect = false;
344
344
    }
345
345
 
346
346
    /**
351
351
     * from the dbobject argument for at least one of the rights
352
352
     * contained in the rights argument. Otherwise, it throws.
353
353
     */
354
 
    void check(Object dbobject, int rights) throws HsqlException {
 
354
    void check(HsqlName dbobject, int rights) throws HsqlException {
355
355
 
356
356
        if (!isAccessible(dbobject, rights)) {
357
357
            throw Trace.error(Trace.ACCESS_IS_DENIED);
358
358
        }
359
359
    }
360
360
 
 
361
    void check(String dbobject) throws HsqlException {
 
362
 
 
363
        if (!isAccessible(dbobject)) {
 
364
            throw Trace.error(Trace.ACCESS_IS_DENIED);
 
365
        }
 
366
    }
 
367
 
361
368
    /**
362
369
     * Returns true if any of the rights represented by the
363
370
     * rights argument has been granted on the database object identified
369
376
     *
370
377
     * Only does one level of recursion to check the PUBLIC role.
371
378
     */
372
 
    boolean isAccessible(Object dbObject, int rights) throws HsqlException {
373
 
 
374
 
        if (dbObject instanceof String) {
375
 
            if (((String) dbObject).startsWith("org.hsqldb.Library")
376
 
                    || ((String) dbObject).startsWith("java.lang.Math")) {
377
 
                return true;
378
 
            }
379
 
        }
380
 
 
381
 
        if (admin) {
 
379
    boolean isAccessible(HsqlName dbObject, int rights) throws HsqlException {
 
380
 
 
381
        if (isAdmin) {
382
382
            return true;
383
383
        }
384
384
 
396
396
    }
397
397
 
398
398
    /**
 
399
     * Returns true if any right at all has been granted to this User object
 
400
     * on the database object identified by the dbObject argument.
 
401
     */
 
402
    boolean isAccessible(String functionName) throws HsqlException {
 
403
 
 
404
        if (functionName.startsWith("org.hsqldb.Library")
 
405
                || functionName.startsWith("java.lang.Math")) {
 
406
            return true;
 
407
        }
 
408
 
 
409
        if (isAdmin) {
 
410
            return true;
 
411
        }
 
412
 
 
413
        if (pubGrantee != null && pubGrantee.isAccessible(functionName)) {
 
414
            return true;
 
415
        }
 
416
 
 
417
        int n = fullRightsMap.get(functionName, 0);
 
418
 
 
419
        return n != 0;
 
420
    }
 
421
 
 
422
    /**
399
423
     * Returns true if any of the rights represented by the
400
424
     * rights argument has been granted on the database object identified
401
425
     * by the dbObject argument. <p>
423
447
     * Returns true if any right at all has been granted to this User object
424
448
     * on the database object identified by the dbObject argument.
425
449
     */
426
 
    boolean isAccessible(Object dbObject) throws HsqlException {
 
450
    boolean isAccessible(HsqlName dbObject) throws HsqlException {
427
451
        return isAccessible(dbObject, GranteeManager.ALL);
428
452
    }
429
453
 
443
467
     * or indirectly.
444
468
     */
445
469
    boolean isAdmin() {
446
 
        return admin;
 
470
        return isAdmin;
447
471
    }
448
472
 
449
473
    /**
450
 
     * Returns true if this User object is for a user with Direct
 
474
     * Returns true if this grantee object is for a user with Direct
451
475
     * database administrator privileges.
452
476
     * I.e., if this User/Role has Admin priv. directly, not via a
453
477
     * nested Role.
454
478
     */
455
479
    boolean isAdminDirect() {
456
 
        return adminDirect;
 
480
        return isAdminDirect;
457
481
    }
458
482
 
459
483
    /**
566
590
     * Should be "setAdminDirect(boolean").
567
591
     */
568
592
    void setAdminDirect() {
569
 
        admin = adminDirect = true;
 
593
        isAdmin = isAdminDirect = true;
570
594
    }
571
595
 
572
596
    /**
632
656
 
633
657
        fullRightsMap.clear();
634
658
 
635
 
        admin = adminDirect;
 
659
        isAdmin = isAdminDirect;
636
660
 
637
661
        Iterator it = roles.iterator();
638
662
 
644
668
 
645
669
                fullRightsMap.putAll(currentRole.fullRightsMap);
646
670
 
647
 
                admin |= currentRole.isAdmin();
 
671
                isAdmin |= currentRole.isAdmin();
648
672
            } catch (HsqlException e) {}
649
673
        }
650
674