You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/05/05 14:41:50 UTC
svn commit: r400065 - in
/incubator/harmony/enhanced/classlib/trunk/modules/auth/src:
main/java/common/javax/security/auth/kerberos/KerberosKey.java
test/java/common/javax/security/auth/kerberos/KerberosKeyTest.java
Author: smishura
Date: Fri May 5 05:41:49 2006
New Revision: 400065
URL: http://svn.apache.org/viewcvs?rev=400065&view=rev
Log:
Improving KerberosKey constructors + adding regression tests
Added:
incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/javax/security/auth/kerberos/KerberosKeyTest.java (with props)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java?rev=400065&r1=400064&r2=400065&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java Fri May 5 05:41:49 2006
@@ -60,13 +60,13 @@
*/
public KerberosKey(KerberosPrincipal principal, byte[] keyBytes,
int keyType, int versionNumber) {
- //TODO: is a principal mutable ?
- this.principal = principal;
- this.versionNum = versionNumber;
-
+
if (keyBytes == null) {
- throw new IllegalArgumentException("key is null");
+ throw new NullPointerException("key is null");
}
+
+ this.principal = principal;
+ this.versionNum = versionNumber;
this.key = new KeyImpl(keyBytes, keyType);
@@ -77,6 +77,9 @@
*/
public KerberosKey(KerberosPrincipal principal, char[] password,
String algorithm) {
+
+ this.principal = principal;
+
this.key = new KeyImpl(principal, password, algorithm);
}
@@ -198,15 +201,17 @@
*/
public KeyImpl(KerberosPrincipal principal, char[] password, String algorithm) {
- //TODO: need to read a key from a Kerberos "keytab".
- throw new UnsupportedOperationException ();
-/* if (principal == null || password == null || algorithm == null) {
+ if (principal == null || password == null) {
throw new NullPointerException();
}
- this.principal = principal;
- this.password = (char[])password.clone();
- this.algorithm = algorithm;
-*/
+
+ if (algorithm != null && "DES".compareTo(algorithm) != 0) {
+ throw new IllegalArgumentException("Unsupported algorithm");
+ }
+
+ keyType = 3; // DES algorithm
+
+ //FIXME: implement grenerating key from password
}
/**
@@ -215,8 +220,9 @@
*/
public final String getAlgorithm() {
checkState();
- //TODO: if algoritm is null then return "DES"
- // else return another algoritm
+ if (keyType == 0) {
+ return "NULL";
+ }
return "DES";
}
Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/javax/security/auth/kerberos/KerberosKeyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/javax/security/auth/kerberos/KerberosKeyTest.java?rev=400065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/javax/security/auth/kerberos/KerberosKeyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/javax/security/auth/kerberos/KerberosKeyTest.java Fri May 5 05:41:49 2006
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package javax.security.auth.kerberos;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests KerberosKey class implementation.
+ */
+public class KerberosKeyTest extends TestCase {
+
+ // principal object for testing
+ private final KerberosPrincipal principal = new KerberosPrincipal(
+ "name@aaa.com", 1);
+
+ // byte array for testing
+ private final byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07 };
+
+ /**
+ * @tests javax.security.auth.kerberos.KerberosKey#KerberosKey(
+ * javax.security.auth.kerberos.KerberosPrincipal, byte[], int, int)
+ */
+ public void test_Ctor1() {
+
+ // OK to pass null value for principal parameter
+ assertNull(new KerberosKey(null, keyBytes, 0, 0).getPrincipal());
+
+ // NPE for null keyBytes parameter
+ try {
+ new KerberosKey(principal, null, 0, 0);
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+
+ // construct with DES algorithm
+ KerberosKey key = new KerberosKey(principal, keyBytes, 1, 123);
+ assertEquals("DES algorithm", "DES", key.getAlgorithm());
+ assertEquals("version number", 123, key.getVersionNumber());
+ assertEquals("format", "RAW", key.getFormat());
+ assertSame("principal", principal, key.getPrincipal());
+ assertFalse("is destroyed", key.isDestroyed());
+
+ // construct with NULL algorithm
+ key = new KerberosKey(principal, keyBytes, 0, 0);
+ assertEquals("NULL algorithm", "NULL", key.getAlgorithm());
+ assertEquals("version number", 0, key.getVersionNumber());
+ }
+
+ /**
+ * @tests javax.security.auth.kerberos.KerberosKey#KerberosKey(
+ * javax.security.auth.kerberos.KerberosPrincipal, char[],
+ * java.lang.String)
+ */
+ public void test_Ctor2() {
+
+ // NPE for null value for principal parameter
+ try {
+ new KerberosKey(null, new char[10], "DES");
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+
+ // NPE for null password value
+ try {
+ new KerberosKey(principal, null, "DES");
+ fail("No expected NullPointerException");
+ } catch (NullPointerException e) {
+ }
+
+ // IAE for unsupported algorithm
+ try {
+ new KerberosKey(principal, new char[10],
+ "there_is_no_such_algorithm");
+ fail("No expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // if algorithm parameter is null then DES is used
+ KerberosKey key = new KerberosKey(principal, new char[10], null);
+
+ assertEquals("algorithm", "DES", key.getAlgorithm());
+ assertEquals("format", "RAW", key.getFormat());
+ assertEquals("key type", 3, key.getKeyType());
+ assertEquals("version number", 0, key.getVersionNumber());
+ assertFalse("is destroyed", key.isDestroyed());
+ assertSame("principal", principal, key.getPrincipal());
+ }
+
+ /**
+ * @tests javax.security.auth.kerberos.KerberosKey#getEncoded()
+ */
+ public void test_getEncoded() {
+
+ KerberosKey key = new KerberosKey(principal, keyBytes, 1, 123);
+
+ byte[] keyBytes1 = key.getEncoded();
+ assertTrue("encoded", Arrays.equals(keyBytes, keyBytes1));
+
+ // bytes are copied each time we invoke the method
+ assertNotSame("keyBytes immutability 1 ", keyBytes, keyBytes1);
+ assertNotSame("keyBytes immutability 2 ", keyBytes1, key.getEncoded());
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(KerberosKeyTest.class);
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/javax/security/auth/kerberos/KerberosKeyTest.java
------------------------------------------------------------------------------
svn:eol-style = native