directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1369250 - in /directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc: AbstractKerberosITest.java KerberosTcpITest.java KerberosUdpITest.java
Date Fri, 03 Aug 2012 23:30:51 GMT
Author: gokturk
Date: Fri Aug  3 23:30:51 2012
New Revision: 1369250

URL: http://svn.apache.org/viewvc?rev=1369250&view=rev
Log:
Merged with fixes on kerberos-test to run without touching sun jdk's private field.

Modified:
    directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/AbstractKerberosITest.java
    directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java
    directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosUdpITest.java

Modified: directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/AbstractKerberosITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/AbstractKerberosITest.java?rev=1369250&r1=1369249&r2=1369250&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/AbstractKerberosITest.java
(original)
+++ directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/AbstractKerberosITest.java
Fri Aug  3 23:30:51 2012
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertEqu
 
 import java.io.File;
 import java.io.IOException;
-import java.lang.reflect.Field;
+import java.io.UTFDataFormatException;
 import java.util.Collections;
 
 import javax.security.auth.Subject;
@@ -114,31 +114,24 @@ public class AbstractKerberosITest exten
     protected void testObtainTickets( ObtainTicketParameters parameters ) throws Exception
     {
         setupEnv( parameters );
-        try
-        {
-            Subject subject = new Subject();
+        Subject subject = new Subject();
 
-            KerberosTestUtils.obtainTGT( subject, USER_UID, USER_PASSWORD );
+        KerberosTestUtils.obtainTGT( subject, USER_UID, USER_PASSWORD );
 
-            assertEquals( 1, subject.getPrivateCredentials().size() );
-            assertEquals( 0, subject.getPublicCredentials().size() );
+        assertEquals( 1, subject.getPrivateCredentials().size() );
+        assertEquals( 0, subject.getPublicCredentials().size() );
 
-            KerberosTestUtils.obtainServiceTickets( subject, USER_UID, LDAP_SERVICE_NAME,
HOSTNAME );
+        KerberosTestUtils.obtainServiceTickets( subject, USER_UID, LDAP_SERVICE_NAME, HOSTNAME
);
 
-            assertEquals( 2, subject.getPrivateCredentials().size() );
-            assertEquals( 0, subject.getPublicCredentials().size() );
-            for ( KerberosTicket kt : subject.getPrivateCredentials( KerberosTicket.class
) )
-            {
-                // System.out.println( kt.getClient() );
-                // System.out.println( kt.getServer() );
-                // System.out.println( kt.getSessionKeyType() );
-                assertEquals( parameters.encryptionType.getValue(), kt.getSessionKeyType()
);
-            }
-            // System.out.println( subject );
-        }
-        finally
+        assertEquals( 2, subject.getPrivateCredentials().size() );
+        assertEquals( 0, subject.getPublicCredentials().size() );
+
+        for ( KerberosTicket kt : subject.getPrivateCredentials( KerberosTicket.class ) )
         {
-            resetEnv( parameters );
+            // System.out.println( kt.getClient() );
+            // System.out.println( kt.getServer() );
+            // System.out.println( kt.getSessionKeyType() );
+            assertEquals( parameters.encryptionType.getValue(), kt.getSessionKeyType() );
         }
     }
 
