01: /*
02:
03: Derby - Class org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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
38: StatementPermission {
39: private UUID routineUUID;
40:
41: public StatementRoutinePermission(UUID routineUUID) {
42: this .routineUUID = routineUUID;
43: }
44:
45: /**
46: * @see StatementPermission#check
47: */
48: public void check(LanguageConnectionContext lcc,
49: String authorizationId, boolean forGrant)
50: throws StandardException {
51: DataDictionary dd = lcc.getDataDictionary();
52: TransactionController tc = lcc.getTransactionExecute();
53:
54: RoutinePermsDescriptor perms = dd.getRoutinePermissions(
55: routineUUID, authorizationId);
56: if (perms == null || !perms.getHasExecutePermission())
57: perms = dd.getRoutinePermissions(routineUUID,
58: Authorizer.PUBLIC_AUTHORIZATION_ID);
59:
60: if (perms == null || !perms.getHasExecutePermission()) {
61: AliasDescriptor ad = dd.getAliasDescriptor(routineUUID);
62: if (ad == null)
63: throw StandardException.newException(
64: SQLState.AUTH_INTERNAL_BAD_UUID, "routine");
65: SchemaDescriptor sd = dd.getSchemaDescriptor(ad
66: .getSchemaUUID(), tc);
67: if (sd == null)
68: throw StandardException.newException(
69: SQLState.AUTH_INTERNAL_BAD_UUID, "schema");
70: throw StandardException
71: .newException(
72: forGrant ? SQLState.AUTH_NO_EXECUTE_PERMISSION_FOR_GRANT
73: : SQLState.AUTH_NO_EXECUTE_PERMISSION,
74: authorizationId, ad.getDescriptorType(), sd
75: .getSchemaName(), ad
76: .getDescriptorName());
77: }
78: } // end of check
79:
80: /**
81: * @see StatementPermission#getPermissionDescriptor
82: */
83: public PermissionsDescriptor getPermissionDescriptor(String authid,
84: DataDictionary dd) throws StandardException {
85: return dd.getRoutinePermissions(routineUUID, authid);
86: }
87: }
|