Source Code Cross Referenced for ServicePermission.java in  » Apache-Harmony-Java-SE » javax-package » javax » security » auth » kerberos » 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 » Apache Harmony Java SE » javax package » javax.security.auth.kerberos 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package javax.security.auth.kerberos;
019:
020:        import java.io.IOException;
021:        import java.io.Serializable;
022:        import java.security.Permission;
023:        import java.security.PermissionCollection;
024:
025:        import org.apache.harmony.auth.internal.nls.Messages;
026:
027:        public final class ServicePermission extends Permission implements 
028:                Serializable {
029:
030:            private static final long serialVersionUID = -1227585031618624935L;
031:
032:            private static final String INITIATE = "initiate"; //$NON-NLS-1$
033:            private static final String ACCEPT = "accept"; //$NON-NLS-1$
034:            private static final String INITIATE_ACCEPT = "initiate,accept"; //$NON-NLS-1$
035:            private static final String[] ACTIONS_TABLE = {
036:                    "", ACCEPT, INITIATE, INITIATE_ACCEPT }; //$NON-NLS-1$
037:
038:            private final static char ACCEPT_MASK = 1;
039:            private final static char INITIATE_MASK = 2;
040:
041:            private static final int INITIATE_LEN = INITIATE.length();
042:            private static final int ACCEPT_LEN = ACCEPT.length();
043:            private static final int MIN_LEN = Math.min(INITIATE_LEN,
044:                    ACCEPT_LEN);
045:
046:            /** 
047:             * ACCEPT_MASK, INITIATE_ACCEPT or (INITIATE_ACCEPT | ACCEPT_MASK)
048:             */
049:            private String actions;
050:
051:            // initialization of actions
052:            private void initActions(String actions) {
053:                if (actions == null || actions.length() < MIN_LEN) {
054:                    throw new IllegalArgumentException(Messages
055:                            .getString("auth.2E")); //$NON-NLS-1$
056:                }
057:
058:                char[] c_acts = actions.toCharArray();
059:
060:                int result = 0;
061:                int ptr = 0;
062:
063:                int len6 = c_acts.length - ACCEPT_LEN;
064:                int len8 = c_acts.length - INITIATE_LEN;
065:
066:                do {
067:                    //skipping whitespaces
068:                    while (ptr <= len6
069:                            && (c_acts[ptr] == ' ' || c_acts[ptr] == '\t'
070:                                    || c_acts[ptr] == '\n'
071:                                    || c_acts[ptr] == 0x0B
072:                                    || c_acts[ptr] == '\f' || c_acts[ptr] == '\r')) {
073:                        ++ptr;
074:                    }
075:
076:                    if (ptr > len6) {
077:                        // expect string "accept" or "initiate", not just white
078:                        // spaces
079:                        throw new IllegalArgumentException(Messages
080:                                .getString("auth.2E")); //$NON-NLS-1$
081:                    }
082:
083:                    //parsing string
084:                    if ((c_acts[ptr] == 'a' || c_acts[ptr] == 'A')
085:                            && (c_acts[ptr + 1] == 'c' || c_acts[ptr + 1] == 'C')
086:                            && (c_acts[ptr + 2] == 'c' || c_acts[ptr + 2] == 'C')
087:                            && (c_acts[ptr + 3] == 'e' || c_acts[ptr + 3] == 'E')
088:                            && (c_acts[ptr + 4] == 'p' || c_acts[ptr + 4] == 'P')
089:                            && (c_acts[ptr + 5] == 't' || c_acts[ptr + 5] == 'T')) {
090:                        result |= ACCEPT_MASK;
091:                        ptr += ACCEPT_LEN;
092:                    } else if (ptr <= len8
093:                            && (c_acts[ptr] == 'i' || c_acts[ptr] == 'I')
094:                            && (c_acts[ptr + 1] == 'n' || c_acts[ptr + 1] == 'N')
095:                            && (c_acts[ptr + 2] == 'i' || c_acts[ptr + 2] == 'I')
096:                            && (c_acts[ptr + 3] == 't' || c_acts[ptr + 3] == 'T')
097:                            && (c_acts[ptr + 4] == 'i' || c_acts[ptr + 4] == 'I')
098:                            && (c_acts[ptr + 5] == 'a' || c_acts[ptr + 5] == 'A')
099:                            && (c_acts[ptr + 6] == 't' || c_acts[ptr + 6] == 'T')
100:                            && (c_acts[ptr + 7] == 'e' || c_acts[ptr + 7] == 'E')) {
101:                        result |= INITIATE_MASK;
102:                        ptr += INITIATE_LEN;
103:                    } else {
104:                        throw new IllegalArgumentException(Messages
105:                                .getString("auth.2E")); //$NON-NLS-1$
106:                    }
107:
108:                    //skipping trailing whitespaces
109:                    while (ptr < c_acts.length
110:                            && (c_acts[ptr] == ' ' || c_acts[ptr] == '\t'
111:                                    || c_acts[ptr] == '\n'
112:                                    || c_acts[ptr] == 0x0B
113:                                    || c_acts[ptr] == '\f' || c_acts[ptr] == '\r')) {
114:                        ptr++;
115:                    }
116:
117:                    if (ptr == c_acts.length) {
118:                        this .actions = ACTIONS_TABLE[result];
119:                        return;
120:                    }
121:                } while (c_acts[ptr++] == ',');
122:
123:                // unknown trailing symbol
124:                throw new IllegalArgumentException(Messages
125:                        .getString("auth.2E")); //$NON-NLS-1$
126:            }
127:
128:            public ServicePermission(String name, String actions) {
129:                super (name);
130:
131:                initActions(actions);
132:
133:                if (name == null) {
134:                    throw new NullPointerException(Messages
135:                            .getString("auth.2F")); //$NON-NLS-1$
136:                }
137:                if (name.trim().length() == 0) {
138:                    throw new IllegalArgumentException(Messages
139:                            .getString("auth.30")); //$NON-NLS-1$
140:                }
141:            }
142:
143:            @Override
144:            public boolean equals(Object obj) {
145:                if (this  == obj) {
146:                    return true;
147:                }
148:
149:                if (obj == null || ServicePermission.class != obj.getClass()) {
150:                    return false;
151:                }
152:                ServicePermission sp = (ServicePermission) obj;
153:
154:                return actions == sp.actions && getName().equals(sp.getName());
155:            }
156:
157:            @Override
158:            public int hashCode() {
159:                return getName().hashCode() * actions.length();
160:            }
161:
162:            @Override
163:            public String getActions() {
164:                return actions;
165:            }
166:
167:            @Override
168:            public boolean implies(Permission permission) {
169:                if (this  == permission) {
170:                    return true;
171:                }
172:
173:                if (permission == null
174:                        || ServicePermission.class != permission.getClass()) {
175:                    return false;
176:                }
177:
178:                ServicePermission sp = (ServicePermission) permission;
179:                String name = getName();
180:
181:                return (actions == INITIATE_ACCEPT || actions == sp.actions)
182:                        && (name.length() == 1 && name.charAt(0) == '*' || name
183:                                .equals(permission.getName()));
184:            }
185:
186:            @Override
187:            public PermissionCollection newPermissionCollection() {
188:                return new KrbServicePermissionCollection();
189:            }
190:
191:            private synchronized void writeObject(java.io.ObjectOutputStream s)
192:                    throws IOException {
193:                s.defaultWriteObject();
194:            }
195:
196:            private synchronized void readObject(java.io.ObjectInputStream s)
197:                    throws IOException, ClassNotFoundException {
198:                s.defaultReadObject();
199:                initActions(getActions());
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.