@@ -154,22 +147,14 @@ public class AbstractKerberosITest exten
     protected void setupEnv( ObtainTicketParameters parameters )
         throws Exception
     {
-        // Save current value of sun.security.krb5.KrbKdcReq.udpPrefLimit field.
-        // Then set it to -1/1 to force UDP/TCP.
-        parameters.oldUdpPrefLimit = getUdpPrefLimit();
-        setUdpPrefLimit( parameters.transport == TcpTransport.class ? 1 : -1 );
-
-        // Save current value of sun.security.krb5.Checksum.CKSUMTYPE_DEFAULT field.
-        // Then set it to the required checksum value
-        parameters.oldCksumtypeDefault = getCksumtypeDefault();
-        setCksumtypeDefault( parameters.checksumType.getValue() );
-
         // create krb5.conf with proper encryption type
-        String krb5confPath = createKrb5Conf( parameters.encryptionType );
+        String krb5confPath = createKrb5Conf( parameters.checksumType, parameters.encryptionType,
+            parameters.transport == TcpTransport.class );
         System.setProperty( "java.security.krb5.conf", krb5confPath );
 
         // change encryption type in KDC
-        kdcServer.setEncryptionTypes( Collections.singleton( parameters.encryptionType )
);
+        kdcServer.setEncryptionTypes( new EncryptionType[]
+            { parameters.encryptionType } );
 
         // create principals
         createPrincipal( "uid=" + USER_UID, "Last", "First Last",
@@ -184,78 +169,6 @@ public class AbstractKerberosITest exten
     }
 
 
-    protected void resetEnv( ObtainTicketParameters parameters )
-        throws Exception
-    {
-        setUdpPrefLimit( parameters.oldUdpPrefLimit );
-        setCksumtypeDefault( parameters.oldCksumtypeDefault );
-    }
-
-
-    private static Integer getUdpPrefLimit() throws Exception
-    {
-        Field udpPrefLimitField = getUdpPrefLimitField();
-        Object value = udpPrefLimitField.get( null );
-        return ( Integer ) value;
-    }
-
-
-    private static void setUdpPrefLimit( int limit ) throws Exception
-    {
-        Field udpPrefLimitField = getUdpPrefLimitField();
-        udpPrefLimitField.setAccessible( true );
-        udpPrefLimitField.set( null, limit );
-    }
-
-
-    private static Field getUdpPrefLimitField() throws ClassNotFoundException, NoSuchFieldException
-    {
-        String clazz = "sun.security.krb5.KrbKdcReq";
-        Class<?> krbKdcReqClass = Class.forName( clazz );
-
-        // Absolutely ugly fix to get this method working with the latest JVM on Mac (1.6.0_29)
-        Field udpPrefLimitField = null;
-
-        try
-        {
-            udpPrefLimitField = krbKdcReqClass.getDeclaredField( "udpPrefLimit" );
-        }
-        catch ( NoSuchFieldException nsfe )
-        {
-            udpPrefLimitField = krbKdcReqClass.getDeclaredField( "defaultUdpPrefLimit" );
-        }
-
-        udpPrefLimitField.setAccessible( true );
-        return udpPrefLimitField;
-    }
-
-
-    private static Integer getCksumtypeDefault() throws Exception
-    {
-        Field cksumtypeDefaultField = getCksumtypeDefaultField();
-        Object value = cksumtypeDefaultField.get( null );
-        return ( Integer ) value;
-    }
-
-
-    private static void setCksumtypeDefault( int limit ) throws Exception
-    {
-        Field cksumtypeDefaultField = getCksumtypeDefaultField();
-        cksumtypeDefaultField.setAccessible( true );
-        cksumtypeDefaultField.set( null, limit );
-    }
-
-
-    private static Field getCksumtypeDefaultField() throws ClassNotFoundException, NoSuchFieldException
-    {
-        String clazz = "sun.security.krb5.Checksum";
-        Class<?> checksumClass = Class.forName( clazz );
-        Field cksumtypeDefaultField = checksumClass.getDeclaredField( "CKSUMTYPE_DEFAULT"
);
-        cksumtypeDefaultField.setAccessible( true );
-        return cksumtypeDefaultField;
-    }
-
-
     /**
      * Creates the krb5.conf file for the test.
      * 
@@ -283,7 +196,8 @@ public class AbstractKerberosITest exten
      * @return the path to the krb5.conf file
      * @throws IOException
      */
-    private String createKrb5Conf( EncryptionType encryptionType ) throws IOException
+    private String createKrb5Conf( ChecksumType checksumType, EncryptionType encryptionType,
boolean isTcp )
+        throws IOException
     {
         File file = folder.newFile( "krb5.conf" );
 
@@ -296,7 +210,12 @@ public class AbstractKerberosITest exten
         data += "permitted_enctypes = " + encryptionType.getName() + SystemUtils.LINE_SEPARATOR;
         //        data += "default_checksum = " + checksumType.getName() + SystemUtils.LINE_SEPARATOR;
         //        data += "ap_req_checksum_type = " + checksumType.getName() + SystemUtils.LINE_SEPARATOR;
-        //        data += "checksum_type = " + checksumType.getName() + SystemUtils.LINE_SEPARATOR;
+        data += "default-checksum_type = " + checksumType.getName() + SystemUtils.LINE_SEPARATOR;
+
+        if ( isTcp )
+        {
+            data += "udp_preference_limit = 1" + SystemUtils.LINE_SEPARATOR;
+        }
 
         data += "[realms]" + SystemUtils.LINE_SEPARATOR;
         data += REALM + " = {" + SystemUtils.LINE_SEPARATOR;

Modified: directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java?rev=1369250&r1=1369249&r2=1369250&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java
(original)
+++ directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java
Fri Aug  3 23:30:51 2012
@@ -40,8 +40,8 @@ import org.junit.runner.RunWith;
  * Tests to obtain TGTs and Service Tickets from KDCs via TCP.
  * 
  * We use some internal knowledge of the Sun/Oracle implementation here to force
- * the usage of TCP and checksum: 
- * <li>In sun.security.krb5.KrbKdcReq the static field udpPrefLimit is set to 1 
+ * the usage of TCP and checksum:
+ * <li>In sun.security.krb5.KrbKdcReq the static field udpPrefLimit is set to 1
  * which means that TCP is always used.
  * <li>In sun.security.krb5.Checksum the static field CKSUMTYPE_DEFAULT is set
  * to the appropriate checksum value.
@@ -52,25 +52,25 @@ Project</a>
 @RunWith(FrameworkRunner.class)
 @CreateDS(name = "KerberosTcpIT-class",
     partitions =
-       {
-           @CreatePartition(
-               name = "example",
-               suffix = "dc=example,dc=com")
-       },
-       additionalInterceptors =
-       {
-               KeyDerivationInterceptor.class
-       })
+        {
+            @CreatePartition(
+                name = "example",
+                suffix = "dc=example,dc=com")
+    },
+    additionalInterceptors =
+        {
+            KeyDerivationInterceptor.class
+    })
 @CreateLdapServer(
     transports =
-   {
-       @CreateTransport(protocol = "LDAP")
-   })
+        {
+            @CreateTransport(protocol = "LDAP")
+    })
 @CreateKdcServer(
     transports =
-   {
-       @CreateTransport(protocol = "TCP")
-   })
+        {
+            @CreateTransport(protocol = "TCP", port = 6086)
+    })
 @ApplyLdifFiles("org/apache/directory/server/kerberos/kdc/KerberosIT.ldif")
 public class KerberosTcpITest extends AbstractKerberosITest
 {
@@ -82,7 +82,7 @@ public class KerberosTcpITest extends Ab
     @Test
     public void testObtainTickets_DES_CBC_MD5() throws Exception
     {
-        // TODO: rsa-md5-des 
+        // TODO: rsa-md5-des
         // RFC3961, Section 6.2.1: des-cbc-md5 + rsa-md5-des
         ObtainTicketParameters parameters = new ObtainTicketParameters( TcpTransport.class,
             EncryptionType.DES_CBC_MD5, ChecksumType.RSA_MD5 );

Modified: directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosUdpITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosUdpITest.java?rev=1369250&r1=1369249&r2=1369250&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosUdpITest.java
(original)
+++ directory/apacheds/branches/apacheds-txns/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosUdpITest.java
Fri Aug  3 23:30:51 2012
@@ -51,25 +51,26 @@ import org.junit.runner.RunWith;
 @RunWith(FrameworkRunner.class)
 @CreateDS(name = "KerberosUdpIT-class",
     partitions =
-       {
-           @CreatePartition(
-               name = "example",
-               suffix = "dc=example,dc=com")
-       },
-       additionalInterceptors =
-       {
-               KeyDerivationInterceptor.class
-       })
+        {
+            @CreatePartition(
+                name = "example",
+                suffix = "dc=example,dc=com")
+    },
+    additionalInterceptors =
+        {
+            KeyDerivationInterceptor.class
+    })
 @CreateLdapServer(
     transports =
-   {
-       @CreateTransport(protocol = "LDAP")
-   })
+        {
+            @CreateTransport(protocol = "LDAP")
+    })
 @CreateKdcServer(
     transports =
-   {
-       @CreateTransport(protocol = "UDP")
-   })
+        {
+            @CreateTransport(protocol = "TCP", port = 6087),
+            @CreateTransport(protocol = "UDP", port = 6087)
+    })
 @ApplyLdifFiles("org/apache/directory/server/kerberos/kdc/KerberosIT.ldif")
 public class KerberosUdpITest extends AbstractKerberosITest
 {
@@ -82,7 +83,7 @@ public class KerberosUdpITest extends Ab
     public void testObtainTickets_DES_CBC_MD5() throws Exception
     {
         // TODO: RFC3961, Section 6.2.1: des-cbc-md5 + rsa-md5-des
-        ObtainTicketParameters parameters = new ObtainTicketParameters( UdpTransport.class,

+        ObtainTicketParameters parameters = new ObtainTicketParameters( UdpTransport.class,
             EncryptionType.DES_CBC_MD5, ChecksumType.RSA_MD5 );
         testObtainTickets( parameters );
     }



Mime
View raw message