KickJava   Java API By Example, From Geeks To Geeks.

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


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.iapi.sql.conn.Authorizer;
26 import org.apache.derby.iapi.reference.SQLState;
27 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
28 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
29 import org.apache.derby.iapi.store.access.TransactionController;
30 import org.apache.derby.iapi.services.sanity.SanityManager;
31
32 /**
33  * This class describes a schema permission required by a statement.
34  */

35
36 public class StatementSchemaPermission extends StatementPermission
37 {
38     /**
39      * The schema name
40      */

41     private String JavaDoc schemaName;
42     /**
43      * Authorization id
44      */

45     private String JavaDoc aid;
46     /**
47      * One of Authorizer.CREATE_SCHEMA_PRIV, MODIFY_SCHEMA_PRIV,
48      * DROP_SCHEMA_PRIV, etc.
49      */

50     private int privType;
51
52     public StatementSchemaPermission(String JavaDoc schemaName, String JavaDoc aid, int privType)
53     {
54         this.schemaName = schemaName;
55         this.aid = aid;
56         this.privType = privType;
57     }
58
59     /**
60      * @see StatementPermission#check
61      */

62     public void check( LanguageConnectionContext lcc,
63                        String JavaDoc authid,
64                        boolean forGrant) throws StandardException
65     {
66         DataDictionary dd = lcc.getDataDictionary();
67         TransactionController tc = lcc.getTransactionExecute();
68     
69         switch ( privType )
70         {
71             case Authorizer.MODIFY_SCHEMA_PRIV:
72             case Authorizer.DROP_SCHEMA_PRIV:
73                 SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, false);
74                 // If schema hasn't been created already, no need to check
75
// for drop schema, an exception will be thrown if the schema
76
// does not exists.
77
if (sd == null)
78                     return;
79
80                 if (!authid.equals(sd.getAuthorizationId()))
81                     throw StandardException.newException(
82                         SQLState.AUTH_NO_ACCESS_NOT_OWNER, authid, schemaName);
83                 break;
84             
85             case Authorizer.CREATE_SCHEMA_PRIV:
86                 // Non-DBA Users can only create schemas that match their authid
87
// Also allow only DBA to set authid to another user
88
// Note that for DBA, check interface wouldn't be called at all
89
if ( !schemaName.equals(authid) ||
90                         (aid != null && !aid.equals(authid)) )
91                     throw StandardException.newException(
92                         SQLState.AUTH_NOT_DATABASE_OWNER, authid, schemaName);
93                 break;
94             
95             default:
96                 if (SanityManager.DEBUG)
97                 {
98                     SanityManager.THROWASSERT(
99                             "Unexpected value (" + privType + ") for privType");
100                 }
101                 break;
102         }
103     }
104
105     /**
106      * Schema level permission is never required as list of privileges required
107      * for triggers/constraints/views and hence we don't do any work here, but
108      * simply return null
109      *
110      * @see StatementPermission#check
111      */

112     public PermissionsDescriptor getPermissionDescriptor(String JavaDoc authid, DataDictionary dd)
113     throws StandardException
114     {
115         return null;
116     }
117 }
118
Popular Tags