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.actions.bindRequest;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
25 import org.apache.directory.api.asn1.ber.tlv.TLV;
26 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
27 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
28 import org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator;
29 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
30 import org.apache.directory.api.ldap.model.message.BindRequest;
31 import org.apache.directory.api.ldap.model.message.BindResponseImpl;
32 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
33 import org.apache.directory.api.ldap.model.name.Dn;
34 import org.apache.directory.api.util.Strings;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38
39
40
41
42
43
44
45
46
47
48
49 public class StoreName extends GrammarAction<LdapMessageContainer<BindRequestDecorator>>
50 {
51
52 private static final Logger LOG = LoggerFactory.getLogger( StoreName.class );
53
54
55 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
56
57
58
59
60
61 public StoreName()
62 {
63 super( "Store BindRequest Name value" );
64 }
65
66
67
68
69
70 public void action( LdapMessageContainer<BindRequestDecorator> container ) throws DecoderException
71 {
72 BindRequest bindRequestMessage = container.getMessage();
73
74
75 TLV tlv = container.getCurrentTLV();
76
77
78 if ( tlv.getLength() == 0 )
79 {
80 bindRequestMessage.setName( "" );
81 }
82 else
83 {
84 byte[] nameBytes = tlv.getValue().getData();
85 String nameStr = Strings.utf8ToString( nameBytes );
86
87 try
88 {
89
90 new Dn( nameStr );
91 bindRequestMessage.setName( nameStr );
92 }
93 catch ( LdapInvalidDnException ine )
94 {
95 String msg = "Incorrect DN given : " + nameStr + " (" + Strings.dumpBytes( nameBytes )
96 + ") is invalid";
97 LOG.error( "{} : {}", msg, ine.getMessage() );
98
99 BindResponseImpl response = new BindResponseImpl( bindRequestMessage.getMessageId() );
100
101 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
102 Dn.EMPTY_DN, ine );
103 }
104 }
105
106 if ( IS_DEBUG )
107 {
108 LOG.debug( " The Bind name is {}", bindRequestMessage.getName() );
109 }
110 }
111 }