1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.codec.factory;
21
22 import org.apache.directory.api.asn1.ber.tlv.BerValue;
23 import org.apache.directory.api.asn1.util.Asn1Buffer;
24 import org.apache.directory.api.ldap.codec.api.LdapApiService;
25 import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
26 import org.apache.directory.api.ldap.model.message.BindRequest;
27 import org.apache.directory.api.ldap.model.message.Message;
28 import org.apache.directory.api.ldap.model.name.Dn;
29 import org.apache.directory.api.util.Strings;
30
31
32
33
34
35
36 public final class BindRequestFactory implements Messagefactory
37 {
38
39 public static final BindRequestFactory INSTANCE = new BindRequestFactory();
40
41 private BindRequestFactory()
42 {
43
44 }
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 @Override
63 public void encodeReverse( LdapApiService codec, Asn1Buffer buffer, Message message )
64 {
65 int start = buffer.getPos();
66 BindRequest bindMessage = ( BindRequest ) message;
67
68
69 if ( bindMessage.isSimple() )
70 {
71
72 BerValue.encodeOctetString( buffer, ( byte ) LdapCodecConstants.BIND_REQUEST_SIMPLE_TAG,
73 bindMessage.getCredentials() );
74 }
75 else
76 {
77
78
79 if ( !Strings.isEmpty( bindMessage.getCredentials() ) )
80 {
81 BerValue.encodeOctetString( buffer, bindMessage.getCredentials() );
82 }
83
84
85 BerValue.encodeOctetString( buffer, bindMessage.getSaslMechanism() );
86
87
88 BerValue.encodeSequence( buffer, ( byte ) LdapCodecConstants.BIND_REQUEST_SASL_TAG, start );
89 }
90
91
92 Dn dn = bindMessage.getDn();
93
94 if ( !Dn.isNullOrEmpty( dn ) )
95 {
96
97 BerValue.encodeOctetString( buffer, dn.getName() );
98 }
99 else
100 {
101
102 BerValue.encodeOctetString( buffer, bindMessage.getName() );
103 }
104
105
106 BerValue.encodeInteger( buffer, 3 );
107
108
109 BerValue.encodeSequence( buffer, LdapCodecConstants.BIND_REQUEST_TAG, start );
110 }
111 }