View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.changepw.io;
21  
22  
23  import java.io.IOException;
24  import java.nio.ByteBuffer;
25  
26  import org.apache.directory.server.changepw.messages.ChangePasswordRequest;
27  import org.apache.directory.server.changepw.messages.ChangePasswordRequestModifier;
28  import org.apache.directory.server.kerberos.shared.io.decoder.ApplicationRequestDecoder;
29  import org.apache.directory.server.kerberos.shared.io.decoder.PrivateMessageDecoder;
30  import org.apache.directory.server.kerberos.shared.messages.ApplicationRequest;
31  import org.apache.directory.server.kerberos.shared.messages.application.PrivateMessage;
32  
33  
34  /**
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   * @version $Rev: 557127 $, $Date: 2007-07-18 05:02:51 +0200 (Mi, 18 Jul 2007) $
37   */
38  public class ChangePasswordRequestDecoder
39  {
40      /**
41       * Decodes a {@link ByteBuffer} into a {@link ChangePasswordRequest}.
42       *
43       * @param buf
44       * @return The {@link ChangePasswordRequest}.
45       * @throws IOException
46       */
47      public ChangePasswordRequest decode( ByteBuffer buf ) throws IOException
48      {
49          ChangePasswordRequestModifier modifier = new ChangePasswordRequestModifier();
50  
51          buf.getShort(); // message length
52  
53          modifier.setProtocolVersionNumber( buf.getShort() );
54  
55          short authHeaderLength = buf.getShort();
56  
57          byte[] undecodedAuthHeader = new byte[authHeaderLength];
58          buf.get( undecodedAuthHeader, 0, authHeaderLength );
59  
60          ApplicationRequestDecoder decoder = new ApplicationRequestDecoder();
61          ApplicationRequest authHeader = decoder.decode( undecodedAuthHeader );
62  
63          modifier.setAuthHeader( authHeader );
64  
65          byte[] encodedPrivate = new byte[buf.remaining()];
66          buf.get( encodedPrivate, 0, buf.remaining() );
67  
68          PrivateMessageDecoder privateDecoder = new PrivateMessageDecoder();
69          PrivateMessage privMessage = privateDecoder.decode( encodedPrivate );
70  
71          modifier.setPrivateMessage( privMessage );
72  
73          return modifier.getChangePasswordMessage();
74      }
75  }