Source Code Cross Referenced for SpNegoToken.java in  » 6.0-JDK-Modules-sun » security » sun » security » jgss » spnego » 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 » 6.0 JDK Modules sun » security » sun.security.jgss.spnego 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package sun.security.jgss.spnego;
027:
028:        import java.io.*;
029:        import java.util.*;
030:        import org.ietf.jgss.*;
031:        import sun.security.util.*;
032:        import sun.security.jgss.*;
033:
034:        /** 
035:         * Astract class for SPNEGO tokens.
036:         * Implementation is based on RFC 2478 
037:         * 
038:         * NegotiationToken ::= CHOICE {
039:         * 	negTokenInit  [0]	 NegTokenInit,
040:         *	negTokenTarg  [1]	 NegTokenTarg }
041:         *
042:         *
043:         * @author Seema Malkani
044:         * @version 1.8, 05/05/07
045:         * @since 1.6
046:         */
047:
048:        abstract class SpNegoToken extends GSSToken {
049:
050:            static final int NEG_TOKEN_INIT_ID = 0x00;
051:            static final int NEG_TOKEN_TARG_ID = 0x01;
052:
053:            static enum NegoResult {
054:                ACCEPT_COMPLETE, ACCEPT_INCOMPLETE, REJECT,
055:            };
056:
057:            private int tokenType;
058:
059:            // property
060:            static final boolean DEBUG = SpNegoContext.DEBUG;
061:
062:            /**
063:             * The object identifier corresponding to the SPNEGO GSS-API
064:             * mechanism.
065:             */
066:            public static ObjectIdentifier OID;
067:
068:            static {
069:                try {
070:                    OID = new ObjectIdentifier(
071:                            SpNegoMechFactory.GSS_SPNEGO_MECH_OID.toString());
072:                } catch (IOException ioe) {
073:                    // should not happen
074:                }
075:            }
076:
077:            /**
078:             * Creates SPNEGO token of the specified type.
079:             */
080:            protected SpNegoToken(int tokenType) {
081:                this .tokenType = tokenType;
082:            }
083:
084:            /**
085:             * Returns the individual encoded SPNEGO token
086:             *
087:             * @return the encoded token 
088:             * @exception GSSException
089:             */
090:            abstract byte[] encode() throws GSSException;
091:
092:            /**
093:             * Returns the encoded SPNEGO token
094:             * Note: inserts the required CHOICE tags
095:             *
096:             * @return the encoded token
097:             * @exception GSSException
098:             */
099:            byte[] getEncoded() throws IOException, GSSException {
100:
101:                // get the token encoded value
102:                DerOutputStream token = new DerOutputStream();
103:                token.write(encode());
104:
105:                // now insert the CHOICE
106:                switch (tokenType) {
107:                case NEG_TOKEN_INIT_ID:
108:                    // Insert CHOICE of Negotiation Token
109:                    DerOutputStream initToken = new DerOutputStream();
110:                    initToken.write(DerValue.createTag(DerValue.TAG_CONTEXT,
111:                            true, (byte) NEG_TOKEN_INIT_ID), token);
112:                    return initToken.toByteArray();
113:
114:                case NEG_TOKEN_TARG_ID:
115:                    // Insert CHOICE of Negotiation Token
116:                    DerOutputStream targToken = new DerOutputStream();
117:                    targToken.write(DerValue.createTag(DerValue.TAG_CONTEXT,
118:                            true, (byte) NEG_TOKEN_TARG_ID), token);
119:                    return targToken.toByteArray();
120:                default:
121:                    return token.toByteArray();
122:                }
123:            }
124:
125:            /**
126:             * Returns the SPNEGO token type
127:             *
128:             * @return the token type
129:             */
130:            final int getType() {
131:                return tokenType;
132:            }
133:
134:            /**
135:             * Returns a string representing the token type.
136:             *
137:             * @param tokenType the token type for which a string name is desired
138:             * @return the String name of this token type
139:             */
140:            static String getTokenName(int type) {
141:                switch (type) {
142:                case NEG_TOKEN_INIT_ID:
143:                    return "SPNEGO NegTokenInit";
144:                case NEG_TOKEN_TARG_ID:
145:                    return "SPNEGO NegTokenTarg";
146:                default:
147:                    return "SPNEGO Mechanism Token";
148:                }
149:            }
150:
151:            /**
152:             * Returns the enumerated type of the Negotiation result.
153:             *
154:             * @param result the negotiated result represented by integer
155:             * @return the enumerated type of Negotiated result
156:             */
157:            static NegoResult getNegoResultType(int result) {
158:                switch (result) {
159:                case 0:
160:                    return NegoResult.ACCEPT_COMPLETE;
161:                case 1:
162:                    return NegoResult.ACCEPT_INCOMPLETE;
163:                case 2:
164:                    return NegoResult.REJECT;
165:                default:
166:                    // unknown - return optimistic result
167:                    return NegoResult.ACCEPT_COMPLETE;
168:                }
169:            }
170:
171:            /**
172:             * Returns a string representing the negotiation result.
173:             *
174:             * @param result the negotiated result
175:             * @return the String message of this negotiated result
176:             */
177:            static String getNegoResultString(int result) {
178:                switch (result) {
179:                case 0:
180:                    return "Accept Complete";
181:                case 1:
182:                    return "Accept InComplete";
183:                case 2:
184:                    return "Reject";
185:                default:
186:                    return ("Unknown Negotiated Result: " + result);
187:                }
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.