File: DdlGrantRoleStmt.java

package info (click to toggle)
eigenbase-farrago 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 21,196 kB
  • ctags: 23,427
  • sloc: java: 210,765; xml: 25,741; sql: 1,765; sh: 581; makefile: 8
file content (113 lines) | stat: -rw-r--r-- 3,904 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
// $Id: //open/dev/farrago/src/net/sf/farrago/ddl/DdlGrantRoleStmt.java#11 $
// Farrago is an extensible data management system.
// Copyright (C) 2005-2009 The Eigenbase Project
// Copyright (C) 2005-2009 SQLstream, Inc.
// Copyright (C) 2005-2009 LucidEra, Inc.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version approved by The Eigenbase Project.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package net.sf.farrago.ddl;

import java.util.*;

import net.sf.farrago.catalog.*;
import net.sf.farrago.fem.security.*;
import net.sf.farrago.session.*;

import org.eigenbase.sql.*;


/**
 * DdlGrantRoleStmt represents a DDL GRANT ROLE statement.
 *
 * @author Quoc Tai Tran
 * @version $Id: //open/dev/farrago/src/net/sf/farrago/ddl/DdlGrantRoleStmt.java#11 $
 */
public class DdlGrantRoleStmt
    extends DdlGrantStmt
{
    //~ Instance fields --------------------------------------------------------

    protected List<SqlIdentifier> roleList;

    //~ Constructors -----------------------------------------------------------

    /**
     * Constructs a new DdlGrantRoleStmt.
     */
    public DdlGrantRoleStmt()
    {
        super();
    }

    //~ Methods ----------------------------------------------------------------

    // implement DdlStmt
    public void visit(DdlVisitor visitor)
    {
        visitor.visit(this);
    }

    // implement FarragoSessionDdlStmt
    public void preValidate(FarragoSessionDdlValidator ddlValidator)
    {
        FarragoRepos repos = ddlValidator.getRepos();

        FemAuthId grantorAuthId = determineGrantor(ddlValidator);

        // TODO: Check that for all roles to be granted  (a) the grantor must be
        // the owner. Or (b) the owner has been granted with Admin Option. Need
        // model change!

        for (SqlIdentifier granteeId : granteeList) {
            // REVIEW: SWZ: 2008-07-29: getAuthIdByName most certainly does not
            // create an AuthId if it does not exist.  An optimization here
            // would be to modify newRoleGrant to accept AuthId instances
            // instead of re-doing the lookup for granteeId for each role in the
            // roleList.

            // Find the repository element id for the grantee,  create one if
            // it does not exist
            FemAuthId granteeAuthId =
                FarragoCatalogUtil.getAuthIdByName(
                    repos,
                    granteeId.getSimple());

            // for each role in the list, we instantiate a repository
            // element. Note that this makes it easier to revoke the privs on
            // the individual basis.
            for (SqlIdentifier roleId : roleList) {
                // create a privilege object and set its properties
                FemGrant grant =
                    FarragoCatalogUtil.newRoleGrant(
                        repos,
                        grantorAuthId.getName(),
                        granteeId.getSimple(),
                        roleId.getSimple());

                // set the privilege name (i.e. action) and properties
                grant.setWithGrantOption(grantOption);
            }
        }
    }

    public void setRoleList(List<SqlIdentifier> roleList)
    {
        this.roleList = roleList;
    }
}

// End DdlGrantRoleStmt.java