KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.RoutinePrivilegeInfo
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.iapi.sql.Activation;
25 import org.apache.derby.iapi.services.sanity.SanityManager;
26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
27 import org.apache.derby.iapi.store.access.TransactionController;
28 import org.apache.derby.iapi.sql.depend.DependencyManager;
29 import org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor;
30 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
31 import org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission;
32 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
33 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
34 import org.apache.derby.iapi.error.StandardException;
35
36 import java.util.Iterator JavaDoc;
37 import java.util.List JavaDoc;
38
39 public class RoutinePrivilegeInfo extends PrivilegeInfo
40 {
41     private AliasDescriptor aliasDescriptor;
42
43     public RoutinePrivilegeInfo( AliasDescriptor aliasDescriptor)
44     {
45         this.aliasDescriptor = aliasDescriptor;
46     }
47     
48     /**
49      * This is the guts of the Execution-time logic for GRANT/REVOKE of a routine execute privilege
50      *
51      * @param activation
52      * @param grant true if grant, false if revoke
53      * @param grantees a list of authorization ids (strings)
54      *
55      * @exception StandardException Thrown on failure
56      */

57     public void executeGrantRevoke( Activation activation,
58                                     boolean grant,
59                                     List JavaDoc grantees)
60         throws StandardException
61     {
62         // Check that the current user has permission to grant the privileges.
63
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
64         DataDictionary dd = lcc.getDataDictionary();
65         String JavaDoc currentUser = lcc.getAuthorizationId();
66         TransactionController tc = lcc.getTransactionExecute();
67
68         // Check that the current user has permission to grant the privileges.
69
checkOwnership( currentUser,
70                         aliasDescriptor,
71                         dd.getSchemaDescriptor( aliasDescriptor.getSchemaUUID(), tc),
72                         dd);
73         
74         DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
75
76         RoutinePermsDescriptor routinePermsDesc = ddg.newRoutinePermsDescriptor( aliasDescriptor, currentUser);
77
78         dd.startWriting(lcc);
79         for( Iterator JavaDoc itr = grantees.iterator(); itr.hasNext();)
80         {
81             // Keep track to see if any privileges are revoked by a revoke
82
// statement. If a privilege is not revoked, we need to raise a
83
// warning.
84
boolean privileges_revoked = false;
85             String JavaDoc grantee = (String JavaDoc) itr.next();
86             if (dd.addRemovePermissionsDescriptor( grant, routinePermsDesc, grantee, tc))
87             {
88                 privileges_revoked = true;
89                 //Derby currently supports only restrict form of revoke execute
90
//privilege and that is why, we are sending invalidation action
91
//as REVOKE_PRIVILEGE_RESTRICT rather than REVOKE_PRIVILEGE
92
dd.getDependencyManager().invalidateFor(routinePermsDesc, DependencyManager.REVOKE_PRIVILEGE_RESTRICT, lcc);
93             }
94             
95             addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
96         }
97     } // end of executeConstantAction
98
}
99
Popular Tags