directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1443107 [1/6] - in /directory/apacheds/trunk: interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/ kerberos-codec/ kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/ kerberos-codec/src/mai...
Date Wed, 06 Feb 2013 18:19:39 GMT
Author: kayyagari
Date: Wed Feb  6 18:19:36 2013
New Revision: 1443107

URL: http://svn.apache.org/viewvc?rev=1443107&view=rev
Log:
o decoupled kerberos codec from MINA
o added changepassword server implementation with support for rfc 3244
o fixed EncTimeStamp  preauth
o sorted the default encryption types based on their strength
o removed the ads-kdcprincipal attribute
o fixed tests and compiler errors
o added a new annotation for change password server

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswdErrorType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswordException.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/package-info.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordDecoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordEncoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/package-info.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/AbstractPasswordMessage.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordError.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordReply.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordRequest.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/package-info.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosAttribute.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/ChangePasswdDataContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/ChangePasswdDataGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/ChangePasswdDataStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/actions/ChangePasswdDataInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/actions/StoreNewPassword.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/actions/StoreTargName.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/changePwdData/actions/StoreTargRealm.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/ChangePasswdData.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/ChangePasswdDataDecoderTest.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/ChangePasswordConfig.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/KerberosConfig.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/ChangePasswordServer.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/package-info.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/protocol/
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/protocol/ChangePasswordProtocolCodecFactory.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/protocol/ChangePasswordProtocolHandler.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/protocol/MinaChangePasswordDecoder.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/protocol/MinaChangePasswordEncoder.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/protocol/package-info.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/service/
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/service/ChangePasswordContext.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/service/ChangePasswordService.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/changepwd/service/package-info.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/kdc/DirectoryPrincipalStore.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/codec/
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosProtocolCodecFactory.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/codec/MinaKerberosDecoder.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/codec/MinaKerberosEncoder.java
    directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/kerberos/
    directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/kerberos/GetPrincipal.java
    directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/kerberos/StoreUtils.java
    directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateChngPwdServer.java
Removed:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosProtocolCodecFactory.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/DirectoryPrincipalStore.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/KerberosAttribute.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/KerberosCatalog.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/
Modified:
    directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java
    directory/apacheds/trunk/kerberos-codec/pom.xml
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosDecoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosEncoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/crypto/encryption/KerberosKeyFactory.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/KeytabDecoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/KeytabEncoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/replay/ReplayCache.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/PrincipalStore.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/PrincipalStoreEntryModifier.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosTime.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosUtils.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/types/PaDataType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/ETypeInfo2Entry.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReqBody.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/Authenticator.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/keytab/KeytabTest.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/server/kerberos/shared/replay/ReplayCacheImplTest.java
    directory/apacheds/trunk/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/AbstractKerberosITest.java
    directory/apacheds/trunk/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/SaslGssapiBindITest.java
    directory/apacheds/trunk/protocol-kerberos/pom.xml
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/kdc/KdcContext.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/kdc/KdcServer.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/kdc/authentication/AuthenticationService.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/kdc/ticketgrant/TicketGrantingService.java
    directory/apacheds/trunk/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosProtocolHandler.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/AbstractAuthenticationServiceTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/AbstractTicketGrantingServiceTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/AuthenticationEncryptionTypeTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/AuthenticationPolicyTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/AuthenticationServiceTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/EncTktInSkeyTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/MapPrincipalStoreImpl.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/PreAuthenticationTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/TicketGrantingEncryptionTypeTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/TicketGrantingPolicyTest.java
    directory/apacheds/trunk/protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/TicketGrantingServiceTest.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/bind/gssapi/GssapiCallbackHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/bind/gssapi/GssapiMechanismHandler.java
    directory/apacheds/trunk/protocol-shared/pom.xml
    directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateKdcServer.java
    directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateLdapServer.java
    directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
    directory/apacheds/trunk/server-annotations/src/test/java/org/apache/directory/server/factory/CreateKdcServerAnnotationTest.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/ChangePasswordServerBean.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/KdcServerBean.java
    directory/apacheds/trunk/server-config/src/main/resources/config.ldif
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/kerberos/KeyDerivationServiceIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
    directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java
    directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/ApacheDsService.java

Modified: directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java?rev=1443107&r1=1443106&r2=1443107&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java (original)
+++ directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java Wed Feb  6 18:19:36 2013
@@ -50,7 +50,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory;
 import org.apache.directory.server.kerberos.shared.crypto.encryption.RandomKeyFactory;
-import org.apache.directory.server.kerberos.shared.store.KerberosAttribute;
+import org.apache.directory.shared.kerberos.KerberosAttribute;
 import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
 import org.apache.directory.shared.kerberos.components.EncryptionKey;
 import org.apache.directory.shared.kerberos.exceptions.KerberosException;

Modified: directory/apacheds/trunk/kerberos-codec/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/pom.xml?rev=1443107&r1=1443106&r2=1443107&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/pom.xml (original)
+++ directory/apacheds/trunk/kerberos-codec/pom.xml Wed Feb  6 18:19:36 2013
@@ -40,24 +40,9 @@
 
     <dependency>
       <groupId>${project.groupId}</groupId>
-      <artifactId>apacheds-core-api</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>${project.groupId}</groupId>
       <artifactId>apacheds-i18n</artifactId>
     </dependency>
-    
-    <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>apacheds-protocol-shared</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.apache.mina</groupId>
-      <artifactId>mina-core</artifactId>
-    </dependency>
-    
+            
     <dependency>
       <groupId>org.apache.directory.api</groupId>
       <artifactId>api-asn1-api</artifactId>
@@ -67,7 +52,7 @@
       <groupId>org.apache.directory.api</groupId>
       <artifactId>api-asn1-ber</artifactId>
     </dependency>
