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.request.add;
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.i18n.I18n;
27 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
28 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
29 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
30 import org.apache.directory.api.ldap.model.message.AddRequest;
31 import org.apache.directory.api.ldap.model.message.AddResponseImpl;
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.ldap.model.name.DnFactory;
35 import org.apache.directory.api.util.Strings;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39
40
41
42
43
44
45
46
47
48
49 public class StoreAddRequestEntryName extends GrammarAction<LdapMessageContainer<AddRequest>>
50 {
51
52 private static final Logger LOG = LoggerFactory.getLogger( StoreAddRequestEntryName.class );
53
54
55
56
57
58 public StoreAddRequestEntryName()
59 {
60 super( "Store Add request entry Name" );
61 }
62
63
64
65
66
67 @Override
68 public void action( LdapMessageContainer<AddRequest> container ) throws DecoderException
69 {
70 AddRequest addRequest = container.getMessage();
71
72 TLV tlv = container.getCurrentTLV();
73
74
75 if ( tlv.getLength() == 0 )
76 {
77 String msg = I18n.err( I18n.ERR_05115_EMTPY_ENTRY_DN_GIVEN );
78 LOG.error( msg );
79
80 AddResponseImpl response = new AddResponseImpl( addRequest.getMessageId() );
81
82
83
84 throw new ResponseCarryingException( msg, response, ResultCodeEnum.NAMING_VIOLATION,
85 Dn.EMPTY_DN, null );
86 }
87 else
88 {
89 byte[] dnBytes = tlv.getValue().getData();
90 String dnStr = Strings.utf8ToString( dnBytes );
91
92 try
93 {
94 DnFactory dnFactory = container.getDnFactory();
95 Dn entryDn;
96
97 if ( dnFactory == null )
98 {
99 entryDn = new Dn( dnStr );
100 }
101 else
102 {
103 entryDn = dnFactory.create( dnStr );
104 }
105
106 addRequest.setEntryDn( entryDn );
107 }
108 catch ( LdapInvalidDnException ine )
109 {
110 String msg = I18n.err( I18n.ERR_05113_INVALID_DN, dnStr, Strings.dumpBytes( dnBytes ) );
111 LOG.error( I18n.err( I18n.ERR_05114_ERROR_MESSAGE, msg, ine.getMessage() ) );
112
113 AddResponseImpl response = new AddResponseImpl( addRequest.getMessageId() );
114 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
115 Dn.EMPTY_DN, ine );
116 }
117
118 }
119
120 if ( LOG.isDebugEnabled() )
121 {
122 LOG.debug( I18n.msg( I18n.MSG_05113_ADDING_ENTRY_WITH_DN, addRequest.getEntry() ) );
123 }
124 }
125 }