KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > PrivilegeInfo


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.PrivilegeInfo
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
23
24 import org.apache.derby.catalog.UUID;
25 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
26 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
27 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29 import org.apache.derby.iapi.sql.Activation;
30 import org.apache.derby.iapi.reference.SQLState;
31
32 import org.apache.derby.iapi.error.StandardException;
33
34 import java.util.List JavaDoc;
35
36 public abstract class PrivilegeInfo
37 {
38
39     /**
40      * This is the guts of the Execution-time logic for GRANT/REVOKE
41      *
42      * @param activation
43      * @param grant true if grant, false if revoke
44      * @param grantees a list of authorization ids (strings)
45      *
46      * @exception StandardException Thrown on failure
47      */

48     abstract public void executeGrantRevoke( Activation activation,
49                                              boolean grant,
50                                              List JavaDoc grantees)
51         throws StandardException;
52
53     /**
54      * Determines whether a user is the owner of an object
55      * (table, function, or procedure). Note that Database Owner can access
56      * database objects without needing to be their owner
57      *
58      * @param user authorizationId of current user
59      * @param objectDescriptor object being checked against
60      * @param sd SchemaDescriptor
61      * @param dd DataDictionary
62      *
63      * @exception StandardException if user does not own the object
64      */

65     protected void checkOwnership( String JavaDoc user,
66                                    TupleDescriptor objectDescriptor,
67                                    SchemaDescriptor sd,
68                                    DataDictionary dd)
69         throws StandardException
70     {
71         if (!user.equals(sd.getAuthorizationId()) &&
72                 !user.equals(dd.getAuthorizationDatabaseOwner()))
73             throw StandardException.newException(SQLState.AUTH_NOT_OWNER,
74                                       user,
75                                       objectDescriptor.getDescriptorType(),
76                                       sd.getSchemaName(),
77                                       objectDescriptor.getDescriptorName());
78     }
79     
80     /**
81      * This method adds a warning if a revoke statement has not revoked
82      * any privileges from a grantee.
83      *
84      * @param activation
85      * @param grant true if grant, false if revoke
86      * @param privileges_revoked true, if at least one privilege has been
87      * revoked from a grantee, false otherwise
88      * @param grantee authorization id of the user
89      */

90     protected void addWarningIfPrivilegeNotRevoked( Activation activation,
91                                                     boolean grant,
92                                                     boolean privileges_revoked,
93                                                     String JavaDoc grantee)
94     {
95         if(!grant && !privileges_revoked)
96             activation.addWarning(StandardException.newWarning
97                     (SQLState.LANG_PRIVILEGE_NOT_REVOKED, grantee));
98     }
99 }
100
Popular Tags