1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.ChangePasswordReply;
27 import org.apache.directory.server.changepw.messages.ChangePasswordReplyModifier;
28 import org.apache.directory.server.kerberos.shared.io.decoder.ApplicationReplyDecoder;
29 import org.apache.directory.server.kerberos.shared.io.decoder.PrivateMessageDecoder;
30 import org.apache.directory.server.kerberos.shared.messages.application.ApplicationReply;
31 import org.apache.directory.server.kerberos.shared.messages.application.PrivateMessage;
32
33
34
35
36
37
38 public class ChangePasswordReplyDecoder
39 {
40 private static final int HEADER_LENGTH = 6;
41
42
43
44
45
46
47
48
49
50 public ChangePasswordReply decode( ByteBuffer buf ) throws IOException
51 {
52 ChangePasswordReplyModifier modifier = new ChangePasswordReplyModifier();
53
54 short messageLength = buf.getShort();
55 short protocolVersion = buf.getShort();
56 short encodedAppReplyLength = buf.getShort();
57
58 modifier.setProtocolVersionNumber( protocolVersion );
59
60 byte[] encodedAppReply = new byte[encodedAppReplyLength];
61 buf.get( encodedAppReply );
62
63 ApplicationReplyDecoder appDecoder = new ApplicationReplyDecoder();
64 ApplicationReply applicationReply = appDecoder.decode( encodedAppReply );
65 modifier.setApplicationReply( applicationReply );
66
67 int privateBytesLength = messageLength - HEADER_LENGTH - encodedAppReplyLength;
68 byte[] encodedPrivateMessage = new byte[privateBytesLength];
69 buf.get( encodedPrivateMessage );
70
71 PrivateMessageDecoder privateDecoder = new PrivateMessageDecoder();
72 PrivateMessage privateMessage = privateDecoder.decode( encodedPrivateMessage );
73 modifier.setPrivateMessage( privateMessage );
74
75 return modifier.getChangePasswordReply();
76 }
77 }