Source Code Cross Referenced for BasePermission.java in  » Security » acegi-security » org » acegisecurity » acls » domain » 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 » Security » acegi security » org.acegisecurity.acls.domain 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002:         *
003:         * Licensed under the Apache License, Version 2.0 (the "License");
004:         * you may not use this file except in compliance with the License.
005:         * You may obtain a copy of the License at
006:         *
007:         *     http://www.apache.org/licenses/LICENSE-2.0
008:         *
009:         * Unless required by applicable law or agreed to in writing, software
010:         * distributed under the License is distributed on an "AS IS" BASIS,
011:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:         * See the License for the specific language governing permissions and
013:         * limitations under the License.
014:         */
015:        package org.acegisecurity.acls.domain;
016:
017:        import org.acegisecurity.acls.AclFormattingUtils;
018:        import org.acegisecurity.acls.Permission;
019:
020:        import org.springframework.util.Assert;
021:
022:        import java.lang.reflect.Field;
023:
024:        import java.util.HashMap;
025:        import java.util.List;
026:        import java.util.Map;
027:        import java.util.Vector;
028:
029:        /**
030:         * A set of standard permissions.
031:         *
032:         * @author Ben Alex
033:         * @version $Id: BasePermission.java 1868 2007-05-25 02:28:40Z benalex $
034:         */
035:        public final class BasePermission implements  Permission {
036:            //~ Static fields/initializers =====================================================================================
037:
038:            public static final Permission READ = new BasePermission(1 << 0,
039:                    'R'); // 1
040:            public static final Permission WRITE = new BasePermission(1 << 1,
041:                    'W'); // 2
042:            public static final Permission CREATE = new BasePermission(1 << 2,
043:                    'C'); // 4
044:            public static final Permission DELETE = new BasePermission(1 << 3,
045:                    'D'); // 8
046:            public static final Permission ADMINISTRATION = new BasePermission(
047:                    1 << 4, 'A'); // 16
048:            private static Map locallyDeclaredPermissionsByInteger = new HashMap();
049:            private static Map locallyDeclaredPermissionsByName = new HashMap();
050:
051:            static {
052:                Field[] fields = BasePermission.class.getDeclaredFields();
053:
054:                for (int i = 0; i < fields.length; i++) {
055:                    try {
056:                        Object fieldValue = fields[i].get(null);
057:
058:                        if (BasePermission.class.isAssignableFrom(fieldValue
059:                                .getClass())) {
060:                            // Found a BasePermission static field
061:                            BasePermission perm = (BasePermission) fieldValue;
062:                            locallyDeclaredPermissionsByInteger.put(
063:                                    new Integer(perm.getMask()), perm);
064:                            locallyDeclaredPermissionsByName.put(fields[i]
065:                                    .getName(), perm);
066:                        }
067:                    } catch (Exception ignore) {
068:                    }
069:                }
070:            }
071:
072:            //~ Instance fields ================================================================================================
073:
074:            private char code;
075:            private int mask;
076:
077:            //~ Constructors ===================================================================================================
078:
079:            private BasePermission(int mask, char code) {
080:                this .mask = mask;
081:                this .code = code;
082:            }
083:
084:            //~ Methods ========================================================================================================
085:
086:            /**
087:             * Dynamically creates a <code>CumulativePermission</code> or <code>BasePermission</code> representing the
088:             * active bits in the passed mask.
089:             *
090:             * @param mask to build
091:             *
092:             * @return a Permission representing the requested object
093:             */
094:            public static Permission buildFromMask(int mask) {
095:                if (locallyDeclaredPermissionsByInteger
096:                        .containsKey(new Integer(mask))) {
097:                    // The requested mask has an exactly match against a statically-defined BasePermission, so return it
098:                    return (Permission) locallyDeclaredPermissionsByInteger
099:                            .get(new Integer(mask));
100:                }
101:
102:                // To get this far, we have to use a CumulativePermission
103:                CumulativePermission permission = new CumulativePermission();
104:
105:                for (int i = 0; i < 32; i++) {
106:                    int permissionToCheck = 1 << i;
107:
108:                    if ((mask & permissionToCheck) == permissionToCheck) {
109:                        Permission p = (Permission) locallyDeclaredPermissionsByInteger
110:                                .get(new Integer(permissionToCheck));
111:                        Assert
112:                                .state(
113:                                        p != null,
114:                                        "Mask "
115:                                                + permissionToCheck
116:                                                + " does not have a corresponding static BasePermission");
117:                        permission.set(p);
118:                    }
119:                }
120:
121:                return permission;
122:            }
123:
124:            public static Permission[] buildFromMask(int[] masks) {
125:                if ((masks == null) || (masks.length == 0)) {
126:                    return new Permission[] {};
127:                }
128:
129:                List list = new Vector();
130:
131:                for (int i = 0; i < masks.length; i++) {
132:                    list.add(BasePermission.buildFromMask(masks[i]));
133:                }
134:
135:                return (Permission[]) list.toArray(new Permission[] {});
136:            }
137:
138:            public static Permission buildFromName(String name) {
139:                Assert
140:                        .isTrue(locallyDeclaredPermissionsByName
141:                                .containsKey(name), "Unknown permission '"
142:                                + name + "'");
143:
144:                return (Permission) locallyDeclaredPermissionsByName.get(name);
145:            }
146:
147:            public static Permission[] buildFromName(String[] names) {
148:                if ((names == null) || (names.length == 0)) {
149:                    return new Permission[] {};
150:                }
151:
152:                List list = new Vector();
153:
154:                for (int i = 0; i < names.length; i++) {
155:                    list.add(BasePermission.buildFromName(names[i]));
156:                }
157:
158:                return (Permission[]) list.toArray(new Permission[] {});
159:            }
160:
161:            public boolean equals(Object arg0) {
162:                if (!(arg0 instanceof  BasePermission)) {
163:                    return false;
164:                }
165:
166:                BasePermission rhs = (BasePermission) arg0;
167:
168:                return (this .mask == rhs.getMask());
169:            }
170:
171:            public int getMask() {
172:                return mask;
173:            }
174:
175:            public String getPattern() {
176:                return AclFormattingUtils.printBinary(mask, code);
177:            }
178:
179:            public String toString() {
180:                return "BasePermission[" + getPattern() + "=" + mask + "]";
181:            }
182:
183:            public int hashCode() {
184:                return this.mask;
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.