Source Code Cross Referenced for StatementTablePermission.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » iapi » sql » dictionary » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.iapi.sql.dictionary 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.iapi.sql.dictionary.StatementTablePermission
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:        	  http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.iapi.sql.dictionary;
023:
024:        import org.apache.derby.iapi.error.StandardException;
025:        import org.apache.derby.catalog.UUID;
026:        import org.apache.derby.iapi.sql.conn.Authorizer;
027:        import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
028:        import org.apache.derby.iapi.reference.SQLState;
029:
030:        /**
031:         * This class describes a table permission required by a statement.
032:         */
033:
034:        public class StatementTablePermission extends StatementPermission {
035:            UUID tableUUID;
036:            int privType; // One of Authorizer.SELECT_PRIV, UPDATE_PRIV, etc.
037:
038:            /**
039:             * Constructor for StatementTablePermission. Creates an instance of
040:             * table permission requested for the given access.
041:             * 
042:             * @param tableUUID	UUID of the table
043:             * @param privType	Access privilege requested
044:             *
045:             */
046:            public StatementTablePermission(UUID tableUUID, int privType) {
047:                this .tableUUID = tableUUID;
048:                this .privType = privType;
049:            }
050:
051:            /**
052:             * Return privilege access requested for this access descriptor
053:             *
054:             * @return	Privilege access
055:             */
056:            public int getPrivType() {
057:                return privType;
058:            }
059:
060:            /**
061:             * Return table UUID for this access descriptor
062:             *
063:             * @return	Table UUID
064:             */
065:            public UUID getTableUUID() {
066:                return tableUUID;
067:            }
068:
069:            /**
070:             * Routine to check if another instance of access descriptor matches this.
071:             * Used to ensure only one access descriptor for a table of given privilege is created.
072:             * Otherwise, every column reference from a table may create a descriptor for that table.
073:             *
074:             * @param obj	Another instance of StatementPermission
075:             *
076:             * @return	true if match
077:             */
078:            public boolean equals(Object obj) {
079:                if (obj == null)
080:                    return false;
081:                if (getClass().equals(obj.getClass())) {
082:                    StatementTablePermission other = (StatementTablePermission) obj;
083:                    return privType == other.privType
084:                            && tableUUID.equals(other.tableUUID);
085:                }
086:                return false;
087:            } // end of equals
088:
089:            /**
090:             * Return hash code for this instance
091:             *
092:             * @return	Hashcode
093:             *
094:             */
095:            public int hashCode() {
096:                return privType + tableUUID.hashCode();
097:            }
098:
099:            /**
100:             * @see StatementPermission#check
101:             */
102:            public void check(LanguageConnectionContext lcc,
103:                    String authorizationId, boolean forGrant)
104:                    throws StandardException {
105:                DataDictionary dd = lcc.getDataDictionary();
106:
107:                if (!hasPermissionOnTable(dd, authorizationId, forGrant)) {
108:                    TableDescriptor td = getTableDescriptor(dd);
109:                    throw StandardException
110:                            .newException(
111:                                    forGrant ? SQLState.AUTH_NO_TABLE_PERMISSION_FOR_GRANT
112:                                            : SQLState.AUTH_NO_TABLE_PERMISSION,
113:                                    authorizationId, getPrivName(), td
114:                                            .getSchemaName(), td.getName());
115:                }
116:            } // end of check
117:
118:            protected TableDescriptor getTableDescriptor(DataDictionary dd)
119:                    throws StandardException {
120:                TableDescriptor td = dd.getTableDescriptor(tableUUID);
121:                if (td == null)
122:                    throw StandardException.newException(
123:                            SQLState.AUTH_INTERNAL_BAD_UUID, "table");
124:                return td;
125:            } // end of getTableDescriptor
126:
127:            /*
128:             * Check if authorizationId has permission on the table
129:             */
130:            protected boolean hasPermissionOnTable(DataDictionary dd,
131:                    String authorizationId, boolean forGrant)
132:                    throws StandardException {
133:                return oneAuthHasPermissionOnTable(dd,
134:                        Authorizer.PUBLIC_AUTHORIZATION_ID, forGrant)
135:                        || oneAuthHasPermissionOnTable(dd, authorizationId,
136:                                forGrant);
137:            }
138:
139:            protected boolean oneAuthHasPermissionOnTable(DataDictionary dd,
140:                    String authorizationId, boolean forGrant)
141:                    throws StandardException {
142:                TablePermsDescriptor perms = dd.getTablePermissions(tableUUID,
143:                        authorizationId);
144:                if (perms == null)
145:                    return false;
146:
147:                String priv = null;
148:
149:                switch (privType) {
150:                case Authorizer.SELECT_PRIV:
151:                    priv = perms.getSelectPriv();
152:                    break;
153:                case Authorizer.UPDATE_PRIV:
154:                    priv = perms.getUpdatePriv();
155:                    break;
156:                case Authorizer.REFERENCES_PRIV:
157:                    priv = perms.getReferencesPriv();
158:                    break;
159:                case Authorizer.INSERT_PRIV:
160:                    priv = perms.getInsertPriv();
161:                    break;
162:                case Authorizer.DELETE_PRIV:
163:                    priv = perms.getDeletePriv();
164:                    break;
165:                case Authorizer.TRIGGER_PRIV:
166:                    priv = perms.getTriggerPriv();
167:                    break;
168:                }
169:
170:                return "Y".equals(priv) || (!forGrant) && "y".equals(priv);
171:            } // end of hasPermissionOnTable
172:
173:            /**
174:             * @see StatementPermission#getPermissionDescriptor
175:             */
176:            public PermissionsDescriptor getPermissionDescriptor(String authid,
177:                    DataDictionary dd) throws StandardException {
178:                //if the required type of privilege exists for the given authorizer,
179:                //then pass the permission descriptor for it.
180:                if (oneAuthHasPermissionOnTable(dd, authid, false))
181:                    return dd.getTablePermissions(tableUUID, authid);
182:                else
183:                    return null;
184:            }
185:
186:            /**
187:             * Return privilege needed for this access as string
188:             *
189:             * @return	privilege string
190:             */
191:            public String getPrivName() {
192:                switch (privType) {
193:                case Authorizer.SELECT_PRIV:
194:                    return "select";
195:                case Authorizer.UPDATE_PRIV:
196:                    return "update";
197:                case Authorizer.REFERENCES_PRIV:
198:                    return "references";
199:                case Authorizer.INSERT_PRIV:
200:                    return "insert";
201:                case Authorizer.DELETE_PRIV:
202:                    return "delete";
203:                case Authorizer.TRIGGER_PRIV:
204:                    return "trigger";
205:                }
206:                return "?";
207:            } // end of getPrivName
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.