Source Code Cross Referenced for KerberosKeyTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » auth » tests » 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 » org package » org.apache.harmony.auth.tests.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 org.apache.harmony.auth.tests.javax.security.auth.kerberos;
019:
020:        import java.io.ByteArrayOutputStream;
021:        import java.io.IOException;
022:        import java.io.ObjectOutputStream;
023:        import java.util.Arrays;
024:
025:        import javax.security.auth.kerberos.KerberosKey;
026:        import javax.security.auth.kerberos.KerberosPrincipal;
027:
028:        import junit.framework.TestCase;
029:
030:        /**
031:         * Tests KerberosKey class implementation.
032:         * 
033:         * @see http://www.ietf.org/rfc/rfc3961.txt
034:         */
035:        public class KerberosKeyTest extends TestCase {
036:
037:            // principal object for testing
038:            private final KerberosPrincipal principal = new KerberosPrincipal(
039:                    "name@aaa.com", 1);
040:
041:            // byte array for testing
042:            private final byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02,
043:                    0x03, 0x04, 0x05, 0x06, 0x07 };
044:
045:            /**
046:             * @tests javax.security.auth.kerberos.KerberosKey#KerberosKey(
047:             *        javax.security.auth.kerberos.KerberosPrincipal, byte[], int, int)
048:             */
049:            public void test_Ctor1() {
050:
051:                // OK to pass null value for principal parameter
052:                assertNull(new KerberosKey(null, keyBytes, 0, 0).getPrincipal());
053:
054:                // NPE for null keyBytes parameter
055:                try {
056:                    new KerberosKey(principal, null, 0, 0);
057:                    fail("No expected NullPointerException");
058:                } catch (NullPointerException e) {
059:                }
060:
061:                // construct with DES algorithm
062:                KerberosKey key = new KerberosKey(principal, keyBytes, 1, 123);
063:                assertEquals("DES algorithm", "DES", key.getAlgorithm());
064:                assertEquals("version number", 123, key.getVersionNumber());
065:                assertEquals("format", "RAW", key.getFormat());
066:                assertSame("principal", principal, key.getPrincipal());
067:                assertFalse("is destroyed", key.isDestroyed());
068:
069:                // construct with NULL algorithm
070:                key = new KerberosKey(principal, keyBytes, 0, 0);
071:                assertEquals("NULL algorithm", "NULL", key.getAlgorithm());
072:                assertEquals("version number", 0, key.getVersionNumber());
073:            }
074:
075:            /**
076:             * @tests javax.security.auth.kerberos.KerberosKey#KerberosKey(
077:             *        javax.security.auth.kerberos.KerberosPrincipal, char[],
078:             *        java.lang.String)
079:             */
080:            public void test_Ctor2() {
081:
082:                // NPE for null value for principal parameter
083:                try {
084:                    new KerberosKey(null, new char[10], "DES");
085:                    fail("No expected NullPointerException");
086:                } catch (NullPointerException e) {
087:                }
088:
089:                // NPE for null password value
090:                try {
091:                    new KerberosKey(principal, null, "DES");
092:                    fail("No expected NullPointerException");
093:                } catch (NullPointerException e) {
094:                }
095:
096:                // IAE for unsupported algorithm
097:                try {
098:                    new KerberosKey(principal, new char[10],
099:                            "there_is_no_such_algorithm");
100:                    fail("No expected IllegalArgumentException");
101:                } catch (IllegalArgumentException e) {
102:                }
103:
104:                // if algorithm parameter is null then DES is used
105:                KerberosKey key = new KerberosKey(principal, new char[10], null);
106:
107:                assertEquals("algorithm", "DES", key.getAlgorithm());
108:                assertEquals("format", "RAW", key.getFormat());
109:                assertEquals("key type", 3, key.getKeyType());
110:                assertEquals("version number", 0, key.getVersionNumber());
111:                assertFalse("is destroyed", key.isDestroyed());
112:                assertSame("principal", principal, key.getPrincipal());
113:            }
114:
115:            /**
116:             * @tests javax.security.auth.kerberos.KerberosKey#getEncoded()
117:             */
118:            public void test_getEncoded() {
119:
120:                KerberosKey key = new KerberosKey(principal, keyBytes, 1, 123);
121:
122:                byte[] keyBytes1 = key.getEncoded();
123:                assertTrue("encoded", Arrays.equals(keyBytes, keyBytes1));
124:
125:                // bytes are copied each time we invoke the method
126:                assertNotSame("keyBytes immutability 1 ", keyBytes, keyBytes1);
127:                assertNotSame("keyBytes immutability 2 ", keyBytes1, key
128:                        .getEncoded());
129:
130:                // Test generation of DES key from password
131:                // test data from RFC 3961 (http://www.ietf.org/rfc/rfc3961.txt)
132:                // see A.2 test vectors
133:                // test data format: principal/password/DES key
134:                Object[][] testcases = {
135:                        {
136:                                "raeburn@ATHENA.MIT.EDU",
137:                                "password",
138:                                new byte[] { (byte) 0xcb, (byte) 0xc2,
139:                                        (byte) 0x2f, (byte) 0xae, (byte) 0x23,
140:                                        (byte) 0x52, (byte) 0x98, (byte) 0xe3 } },
141:                        {
142:                                "danny@WHITEHOUSE.GOV",
143:                                "potatoe",
144:                                new byte[] { (byte) 0xdf, (byte) 0x3d,
145:                                        (byte) 0x32, (byte) 0xa7, (byte) 0x4f,
146:                                        (byte) 0xd9, (byte) 0x2a, (byte) 0x01 } },
147:                // TODO add "pianist@EXAMPLE.COM" and "Juri ... @ATHENA.MIT.EDU"
148:                };
149:
150:                for (Object[] element : testcases) {
151:                    KerberosPrincipal kp = new KerberosPrincipal(
152:                            (String) element[0], 1);
153:
154:                    key = new KerberosKey(kp, ((String) element[1])
155:                            .toCharArray(), "DES");
156:
157:                    assertTrue("Testcase: " + (String) element[0], Arrays
158:                            .equals((byte[]) element[2], key.getEncoded()));
159:                }
160:            }
161:
162:            /**
163:             * @tests javax.security.auth.kerberos.KerberosKey#destroy()
164:             */
165:            public void test_destroy() throws Exception {
166:
167:                KerberosKey key = new KerberosKey(principal, new char[10],
168:                        "DES");
169:
170:                assertFalse("not destroyed", key.isDestroyed());
171:
172:                key.destroy();
173:                assertTrue("destroyed", key.isDestroyed());
174:
175:                // no exceptions for second destroy() call
176:                key.destroy();
177:
178:                // check that IllegalStateException is thrown for certain methods
179:                try {
180:                    key.getAlgorithm();
181:                    fail("No expected IllegalStateException");
182:                } catch (IllegalStateException e) {
183:                }
184:
185:                try {
186:                    key.getEncoded();
187:                    fail("No expected IllegalStateException");
188:                } catch (IllegalStateException e) {
189:                }
190:
191:                try {
192:                    key.getFormat();
193:                    fail("No expected IllegalStateException");
194:                } catch (IllegalStateException e) {
195:                }
196:
197:                try {
198:                    key.getKeyType();
199:                    fail("No expected IllegalStateException");
200:                } catch (IllegalStateException e) {
201:                }
202:
203:                try {
204:                    key.getPrincipal();
205:                    fail("No expected IllegalStateException");
206:                } catch (IllegalStateException e) {
207:                }
208:
209:                try {
210:                    key.getVersionNumber();
211:                    fail("No expected IllegalStateException");
212:                } catch (IllegalStateException e) {
213:                }
214:
215:                try {
216:                    // but for serialization IOException is expected
217:                    ObjectOutputStream out = new ObjectOutputStream(
218:                            new ByteArrayOutputStream());
219:                    out.writeObject(key);
220:                    fail("No expected IOException");
221:                } catch (IOException e) {
222:                }
223:
224:                try {
225:                    key.toString();
226:                    fail("No expected IllegalStateException");
227:                } catch (IllegalStateException e) {
228:                }
229:            }
230:        }
w__w_w.__j___a___v__a__2_s_._c___o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.