Source Code Cross Referenced for SimpleAclEntry.java in  » Security » acegi-security » org » acegisecurity » acl » basic » 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.acl.basic 
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:
016:        package org.acegisecurity.acl.basic;
017:
018:        import org.apache.commons.logging.Log;
019:        import org.apache.commons.logging.LogFactory;
020:
021:        /**
022:         * Stores some privileges typical of a domain object.
023:         *
024:         * @author Ben Alex
025:         * @version $Id: SimpleAclEntry.java 1784 2007-02-24 21:00:24Z luke_t $
026:         */
027:        public class SimpleAclEntry extends AbstractBasicAclEntry {
028:            //~ Static fields/initializers =====================================================================================
029:
030:            private static final Log logger = LogFactory
031:                    .getLog(SimpleAclEntry.class);
032:
033:            // Base permissions we permit
034:            public static final int NOTHING = 0;
035:            public static final int ADMINISTRATION = (int) Math.pow(2, 0);
036:            public static final int READ = (int) Math.pow(2, 1);
037:            public static final int WRITE = (int) Math.pow(2, 2);
038:            public static final int CREATE = (int) Math.pow(2, 3);
039:            public static final int DELETE = (int) Math.pow(2, 4);
040:
041:            // Combinations of base permissions we permit
042:            public static final int READ_WRITE_CREATE_DELETE = READ | WRITE
043:                    | CREATE | DELETE;
044:            public static final int READ_WRITE_CREATE = READ | WRITE | CREATE;
045:            public static final int READ_WRITE = READ | WRITE;
046:            public static final int READ_WRITE_DELETE = READ | WRITE | DELETE;
047:
048:            // Array required by the abstract superclass via getValidPermissions()
049:            private static final int[] VALID_PERMISSIONS = { NOTHING,
050:                    ADMINISTRATION, READ, WRITE, CREATE, DELETE,
051:                    READ_WRITE_CREATE_DELETE, READ_WRITE_CREATE, READ_WRITE,
052:                    READ_WRITE_DELETE };
053:
054:            private static final String[] VALID_PERMISSIONS_AS_STRING = {
055:                    "NOTHING", "ADMINISTRATION", "READ", "WRITE", "CREATE",
056:                    "DELETE", "READ_WRITE_CREATE_DELETE", "READ_WRITE_CREATE",
057:                    "READ_WRITE", "READ_WRITE_DELETE" };
058:
059:            //~ Constructors ===================================================================================================
060:
061:            /**
062:             * Allows {@link BasicAclDao} implementations to construct this object
063:             * using <code>newInstance()</code>.
064:             *
065:             * <P>
066:             * Normal classes should <B>not</B> use this default constructor.
067:             * </p>
068:             */
069:            public SimpleAclEntry() {
070:                super ();
071:            }
072:
073:            public SimpleAclEntry(Object recipient,
074:                    AclObjectIdentity aclObjectIdentity,
075:                    AclObjectIdentity aclObjectParentIdentity, int mask) {
076:                super (recipient, aclObjectIdentity, aclObjectParentIdentity,
077:                        mask);
078:            }
079:
080:            //~ Methods ========================================================================================================
081:
082:            /**
083:             * @return a copy of the permissions array, changes to the values won't affect this class.
084:             */
085:            public int[] getValidPermissions() {
086:                return (int[]) VALID_PERMISSIONS.clone();
087:            }
088:
089:            public String printPermissionsBlock(int i) {
090:                StringBuffer sb = new StringBuffer();
091:
092:                if (isPermitted(i, ADMINISTRATION)) {
093:                    sb.append('A');
094:                } else {
095:                    sb.append('-');
096:                }
097:
098:                if (isPermitted(i, READ)) {
099:                    sb.append('R');
100:                } else {
101:                    sb.append('-');
102:                }
103:
104:                if (isPermitted(i, WRITE)) {
105:                    sb.append('W');
106:                } else {
107:                    sb.append('-');
108:                }
109:
110:                if (isPermitted(i, CREATE)) {
111:                    sb.append('C');
112:                } else {
113:                    sb.append('-');
114:                }
115:
116:                if (isPermitted(i, DELETE)) {
117:                    sb.append('D');
118:                } else {
119:                    sb.append('-');
120:                }
121:
122:                return sb.toString();
123:            }
124:
125:            /**
126:             * Parse a permission {@link String} literal and return associated value.
127:             *
128:             * @param permission one of the field names that represent a permission: <code>ADMINISTRATION</code>,
129:             * <code>READ</code>, <code>WRITE</code>,...
130:             * @return the value associated to that permission
131:             * @throws IllegalArgumentException if argument is not a valid permission
132:             */
133:            public static int parsePermission(String permission) {
134:                for (int i = 0; i < VALID_PERMISSIONS_AS_STRING.length; i++) {
135:                    if (VALID_PERMISSIONS_AS_STRING[i]
136:                            .equalsIgnoreCase(permission)) {
137:                        return VALID_PERMISSIONS[i];
138:                    }
139:                }
140:                throw new IllegalArgumentException(
141:                        "Permission provided does not exist: " + permission);
142:            }
143:
144:            /**
145:             * Parse a list of permission {@link String} literals and return associated values.
146:             *
147:             * @param permissions array with permissions as {@link String}
148:             * @see #parsePermission(String) for valid values
149:             */
150:            public static int[] parsePermissions(String[] permissions) {
151:                int[] requirepermissionAsIntArray = new int[permissions.length];
152:                for (int i = 0; i < requirepermissionAsIntArray.length; i++) {
153:                    requirepermissionAsIntArray[i] = parsePermission(permissions[i]);
154:                }
155:                return requirepermissionAsIntArray;
156:            }
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.