-    
+        
     <dependency>
       <groupId>org.apache.directory.api</groupId>
       <artifactId>api-i18n</artifactId>

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswdErrorType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswdErrorType.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswdErrorType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswdErrorType.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,146 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.directory.server.kerberos.changepwd.exceptions;
+
+
+/**
+ * Type safe enumeration of Change Password error types
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum ChangePasswdErrorType
+{
+    // TODO Add i18n. Don't no if these error messages are also a response to the client.
+    // If so shall they really be i18n?
+
+    /**
+     * Constant for the "Request failed due to being malformed" error type.
+     */
+    KRB5_KPASSWD_MALFORMED(1, "Request failed due to being malformed."),
+
+    /**
+     * Constant for the "Request failed due to a hard error in processing the request" error type.
+     */
+    KRB5_KPASSWD_HARDERROR(2, "Request failed due to a hard error in processing the request."),
+
+    /**
+     * Constant for the "Request failed due to an error in authentication processing" error type.
+     */
+    KRB5_KPASSWD_AUTHERROR(3, "Request failed due to an error in authentication processing."),
+
+    /**
+     * Constant for the "Request failed due to a soft error in processing the request" error type.
+     */
+    KRB5_KPASSWD_SOFTERROR(4, "Request failed due to a soft error in processing the request."),
+
+    /**
+     * Constant for the "Requestor not authorized" error type.
+     */
+    KRB5_KPASSWD_ACCESSDENIED(5, "Requestor not authorized."),
+
+    /**
+     * Constant for the "Protocol version unsupported" error type.
+     */
+    KRB5_KPASSWD_BAD_VERSION(6, "Protocol version unsupported."),
+
+    /**
+     * Constant for the "Initial flag required" error type.
+     */
+    KRB5_KPASSWD_INITIAL_FLAG_NEEDED(7, "Initial flag required."),
+
+    /**
+     * Constant for the "Request failed for an unknown reason" error type.
+     */
+    KRB5_KPASSWD_UNKNOWN_ERROR(8, "Request failed for an unknown reason.");
+
+    /**
+     * The name of the error type.
+     */
+    private final String name;
+
+    /**
+     * The value/code for the error type.
+     */
+    private final int value;
+
+
+    /**
+     * Private constructor prevents construction outside of this class.
+     */
+    private ChangePasswdErrorType( int value, String name )
+    {
+        this.value = value;
+        this.name = name;
+    }
+
+
+    /**
+     * Returns the message for this Change Password error.
+     *
+     * @return the message for this Change Password error.
+     */
+    public String getMessage()
+    {
+        return name;
+    }
+
+
+    /**
+     * Returns the message for this Change Password error.
+     *
+     * @return the message for this Change Password error.
+     */
+    public String toString()
+    {
+        return name;
+    }
+
+
+    /**
+     * Gets the error type by its value.
+     *
+     * @param value the value of the error
+     * @return the type corresponding to the value
+     */
+    public static ChangePasswdErrorType getTypeByValue( int value )
+    {
+        for ( ChangePasswdErrorType et : ChangePasswdErrorType.values() )
+        {
+            if ( value == et.getValue() )
+            {
+                return et;
+            }
+        }
+
+        return KRB5_KPASSWD_UNKNOWN_ERROR;
+    }
+
+
+    /**
+     * Gets the value associated with this Change Password error.
+     *
+     * @return the value associated with this Change Password error
+     */
+    public int getValue()
+    {
+        return value;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswordException.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswordException.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswordException.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/ChangePasswordException.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.directory.server.kerberos.changepwd.exceptions;
+
+
+import org.apache.directory.shared.kerberos.exceptions.KerberosException;
+
+
+/**
+ * The root of the Change Password exception hierarchy.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ChangePasswordException extends KerberosException
+{
+    private static final long serialVersionUID = 4880242751298831543L;
+
+
+    /**
+     * Creates a ChangePasswordException with an {@link ChangePasswdErrorType}.
+     *
+     * @param errorType The {@link ChangePasswdErrorType} associated with this ChangePasswordException.
+     */
+    public ChangePasswordException( ChangePasswdErrorType errorType )
+    {
+        super( errorType.getValue(), errorType.getMessage() );
+    }
+
+    
+    /**
+     * Creates a new instance of ChangePasswordException.
+     *
+     * @param errorType the error type
+     * @param message the message
+     */
+    public ChangePasswordException( ChangePasswdErrorType errorType, String message )
+    {
+        super( errorType.getValue(), message );
+    }
+
+    
+    /**
+     * Creates a ChangePasswordException with an {@link ChangePasswdErrorType} and an
+     * underlying throwable that caused this fault.
+     *
+     * @param errorType The {@link ChangePasswdErrorType} associated with this ChangePasswordException.
+     * @param cause The underlying failure, if any.
+     */
+    public ChangePasswordException( ChangePasswdErrorType errorType, Throwable cause )
+    {
+        super( errorType.getValue(), errorType.getMessage(), cause );
+    }
+
+
+    /**
+     * Creates a ChangePasswordException with an {@link ChangePasswdErrorType} and
+     * data helping to explain what caused this fault.
+     *
+     * @param errorType The {@link ChangePasswdErrorType} associated with this ChangePasswordException.
+     * @param explanatoryData Data helping to explain this fault, if any.
+     */
+    public ChangePasswordException( ChangePasswdErrorType errorType, byte[] explanatoryData )
+    {
+        super( errorType.getValue(), errorType.getMessage(), explanatoryData );
+    }
+
+
+    /**
+     * Creates a ChangePasswordException with an {@link ChangePasswdErrorType}, data helping to explain
+     * what caused this fault, and an underlying throwable that caused this fault.
+     *
+     * @param errorType The error type associated with this ChangePasswordException.
+     * @param explanatoryData Data helping to explain this fault, if any.
+     * @param cause The underlying failure, if any.
+     */
+    public ChangePasswordException( ChangePasswdErrorType errorType, byte[] explanatoryData, Throwable cause )
+    {
+        super( errorType.getValue(), errorType.getMessage(), explanatoryData, cause );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/package-info.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/package-info.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/package-info.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/exceptions/package-info.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,28 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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. 
+ *  
+ */
+
+/**
+ * Provides the root of the exception hierarchy, as well as the
+ * enumerator for mapping Change Password errors to error codes.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+
+package org.apache.directory.server.kerberos.changepwd.exceptions;

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordDecoder.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordDecoder.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordDecoder.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,60 @@
+
+package org.apache.directory.server.kerberos.changepwd.io;
+
+import java.nio.ByteBuffer;
+import java.nio.InvalidMarkException;
+
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswordException;
+import org.apache.directory.server.kerberos.changepwd.messages.AbstractPasswordMessage;
+import org.apache.directory.server.kerberos.changepwd.messages.ChangePasswordError;
+import org.apache.directory.server.kerberos.changepwd.messages.ChangePasswordReply;
+import org.apache.directory.server.kerberos.changepwd.messages.ChangePasswordRequest;
+
+public class ChangePasswordDecoder
+{
+    public static AbstractPasswordMessage decode( ByteBuffer buf, boolean isTcp ) throws ChangePasswordException
+    {
+        if ( isTcp )
+        {
+            // For TCP transport, there is a 4 octet header in network byte order
+            // that precedes the message and specifies the length of the message.
+            buf.getInt();
+            buf.mark();
+        }
+        
+        // cause we don't have a special message type value, try decoding as request, reply and error and send whichever succeeds
+        
+        try
+        {
+            return ChangePasswordRequest.decode( buf );
+        }
+        catch( Exception e )
+        {
+            resetOrRewind( buf );
+        }
+        
+        try
+        {
+            return ChangePasswordReply.decode( buf );
+        }
+        catch( Exception e )
+        {
+            resetOrRewind( buf );
+        }
+        
+        return ChangePasswordError.decode( buf );
+    }
+    
+    
+    private static void resetOrRewind( ByteBuffer buf )
+    {
+        try
+        {
+            buf.reset();
+        }
+        catch( InvalidMarkException e )
+        {
+            buf.rewind();
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordEncoder.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordEncoder.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/ChangePasswordEncoder.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,31 @@
+
+package org.apache.directory.server.kerberos.changepwd.io;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.kerberos.changepwd.messages.AbstractPasswordMessage;
+import org.apache.directory.api.asn1.EncoderException;
+
+public class ChangePasswordEncoder
+{
+    public static ByteBuffer encode( AbstractPasswordMessage chngPwdMsg, boolean isTcp ) throws EncoderException
+    {
+        int len = chngPwdMsg.computeLength();
+        
+        ByteBuffer buf;
+        if( isTcp )
+        {
+            buf = ByteBuffer.allocate( len + 4 );
+            buf.putInt( len );
+        }
+        else
+        {
+            buf = ByteBuffer.allocate( len );
+        }
+        
+        buf = chngPwdMsg.encode( buf );
+        buf.flip();
+        
+        return buf;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/package-info.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/package-info.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/package-info.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/io/package-info.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,28 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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. 
+ *  
+ */
+
+/**
+ * Provides encoders and decoders for request, reply, error, and data
+ * payload conversions.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+
+package org.apache.directory.server.kerberos.changepwd.io;

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/AbstractPasswordMessage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/AbstractPasswordMessage.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/AbstractPasswordMessage.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/AbstractPasswordMessage.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.directory.server.kerberos.changepwd.messages;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.EncoderException;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+abstract public class AbstractPasswordMessage
+{
+    /**
+     * ChangePassword protocol version number.
+     */
+    public static final short PVNO = (short) 0xFF80;
+
+    public static final short OLD_PVNO = 1;
+    
+    static final int HEADER_LENGTH = 6;
+    
+    private short versionNumber;
+
+
+    protected AbstractPasswordMessage( short versionNumber )
+    {
+        this.versionNumber = versionNumber;
+    }
+
+
+    /**
+     * Returns the version number.
+     *
+     * @return The version number.
+     */
+    public short getVersionNumber()
+    {
+        return versionNumber;
+    }
+    
+    public abstract short computeLength();
+    
+    public abstract ByteBuffer encode( ByteBuffer buf ) throws EncoderException;
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordError.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordError.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordError.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordError.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,154 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.directory.server.kerberos.changepwd.messages;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswdErrorType;
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswordException;
+import org.apache.directory.shared.kerberos.codec.krbError.KrbErrorContainer;
+import org.apache.directory.shared.kerberos.messages.KrbError;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ChangePasswordError extends AbstractPasswordMessage
+{
+    private KrbError krbError;
+
+    private short krbErrorLen;
+    private short messageLength;
+
+    public ChangePasswordError( KrbError krbError )
+    {
+        this( PVNO, krbError );
+    }
+    
+    /**
+     * Creates a new instance of ChangePasswordError.
+     *
+     * @param versionNumber
+     * @param krbError The KRB-ERROR
+     */
+    public ChangePasswordError( short versionNumber, KrbError krbError )
+    {
+        super( versionNumber );
+
+        this.krbError = krbError;
+    }
+
+
+    /**
+     * Returns the {@link KrbError}.
+     *
+     * @return The {@link KrbError}.
+     */
+    public KrbError getKrbError()
+    {
+        return krbError;
+    }
+
+
+    @Override
+    public short computeLength()
+    {
+        krbErrorLen = ( short ) krbError.computeLength();
+        messageLength = ( short ) ( HEADER_LENGTH + krbErrorLen );
+        
+        return messageLength;
+    }
+
+    @Override
+    public ByteBuffer encode( ByteBuffer buf ) throws EncoderException
+    {
+        buf.putShort( messageLength );
+
+        buf.putShort( getVersionNumber() );
+
+        buf.putShort( ( short )0 ); // zero means, what follows is an error
+
+        krbError.encode( buf );
+        
+        return buf;
+    }
+
+    /**
+     * Decodes a {@link ByteBuffer} into a {@link ChangePasswordError}.
+     *
+     * @param buf
+     * @return The {@link ChangePasswordError}.
+     * @throws ChangePasswordException
+     */
+    public static ChangePasswordError decode( ByteBuffer buf ) throws ChangePasswordException
+    {
+        short messageLength = buf.getShort();
+
+        short pvno = buf.getShort();
+
+        // AP_REQ length will be 0 for error messages
+        buf.getShort(); // authHeader length
+
+        int errorLength = messageLength - HEADER_LENGTH;
+
+        byte[] errorBytes = new byte[errorLength];
+
+        buf.get( errorBytes );
+        ByteBuffer errorBuffer = ByteBuffer.wrap( errorBytes );
+        errorBuffer.flip();
+
+        KrbErrorContainer container = new KrbErrorContainer( errorBuffer );
+        Asn1Decoder decoder = new Asn1Decoder();
+
+        try
+        {
+            decoder.decode( errorBuffer, container );
+        }
+        catch( DecoderException e )
+        {
+            throw new ChangePasswordException( ChangePasswdErrorType.KRB5_KPASSWD_MALFORMED, e );
+        }
+        
+        KrbError errorMessage = container.getKrbError();
+
+        return new ChangePasswordError( pvno, errorMessage );
+    }
+
+    public ChangePasswdErrorType getResultCode()
+    {
+        ByteBuffer buf = ByteBuffer.wrap( krbError.getEData() );
+        
+        return ChangePasswdErrorType.getTypeByValue( buf.getShort() );
+    }
+    
+    public String getResultString()
+    {
+        byte[] edata = krbError.getEData();
+
+        // first two bytes contain the result code
+        return Strings.utf8ToString( edata, 2, edata.length - 2 );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordReply.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordReply.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordReply.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordReply.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,150 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.directory.server.kerberos.changepwd.messages;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswdErrorType;
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswordException;
+import org.apache.directory.server.kerberos.protocol.codec.KerberosDecoder;
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.shared.kerberos.exceptions.KerberosException;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+import org.apache.directory.shared.kerberos.messages.KrbPriv;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ChangePasswordReply extends AbstractPasswordMessage
+{
+    private ApRep applicationReply;
+    private KrbPriv privateMessage;
+
+    private short applicationReplyLen ;
+    private short privateMessageLen;
+    private short messageLength;
+
+    public ChangePasswordReply( ApRep applicationReply, KrbPriv privateMessage )
+    {
+        this( PVNO, applicationReply, privateMessage );
+    }
+    
+    
+    /**
+     * Creates a new instance of ChangePasswordReply.
+     *
+     * @param versionNumber
+     * @param applicationReply
+     * @param privateMessage
+     */
+    public ChangePasswordReply( short versionNumber, ApRep applicationReply, KrbPriv privateMessage )
+    {
+        super( versionNumber );
+
+        this.applicationReply = applicationReply;
+        this.privateMessage = privateMessage;
+    }
+
+
+    /**
+     * Returns the {@link ApplicationReply}.
+     *
+     * @return The {@link ApplicationReply}.
+     */
+    public ApRep getApplicationReply()
+    {
+        return applicationReply;
+    }
+
+
+    /**
+     * Returns the {@link PrivateMessage}.
+     *
+     * @return The {@link PrivateMessage}.
+     */
+    public KrbPriv getPrivateMessage()
+    {
+        return privateMessage;
+    }
+
+
+    @Override
+    public short computeLength()
+    {
+        applicationReplyLen = ( short ) applicationReply.computeLength();
+        privateMessageLen = ( short ) privateMessage.computeLength();
+        
+        messageLength = ( short ) ( HEADER_LENGTH + applicationReplyLen + privateMessageLen );
+        
+        return messageLength;
+    }
+
+
+    @Override
+    public ByteBuffer encode( ByteBuffer buf ) throws EncoderException
+    {
+        buf.putShort( messageLength );
+        buf.putShort( getVersionNumber() );
+        buf.putShort( applicationReplyLen );
+        
+        applicationReply.encode( buf );
+        privateMessage.encode( buf );
+        
+        return buf;
+    }
+
+    
+    /**
+     * Decodes a {@link ByteBuffer} into a {@link ChangePasswordReply}.
+     *
+     * @param buf
+     * @return The {@link ChangePasswordReply}.
+     * @throws KerberosException
+     */
+    public static ChangePasswordReply decode( ByteBuffer buf ) throws ChangePasswordException
+    {
+        try
+        {
+            short messageLength = buf.getShort();
+            short protocolVersion = buf.getShort();
+            short encodedAppReplyLength = buf.getShort();
+            
+            byte[] encodedAppReply = new byte[encodedAppReplyLength];
+            buf.get( encodedAppReply );
+            
+            ApRep applicationReply = KerberosDecoder.decodeApRep( encodedAppReply );
+            
+            int privateBytesLength = messageLength - HEADER_LENGTH - encodedAppReplyLength;
+            byte[] encodedPrivateMessage = new byte[privateBytesLength];
+            buf.get( encodedPrivateMessage );
+            
+            KrbPriv privateMessage = KerberosDecoder.decodeKrbPriv( encodedPrivateMessage );
+            
+            return new ChangePasswordReply( protocolVersion, applicationReply, privateMessage );
+        }
+        catch( KerberosException e )
+        {
+            throw new ChangePasswordException( ChangePasswdErrorType.KRB5_KPASSWD_MALFORMED, e );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordRequest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordRequest.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordRequest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/ChangePasswordRequest.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,153 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.directory.server.kerberos.changepwd.messages;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswdErrorType;
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswordException;
+import org.apache.directory.server.kerberos.protocol.codec.KerberosDecoder;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.shared.kerberos.exceptions.KerberosException;
+import org.apache.directory.shared.kerberos.messages.ApReq;
+import org.apache.directory.shared.kerberos.messages.KrbPriv;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ChangePasswordRequest extends AbstractPasswordMessage
+{
+    private ApReq authHeader;
+    private KrbPriv privateMessage;
+
+    private short authHeaderLen;
+    private short privateMessageLen;
+    private short messageLength;
+
+    public ChangePasswordRequest( ApReq authHeader, KrbPriv privateMessage )
+    {
+        this( PVNO, authHeader, privateMessage );
+    }
+    
+    
+    /**
+     * Creates a new instance of ChangePasswordRequest.
+     *
+     * @param versionNumber
+     * @param authHeader
+     * @param privateMessage
+     */
+    public ChangePasswordRequest( short versionNumber, ApReq authHeader, KrbPriv privateMessage )
+    {
+        super( versionNumber );
+
+        this.authHeader = authHeader;
+        this.privateMessage = privateMessage;
+    }
+
+
+    /**
+     * Returns the {@link ApReq}.
+     *
+     * @return The {@link ApReq}.
+     */
+    public ApReq getAuthHeader()
+    {
+        return authHeader;
+    }
+
+
+    /**
+     * Returns the {@link PrivateMessage}.
+     *
+     * @return The {@link PrivateMessage}.
+     */
+    public KrbPriv getPrivateMessage()
+    {
+        return privateMessage;
+    }
+
+    
+    @Override
+    public short computeLength()
+    {
+        authHeaderLen = ( short ) authHeader.computeLength();
+        privateMessageLen = ( short ) privateMessage.computeLength();
+        
+        messageLength = ( short ) ( HEADER_LENGTH + authHeaderLen + privateMessageLen );
+        
+        return messageLength;
+    }
+
+
+    @Override
+    public ByteBuffer encode( ByteBuffer buf ) throws EncoderException
+    {
+        buf.putShort( messageLength );
+        buf.putShort( getVersionNumber() );
+        
+        // Build application request bytes
+        buf.putShort( authHeaderLen );
+        authHeader.encode( buf );
+        
+        privateMessage.encode( buf );
+        
+        return buf;
+    }
+    
+    /**
+     * Decodes a {@link ByteBuffer} into a {@link ChangePasswordRequest}.
+     *
+     * @param buf
+     * @return The {@link ChangePasswordRequest}.
+     * @throws IOException
+     */
+    public static ChangePasswordRequest decode( ByteBuffer buf ) throws ChangePasswordException
+    {
+        try
+        {
+            short msgLen = buf.getShort(); // message length
+            
+            short pvno = buf.getShort();
+            
+            short authHeaderLength = buf.getShort();
+            
+            byte[] undecodedAuthHeader = new byte[authHeaderLength];
+            buf.get( undecodedAuthHeader, 0, authHeaderLength );
+            
+            ApReq authHeader = KerberosDecoder.decodeApReq( undecodedAuthHeader );
+            
+            byte[] encodedPrivate = new byte[buf.remaining()];
+            buf.get( encodedPrivate, 0, buf.remaining() );
+            
+            KrbPriv privMessage = KerberosDecoder.decodeKrbPriv( encodedPrivate );
+            
+            return new ChangePasswordRequest( pvno, authHeader, privMessage );
+        }
+        catch( KerberosException e )
+        {
+            throw new ChangePasswordException( ChangePasswdErrorType.KRB5_KPASSWD_MALFORMED, e );
+        }
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/package-info.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/package-info.java?rev=1443107&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/package-info.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/changepwd/messages/package-info.java Wed Feb  6 18:19:36 2013
@@ -0,0 +1,27 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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. 
+ *  
+ */
+
+/**
+ * Provides message objects for request, reply, and error messages.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+
+package org.apache.directory.server.kerberos.changepwd.messages;

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosDecoder.java?rev=1443107&r1=1443106&r2=1443107&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosDecoder.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosDecoder.java Wed Feb  6 18:19:36 2013
@@ -20,9 +20,10 @@
 package org.apache.directory.server.kerberos.protocol.codec;
 
 
-import java.io.IOException;
 import java.nio.ByteBuffer;
 
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswdErrorType;
+import org.apache.directory.server.kerberos.changepwd.exceptions.ChangePasswordException;
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
@@ -36,6 +37,7 @@ import org.apache.directory.shared.kerbe
 import org.apache.directory.shared.kerberos.codec.encApRepPart.EncApRepPartContainer;
 import org.apache.directory.shared.kerberos.codec.encAsRepPart.EncAsRepPartContainer;
 import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+import org.apache.directory.shared.kerberos.codec.encTgsRepPart.EncTgsRepPartContainer;
 import org.apache.directory.shared.kerberos.codec.encTicketPart.EncTicketPartContainer;
 import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer;
 import org.apache.directory.shared.kerberos.codec.encryptionKey.EncryptionKeyContainer;
@@ -58,12 +60,9 @@ import org.apache.directory.shared.kerbe
 import org.apache.directory.shared.kerberos.messages.Authenticator;
 import org.apache.directory.shared.kerberos.messages.EncApRepPart;
 import org.apache.directory.shared.kerberos.messages.EncAsRepPart;
+import org.apache.directory.shared.kerberos.messages.EncTgsRepPart;
 import org.apache.directory.shared.kerberos.messages.KrbPriv;
 import org.apache.directory.shared.kerberos.messages.Ticket;
-import org.apache.mina.core.buffer.IoBuffer;
-import org.apache.mina.core.session.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -71,7 +70,7 @@ import org.slf4j.LoggerFactory;
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class KerberosDecoder extends ProtocolDecoderAdapter
+public class KerberosDecoder
 {
 
     /** The logger */
@@ -80,28 +79,11 @@ public class KerberosDecoder extends Pro
     /** A speedup for logger */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
-    /** The ASN 1 decoder instance */
-    private Asn1Decoder asn1Decoder = new Asn1Decoder();
 
-    /** the key used while storing message container in the session */
-    private static final String KERBEROS_MESSAGE_CONTAINER = "kerberosMessageContainer";
-
-
-    public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws IOException
+    public static Object decode( KerberosMessageContainer kerberosMessageContainer, Asn1Decoder asn1Decoder ) throws DecoderException
     {
-        ByteBuffer buf = in.buf();
-        KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer ) session
-            .getAttribute( KERBEROS_MESSAGE_CONTAINER );
-
-        if ( kerberosMessageContainer == null )
-        {
-            kerberosMessageContainer = new KerberosMessageContainer();
-            session.setAttribute( KERBEROS_MESSAGE_CONTAINER, kerberosMessageContainer );
-            kerberosMessageContainer.setStream( buf );
-            kerberosMessageContainer.setGathering( true );
-            kerberosMessageContainer.setTCP( !session.getTransportMetadata().isConnectionless() );
-        }
-
+        ByteBuffer buf = kerberosMessageContainer.getStream();
+        
         if ( kerberosMessageContainer.isTCP() )
         {
             if ( buf.remaining() > 4 )
@@ -111,7 +93,7 @@ public class KerberosDecoder extends Pro
             }
             else
             {
-                return;
+                return null;
             }
         }
         else
@@ -124,7 +106,7 @@ public class KerberosDecoder extends Pro
             try
             {
                 asn1Decoder.decode( buf, kerberosMessageContainer );
-
+                
                 if ( kerberosMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
                 {
                     if ( IS_DEBUG )
@@ -132,25 +114,23 @@ public class KerberosDecoder extends Pro
                         LOG.debug( "Decoded KerberosMessage : " + kerberosMessageContainer.getMessage() );
                         buf.mark();
                     }
-
-                    out.write( kerberosMessageContainer.getMessage() );
-
-                    kerberosMessageContainer.clean();
+        
+                    return kerberosMessageContainer.getMessage();
                 }
             }
             catch ( DecoderException de )
             {
+                LOG.warn( "error while decoding", de );
                 buf.clear();
                 kerberosMessageContainer.clean();
-            }
-            catch ( Exception e )
-            {
-                LOG.warn( "error while decoding", e );
+                throw de;
             }
         }
+        
+        return null;
     }
-
-
+    
+    
     /**
      * Decode an EncrytedData structure
      * 
@@ -163,7 +143,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a EncryptedData Container
         Asn1Container encryptedDataContainer = new EncryptedDataContainer();
 
@@ -184,8 +164,8 @@ public class KerberosDecoder extends Pro
 
         return encryptedData;
     }
-
-
+    
+    
     /**
      * Decode an PaEncTsEnc structure
      * 
@@ -198,7 +178,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a PaEncTsEnc Container
         Asn1Container paEncTsEncContainer = new PaEncTsEncContainer();
 
@@ -219,8 +199,8 @@ public class KerberosDecoder extends Pro
 
         return paEncTsEnc;
     }
-
-
+    
+    
     /**
      * Decode an EncApRepPart structure
      * 
@@ -233,7 +213,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a EncApRepPart Container
         Asn1Container encApRepPartContainer = new EncApRepPartContainer( stream );
 
@@ -254,8 +234,8 @@ public class KerberosDecoder extends Pro
 
         return encApRepPart;
     }
-
-
+    
+    
     /**
      * Decode an EncKdcRepPart structure
      * 
@@ -268,7 +248,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a EncKdcRepPart Container
         Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer( stream );
 
@@ -289,8 +269,8 @@ public class KerberosDecoder extends Pro
 
         return encKdcRepPart;
     }
-
-
+    
+    
     /**
      * Decode an EncKrbPrivPart structure
      * 
@@ -303,7 +283,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a EncKrbPrivPart Container
         Asn1Container encKrbPrivPartContainer = new EncKrbPrivPartContainer( stream );
 
@@ -324,8 +304,8 @@ public class KerberosDecoder extends Pro
 
         return encKrbPrivPart;
     }
-
-
+    
+    
     /**
      * Decode an EncTicketPart structure
      * 
@@ -338,7 +318,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a EncTicketPart Container
         Asn1Container encTicketPartContainer = new EncTicketPartContainer( stream );
 
@@ -359,8 +339,8 @@ public class KerberosDecoder extends Pro
 
         return encTicketPart;
     }
-
-
+    
+    
     /**
      * Decode an EncryptionKey structure
      * 
@@ -373,7 +353,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a EncryptionKey Container
         Asn1Container encryptionKeyContainer = new EncryptionKeyContainer();
 
@@ -394,8 +374,8 @@ public class KerberosDecoder extends Pro
 
         return encryptionKey;
     }
-
-
+    
+    
     /**
      * Decode an PrincipalName structure
      * 
@@ -408,7 +388,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a PrincipalName Container
         Asn1Container principalNameContainer = new PrincipalNameContainer();
 
@@ -429,8 +409,8 @@ public class KerberosDecoder extends Pro
 
         return principalName;
     }
-
-
+    
+    
     /**
      * Decode a Ticket structure
      * 
@@ -443,7 +423,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a Ticket Container
         Asn1Container ticketContainer = new TicketContainer( stream );
 
@@ -464,8 +444,8 @@ public class KerberosDecoder extends Pro
 
         return ticket;
     }
-
-
+    
+    
     /**
      * Decode a Authenticator structure
      * 
@@ -478,7 +458,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a Authenticator Container
         Asn1Container authenticatorContainer = new AuthenticatorContainer( stream );
 
@@ -499,8 +479,8 @@ public class KerberosDecoder extends Pro
 
         return authenticator;
     }
-
-
+    
+    
     /**
      * Decode a AuthorizationData structure
      * 
@@ -513,7 +493,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a AuthorizationData Container
         Asn1Container authorizationDataContainer = new AuthorizationDataContainer();
 
@@ -530,13 +510,12 @@ public class KerberosDecoder extends Pro
         }
 
         // get the decoded AuthorizationData
-        AuthorizationData authorizationData = ( ( AuthorizationDataContainer ) authorizationDataContainer )
-            .getAuthorizationData();
+        AuthorizationData authorizationData = ( ( AuthorizationDataContainer ) authorizationDataContainer ).getAuthorizationData();
 
         return authorizationData;
     }
 
-
+    
     /**
      * Decode a AP-REP structure
      * 
@@ -549,7 +528,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a ApRep Container
         Asn1Container apRepContainer = new ApRepContainer( stream );
 
@@ -571,7 +550,7 @@ public class KerberosDecoder extends Pro
         return apRep;
     }
 
-
+    
     /**
      * Decode a AP-REQ structure
      * 
@@ -584,7 +563,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a ApReq Container
         Asn1Container apReqContainer = new ApReqContainer( stream );
 
@@ -606,7 +585,7 @@ public class KerberosDecoder extends Pro
         return apReq;
     }
 
-
+    
     /**
      * Decode a KRB-PRIV structure
      * 
@@ -619,7 +598,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a KrbPriv Container
         Asn1Container krbPrivContainer = new KrbPrivContainer( stream );
 
@@ -640,8 +619,8 @@ public class KerberosDecoder extends Pro
 
         return krbPriv;
     }
-
-
+    
+    
     /**
      * Decode an EncAsRepPart structure
      * 
@@ -654,7 +633,7 @@ public class KerberosDecoder extends Pro
         ByteBuffer stream = ByteBuffer.allocate( data.length );
         stream.put( data );
         stream.flip();
-
+        
         // Allocate a EncAsRepPart Container
         Asn1Container encAsRepPartContainer = new EncAsRepPartContainer( stream );
 
@@ -676,4 +655,38 @@ public class KerberosDecoder extends Pro
         return encAsRepPart;
     }
 
+    
+    /**
+     * Decode an EncTgsRepPart structure
+     * 
+     * @param data The byte array containing the data structure to decode
+     * @return An instance of EncTgsRepPart
+     * @throws KerberosException If the decoding fails
+     */
+    public static EncTgsRepPart decodeEncTgsRepPart( byte[] data ) throws ChangePasswordException
+    {
+        ByteBuffer stream = ByteBuffer.allocate( data.length );
+        stream.put( data );
+        stream.flip();
+        
+        // Allocate a EncTgsRepPart Container
+        Asn1Container encTgsRepPartContainer = new EncTgsRepPartContainer( stream );
+
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        // Decode the EncTgsRepPart PDU
+        try
+        {
+            kerberosDecoder.decode( stream, encTgsRepPartContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw new ChangePasswordException( ChangePasswdErrorType.KRB5_KPASSWD_MALFORMED, de );
+        }
+
+        // get the decoded EncTgsRepPart
+        EncTgsRepPart encTgsRepPart = ( ( EncTgsRepPartContainer ) encTgsRepPartContainer ).getEncTgsRepPart();
+
+        return encTgsRepPart;
+    }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosEncoder.java?rev=1443107&r1=1443106&r2=1443107&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosEncoder.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/codec/KerberosEncoder.java Wed Feb  6 18:19:36 2013
@@ -21,56 +21,48 @@ package org.apache.directory.server.kerb
 
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
 
 import org.apache.directory.api.asn1.AbstractAsn1Object;
 import org.apache.directory.api.asn1.EncoderException;
-import org.apache.mina.core.buffer.IoBuffer;
-import org.apache.mina.core.session.IoSession;
-import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
-import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.directory.api.asn1.util.Asn1StringUtils;
 
 
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class KerberosEncoder extends ProtocolEncoderAdapter
+public class KerberosEncoder
 {
-    public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws IOException
+    public static ByteBuffer encode( AbstractAsn1Object asn1Obj, boolean isTcp ) throws IOException
     {
-        AbstractAsn1Object asn1Obj = ( AbstractAsn1Object ) message;
-        boolean isTcp = !session.getTransportMetadata().isConnectionless();
-        IoBuffer response = null;
-        IoBuffer kerberosMessage = null;
-
+        ByteBuffer response = null;
+        ByteBuffer kerberosMessage = null;
+        
         int responseLength = asn1Obj.computeLength();
-        kerberosMessage = IoBuffer.allocate( responseLength );
-
-        if ( isTcp )
-        {
-            response = IoBuffer.allocate( responseLength + 4 );
-        }
-        else
-        {
-            response = kerberosMessage;
-        }
-
+        kerberosMessage = ByteBuffer.allocate( responseLength );
+        
         try
         {
-            asn1Obj.encode( kerberosMessage.buf() );
+            asn1Obj.encode( kerberosMessage );
 
             if ( isTcp )
-            {
+            { 
+                response = ByteBuffer.allocate( responseLength + 4 );
                 response.putInt( responseLength );
-                response.put( kerberosMessage.buf().array() );
+                response.put( kerberosMessage.array() );
+            }
+            else
+            {
+                response = kerberosMessage;
             }
 
             response.flip();
 
-            out.write( response );
+            return response;
         }
-        catch ( EncoderException e )
+        catch( EncoderException e )
         {
-            throw new IOException( e.getMessage() );
+            throw new IOException(e.getMessage());
         }
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/crypto/encryption/KerberosKeyFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/crypto/encryption/KerberosKeyFactory.java?rev=1443107&r1=1443106&r2=1443107&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/crypto/encryption/KerberosKeyFactory.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/crypto/encryption/KerberosKeyFactory.java Wed Feb  6 18:19:36 2013
@@ -30,6 +30,7 @@ import java.util.Set;
 import javax.security.auth.kerberos.KerberosKey;
 import javax.security.auth.kerberos.KerberosPrincipal;
 
+import org.apache.directory.shared.kerberos.KerberosUtils;
 import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
 import org.apache.directory.shared.kerberos.components.EncryptionKey;
 
@@ -44,7 +45,7 @@ import org.apache.directory.shared.kerbe
 public class KerberosKeyFactory
 {
     /** A map of default encryption types mapped to cipher names. */
-    private static final Map<EncryptionType, String> DEFAULT_CIPHERS;
+    public static final Map<EncryptionType, String> DEFAULT_CIPHERS;
 
     static
     {
@@ -88,22 +89,15 @@ public class KerberosKeyFactory
     public static Map<EncryptionType, EncryptionKey> getKerberosKeys( String principalName, String passPhrase,
         Set<EncryptionType> ciphers )
     {
-        KerberosPrincipal principal = new KerberosPrincipal( principalName );
         Map<EncryptionType, EncryptionKey> kerberosKeys = new HashMap<EncryptionType, EncryptionKey>();
 
         Iterator<EncryptionType> it = ciphers.iterator();
         while ( it.hasNext() )
         {
             EncryptionType encryptionType = it.next();
-            String algorithm = DEFAULT_CIPHERS.get( encryptionType );
-
             try
             {
-                KerberosKey kerberosKey = new KerberosKey( principal, passPhrase.toCharArray(), algorithm );
-                EncryptionKey encryptionKey = new EncryptionKey( encryptionType, kerberosKey.getEncoded(), kerberosKey
-                    .getVersionNumber() );
-
-                kerberosKeys.put( encryptionType, encryptionKey );
+                kerberosKeys.put( encryptionType, string2Key( principalName, passPhrase, encryptionType ) );
             }
             catch ( IllegalArgumentException iae )
             {
@@ -115,4 +109,15 @@ public class KerberosKeyFactory
 
         return kerberosKeys;
     }
+    
+    
+    public static EncryptionKey string2Key( String principalName, String passPhrase, EncryptionType encryptionType )
+    {
+        KerberosPrincipal principal = new KerberosPrincipal( principalName );
+        KerberosKey kerberosKey = new KerberosKey( principal, passPhrase.toCharArray(), KerberosUtils.getAlgoNameFromEncType( encryptionType ) );
+        EncryptionKey encryptionKey = new EncryptionKey( encryptionType, kerberosKey.getEncoded(), kerberosKey
+            .getVersionNumber() );
+        
+        return encryptionKey;
+    }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java?rev=1443107&r1=1443106&r2=1443107&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java Wed Feb  6 18:19:36 2013
@@ -25,13 +25,13 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
 import org.apache.directory.server.i18n.I18n;
-import org.apache.mina.core.buffer.IoBuffer;
 
 
 /**
@@ -66,7 +66,7 @@ public class Keytab
      */
     public static Keytab read( File file ) throws IOException
     {
-        IoBuffer buffer = IoBuffer.wrap( getBytesFromFile( file ) );
+        ByteBuffer buffer = ByteBuffer.wrap( getBytesFromFile( file ) );
         return readKeytab( buffer );
     }
 
@@ -92,7 +92,7 @@ public class Keytab
     public void write( File file ) throws IOException
     {
         KeytabEncoder writer = new KeytabEncoder();
-        IoBuffer buffer = writer.write( keytabVersion, entries );
+        ByteBuffer buffer = writer.write( keytabVersion, entries );
         writeFile( buffer, file );
     }
 
@@ -141,7 +141,7 @@ public class Keytab
      */
     static Keytab read( byte[] bytes )
     {
-        IoBuffer buffer = IoBuffer.wrap( bytes );
+        ByteBuffer buffer = ByteBuffer.wrap( bytes );
         return readKeytab( buffer );
     }
 
@@ -150,7 +150,7 @@ public class Keytab
      * Write the keytab to a {@link ByteBuffer}.
      * @return The buffer.
      */
-    IoBuffer write()
+    ByteBuffer write()
     {
         KeytabEncoder writer = new KeytabEncoder();
         return writer.write( keytabVersion, entries );
@@ -163,7 +163,7 @@ public class Keytab
      * @param buffer
      * @return The keytab.
      */
-    private static Keytab readKeytab( IoBuffer buffer )
+    private static Keytab readKeytab( ByteBuffer buffer )
     {
         KeytabDecoder reader = new KeytabDecoder();
         byte[] keytabVersion = reader.getKeytabVersion( buffer );
@@ -224,22 +224,20 @@ public class Keytab
 
 
     /**
-     * Write the contents of the {@link IoBuffer} to a {@link File}.
+     * Write the contents of the {@link ByteBuffer} to a {@link File}.
      *
      * @param buffer
      * @param file
      * @throws IOException
      */
-    protected void writeFile( IoBuffer buffer, File file ) throws IOException
+    protected void writeFile( ByteBuffer buffer, File file ) throws IOException
     {
         // Set append false to replace existing.
-        FileOutputStream fos = new FileOutputStream( file, false );
-        FileChannel wChannel = fos.getChannel();
+        FileChannel wChannel = new FileOutputStream( file, false ).getChannel();
 
         // Write the bytes between the position and limit.
-        wChannel.write( buffer.buf() );
+        wChannel.write( buffer );
 
         wChannel.close();
-        fos.close();
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/KeytabDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/KeytabDecoder.java?rev=1443107&r1=1443106&r2=1443107&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/KeytabDecoder.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/KeytabDecoder.java Wed Feb  6 18:19:36 2013
@@ -21,17 +21,17 @@ package org.apache.directory.server.kerb
 
 
 import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.directory.shared.kerberos.KerberosTime;
 import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
 import org.apache.directory.shared.kerberos.components.EncryptionKey;
-import org.apache.mina.core.buffer.IoBuffer;
 
 
 /**
- * Decode a {@link IoBuffer} into keytab fields.
+ * Decode a {@link ByteBuffer} into keytab fields.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -41,7 +41,7 @@ class KeytabDecoder
      * Read the keytab 16-bit file format version.  This
      * keytab reader currently only supports version 5.2.
      */
-    byte[] getKeytabVersion( IoBuffer buffer )
+    byte[] getKeytabVersion( ByteBuffer buffer )
     {
         byte[] version = new byte[2];
         buffer.get( version );
@@ -57,7 +57,7 @@ class KeytabDecoder
      * @param buffer
      * @return The keytab entries.
      */
-    List<KeytabEntry> getKeytabEntries( IoBuffer buffer )
+    List<KeytabEntry> getKeytabEntries( ByteBuffer buffer )
     {
         List<KeytabEntry> entries = new ArrayList<KeytabEntry>();
 
@@ -67,7 +67,7 @@ class KeytabDecoder
             byte[] entry = new byte[size];
 
             buffer.get( entry );
-            entries.add( getKeytabEntry( IoBuffer.wrap( entry ) ) );
+            entries.add( getKeytabEntry( ByteBuffer.wrap( entry ) ) );
         }
 
         return entries;
@@ -78,13 +78,13 @@ class KeytabDecoder
      * Reads off a "keytab entry," which consists of a principal name,
      * principal type, key version number, and key material.
      */
-    private KeytabEntry getKeytabEntry( IoBuffer buffer )
+    private KeytabEntry getKeytabEntry( ByteBuffer buffer )
     {
         String principalName = getPrincipalName( buffer );
 
-        long principalType = buffer.getUnsignedInt();
+        long principalType = buffer.getInt();
 
-        long time = buffer.getUnsignedInt();
+        long time = buffer.getInt();
         KerberosTime timeStamp = new KerberosTime( time * 1000 );
 
         byte keyVersion = buffer.get();
@@ -101,9 +101,9 @@ class KeytabDecoder
      * @param buffer
      * @return The principal name.
      */
-    private String getPrincipalName( IoBuffer buffer )
+    private String getPrincipalName( ByteBuffer buffer )
     {
-        int count = buffer.getUnsignedShort();
+        int count = buffer.getShort();
 
         // decrement for v1
         String realm = getCountedString( buffer );
@@ -131,9 +131,9 @@ class KeytabDecoder
     /**
      * Read off a 16-bit encryption type and symmetric key material.
      */
-    private EncryptionKey getKeyBlock( IoBuffer buffer )
+    private EncryptionKey getKeyBlock( ByteBuffer buffer )
     {
-        int type = buffer.getUnsignedShort();
+        int type = buffer.getShort();
         byte[] keyblock = getCountedBytes( buffer );
 
         EncryptionType encryptionType = EncryptionType.getTypeByValue( type );
@@ -147,9 +147,9 @@ class KeytabDecoder
      * Use a prefixed 16-bit length to read off a String.  Realm and name
      * components are ASCII encoded text with no zero terminator.
      */
-    private String getCountedString( IoBuffer buffer )
+    private String getCountedString( ByteBuffer buffer )
     {
-        int length = buffer.getUnsignedShort();
+        int length = buffer.getShort();
         byte[] data = new byte[length];
         buffer.get( data );
 
@@ -168,9 +168,9 @@ class KeytabDecoder
     /**
      * Use a prefixed 16-bit length to read off raw bytes.
      */
-    private byte[] getCountedBytes( IoBuffer buffer )
+    private byte[] getCountedBytes( ByteBuffer buffer )
     {
-        int length = buffer.getUnsignedShort();
+        int length = buffer.getShort();
         byte[] data = new byte[length];
         buffer.get( data );
 



Mime
View raw message