KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > dictionary > StatementRoutinePermission


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission
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.iapi.sql.dictionary;
23
24 import org.apache.derby.iapi.error.StandardException;
25 import org.apache.derby.catalog.UUID;
26 import org.apache.derby.iapi.sql.conn.Authorizer;
27 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
28 import org.apache.derby.iapi.reference.SQLState;
29 import org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor;
30 import org.apache.derby.iapi.store.access.TransactionController;
31
32 /**
33  * This class describes a routine execute permission
34  * required by a statement.
35  */

36
37 public final class StatementRoutinePermission extends StatementPermission
38 {
39     private UUID routineUUID;
40
41     public StatementRoutinePermission( UUID routineUUID)
42     {
43         this.routineUUID = routineUUID;
44     }
45                                      
46     /**
47      * @see StatementPermission#check
48      */

49     public void check( LanguageConnectionContext lcc,
50                        String JavaDoc authorizationId,
51                        boolean forGrant) throws StandardException
52     {
53         DataDictionary dd = lcc.getDataDictionary();
54         TransactionController tc = lcc.getTransactionExecute();
55         
56         RoutinePermsDescriptor perms = dd.getRoutinePermissions( routineUUID, authorizationId);
57         if( perms == null || ! perms.getHasExecutePermission())
58             perms = dd.getRoutinePermissions(routineUUID, Authorizer.PUBLIC_AUTHORIZATION_ID);
59
60         if( perms == null || ! perms.getHasExecutePermission())
61         {
62             AliasDescriptor ad = dd.getAliasDescriptor( routineUUID);
63             if( ad == null)
64                 throw StandardException.newException( SQLState.AUTH_INTERNAL_BAD_UUID, "routine");
65             SchemaDescriptor sd = dd.getSchemaDescriptor( ad.getSchemaUUID(), tc);
66             if( sd == null)
67                 throw StandardException.newException( SQLState.AUTH_INTERNAL_BAD_UUID, "schema");
68             throw StandardException.newException( forGrant ? SQLState.AUTH_NO_EXECUTE_PERMISSION_FOR_GRANT
69                                                   : SQLState.AUTH_NO_EXECUTE_PERMISSION,
70                                                   authorizationId,
71                                                   ad.getDescriptorType(),
72                                                   sd.getSchemaName(),
73                                                   ad.getDescriptorName());
74         }
75     } // end of check
76

77     /**
78      * @see StatementPermission#getPermissionDescriptor
79      */

80     public PermissionsDescriptor getPermissionDescriptor(String JavaDoc authid, DataDictionary dd)
81     throws StandardException
82     {
83         return dd.getRoutinePermissions(routineUUID,authid);
84     }
85 }
86
Popular Tags