Source Code Cross Referenced for RightOwner.java in  » Database-DBMS » h2database » org » h2 » engine » 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 » h2database » org.h2.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003:         * (http://h2database.com/html/license.html).
004:         * Initial Developer: H2 Group
005:         */
006:        package org.h2.engine;
007:
008:        import java.sql.SQLException;
009:        import java.util.HashMap;
010:        import java.util.Iterator;
011:
012:        import org.h2.constant.ErrorCode;
013:        import org.h2.message.Message;
014:        import org.h2.table.Table;
015:
016:        /**
017:         * A right owner (sometimes called principal).
018:         */
019:        public abstract class RightOwner extends DbObjectBase {
020:
021:            /**
022:             * The map of granted roles.
023:             * The key is the role,
024:             * and the value is the right.
025:             */
026:            private HashMap grantedRoles;
027:
028:            /**
029:             * The map of granted rights.
030:             * The key is the table,
031:             * and the value is the right.
032:             */
033:            private HashMap grantedRights;
034:
035:            protected RightOwner(Database database, int id, String name,
036:                    String traceModule) {
037:                super (database, id, name, traceModule);
038:            }
039:
040:            public boolean isRoleGranted(Role grantedRole) {
041:                if (grantedRole == this ) {
042:                    return true;
043:                }
044:                if (grantedRoles != null) {
045:                    Iterator it = grantedRoles.keySet().iterator();
046:                    while (it.hasNext()) {
047:                        Role role = (Role) it.next();
048:                        if (role == grantedRole) {
049:                            return true;
050:                        }
051:                        if (role.isRoleGranted(grantedRole)) {
052:                            return true;
053:                        }
054:                    }
055:                }
056:                return false;
057:            }
058:
059:            protected boolean isRightGrantedRecursive(Table table, int rightMask) {
060:                Right right;
061:                if (grantedRights != null) {
062:                    right = (Right) grantedRights.get(table);
063:                    if (right != null) {
064:                        if ((right.getRightMask() & rightMask) == rightMask) {
065:                            return true;
066:                        }
067:                    }
068:                }
069:                if (grantedRoles != null) {
070:                    Iterator it = grantedRoles.keySet().iterator();
071:                    while (it.hasNext()) {
072:                        RightOwner role = (RightOwner) it.next();
073:                        if (role.isRightGrantedRecursive(table, rightMask)) {
074:                            return true;
075:                        }
076:                    }
077:                }
078:                return false;
079:            }
080:
081:            public void grantRight(Table table, Right right) {
082:                if (grantedRights == null) {
083:                    grantedRights = new HashMap();
084:                }
085:                grantedRights.put(table, right);
086:            }
087:
088:            public void revokeRight(Table table) {
089:                if (grantedRights == null) {
090:                    return;
091:                }
092:                grantedRights.remove(table);
093:                if (grantedRights.size() == 0) {
094:                    grantedRights = null;
095:                }
096:            }
097:
098:            /**
099:             * Grant a role to this object.
100:             * 
101:             * @param session the session
102:             * @param role the role
103:             * @param right the right to grant
104:             */
105:            public void grantRole(Session session, Role role, Right right) {
106:                if (grantedRoles == null) {
107:                    grantedRoles = new HashMap();
108:                }
109:                grantedRoles.put(role, right);
110:            }
111:
112:            public void revokeRole(Session session, Role role)
113:                    throws SQLException {
114:                if (grantedRoles == null) {
115:                    throw Message.getSQLException(ErrorCode.RIGHT_NOT_FOUND);
116:                }
117:                Right right = (Right) grantedRoles.get(role);
118:                if (right == null) {
119:                    throw Message.getSQLException(ErrorCode.RIGHT_NOT_FOUND);
120:                }
121:                grantedRoles.remove(role);
122:                if (grantedRoles.size() == 0) {
123:                    grantedRoles = null;
124:                }
125:            }
126:
127:            public Right getRightForTable(Table table) {
128:                if (grantedRights == null) {
129:                    return null;
130:                }
131:                return (Right) grantedRights.get(table);
132:            }
133:
134:            public Right getRightForRole(Role role) {
135:                if (grantedRoles == null) {
136:                    return null;
137:                }
138:                return (Right) grantedRoles.get(role);
139:            }
140:
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.