directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r557143 - in /directory/apacheds/trunk: kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/ protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/
Date Wed, 18 Jul 2007 04:14:39 GMT
Author: erodriguez
Date: Tue Jul 17 21:14:38 2007
New Revision: 557143

URL: http://svn.apache.org/viewvc?view=rev&rev=557143
Log:
Added support for encoding target principal in anticipation of Set Password support.

Modified:
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java
    directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java

Modified: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java?view=diff&rev=557143&r1=557142&r2=557143
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java
Tue Jul 17 21:14:38 2007
@@ -26,6 +26,7 @@
 
 import javax.security.auth.kerberos.KerberosPrincipal;
 
+import org.apache.directory.server.kerberos.shared.messages.value.PrincipalName;
 import org.apache.directory.shared.asn1.der.DERGeneralString;
 import org.apache.directory.shared.asn1.der.DERInteger;
 import org.apache.directory.shared.asn1.der.DERSequence;
@@ -43,13 +44,15 @@
 
 
     /**
+     * Encodes a {@link KerberosPrincipal} into a {@link DERSequence}.
+     * 
      * PrincipalName ::=   SEQUENCE {
      *               name-type[0]     INTEGER,
      *               name-string[1]   SEQUENCE OF GeneralString
      * }
      * 
      * @param principal 
-     * @return The {@link DERSequence}. 
+     * @return The {@link DERSequence}.
      */
     public static DERSequence encode( KerberosPrincipal principal )
     {
@@ -62,9 +65,26 @@
     }
 
 
+    /**
+     * Encodes a {@link PrincipalName} into a {@link DERSequence}.
+     *
+     * @param name
+     * @return The {@link DERSequence}.
+     */
+    public static DERSequence encode( PrincipalName name )
+    {
+        DERSequence vector = new DERSequence();
+
+        vector.add( new DERTaggedObject( 0, DERInteger.valueOf( name.getNameType() ) ) );
+        vector.add( new DERTaggedObject( 1, encodeNameSequence( name ) ) );
+
+        return vector;
+    }
+
+
     private static DERSequence encodeNameSequence( KerberosPrincipal principal )
     {
-        Iterator it = getNameStrings( principal ).iterator();
+        Iterator<String> it = getNameStrings( principal ).iterator();
 
         DERSequence vector = new DERSequence();
 
@@ -77,10 +97,32 @@
     }
 
 
-    private static List getNameStrings( KerberosPrincipal principal )
+    private static List<String> getNameStrings( KerberosPrincipal principal )
     {
         String nameComponent = principal.getName().split( REALM_SEPARATOR )[0];
         String[] components = nameComponent.split( COMPONENT_SEPARATOR );
+        return Arrays.asList( components );
+    }
+
+
+    private static DERSequence encodeNameSequence( PrincipalName name )
+    {
+        Iterator<String> it = getNameStrings( name ).iterator();
+
+        DERSequence vector = new DERSequence();
+
+        while ( it.hasNext() )
+        {
+            vector.add( DERGeneralString.valueOf( ( String ) it.next() ) );
+        }
+
+        return vector;
+    }
+
+
+    private static List<String> getNameStrings( PrincipalName name )
+    {
+        String[] components = name.getNameComponent().split( COMPONENT_SEPARATOR );
         return Arrays.asList( components );
     }
 }

Modified: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java?view=diff&rev=557143&r1=557142&r2=557143
==============================================================================
--- directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java
(original)
+++ directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java
Tue Jul 17 21:14:38 2007
@@ -20,14 +20,12 @@
 package org.apache.directory.server.changepw.io;
 
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
-import javax.security.auth.kerberos.KerberosPrincipal;
-
 import org.apache.directory.server.changepw.value.ChangePasswordData;
 import org.apache.directory.server.kerberos.shared.io.encoder.PrincipalNameEncoder;
-import org.apache.directory.server.kerberos.shared.messages.value.PrincipalName;
 import org.apache.directory.shared.asn1.der.ASN1OutputStream;
 import org.apache.directory.shared.asn1.der.DERGeneralString;
 import org.apache.directory.shared.asn1.der.DEROctetString;
@@ -42,6 +40,27 @@
 public class ChangePasswordDataEncoder
 {
     /**
+     * Encodes a {@link ChangePasswordData} into a byte array.
+     *
+     * @param data
+     * @return The byte array.
+     * @throws IOException
+     */
+    public byte[] encode( ChangePasswordData data ) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ASN1OutputStream aos = new ASN1OutputStream( baos );
+
+        DERSequence dataSequence = encodeDataSequence( data );
+        aos.writeObject( dataSequence );
+
+        aos.close();
+
+        return baos.toByteArray();
+    }
+
+
+    /**
      * Encodes a {@link ChangePasswordData} into a {@link ByteBuffer}.
      *
      * @param data
@@ -64,11 +83,17 @@
         DERSequence sequence = new DERSequence();
         sequence.add( new DERTaggedObject( 0, new DEROctetString( data.getPassword() ) )
);
 
-        PrincipalName name = data.getPrincipalName();
-        KerberosPrincipal principal = new KerberosPrincipal( name.getNameComponent(), name.getNameType()
);
-        sequence.add( new DERTaggedObject( 1, PrincipalNameEncoder.encode( principal ) )
);
-
-        sequence.add( new DERTaggedObject( 2, DERGeneralString.valueOf( data.getRealm() )
) );
+        // OPTIONAL
+        if ( data.getPrincipalName() != null )
+        {
+            sequence.add( new DERTaggedObject( 1, PrincipalNameEncoder.encode( data.getPrincipalName()
) ) );
+        }
+
+        // OPTIONAL
+        if ( data.getRealm() != null )
+        {
+            sequence.add( new DERTaggedObject( 2, DERGeneralString.valueOf( data.getRealm()
) ) );
+        }
 
         return sequence;
     }



Mime
View raw message