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