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.modifyDnRequest;
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.codec.decorators.ModifyDnRequestDecorator;
30 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
31 import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
32 import org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl;
33 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
34 import org.apache.directory.api.ldap.model.name.Dn;
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<ModifyDnRequestDecorator>>
54 {
55
56 private static final Logger LOG = LoggerFactory.getLogger( StoreModifyDnRequestNewRdn.class );
57
58
59 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
60
61
62
63
64
65 public StoreModifyDnRequestNewRdn()
66 {
67 super( "Store ModifyDN request new RDN" );
68 }
69
70
71
72
73
74 public void action( LdapMessageContainer<ModifyDnRequestDecorator> container ) throws DecoderException
75 {
76 ModifyDnRequest modifyDnRequest = container.getMessage();
77
78
79 TLV tlv = container.getCurrentTLV();
80
81
82
83 Rdn newRdn = null;
84
85 if ( tlv.getLength() == 0 )
86 {
87 String msg = I18n.err( I18n.ERR_04090 );
88 LOG.error( msg );
89
90 ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
91 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
92 modifyDnRequest.getName(), null );
93 }
94 else
95 {
96 byte[] dnBytes = tlv.getValue().getData();
97 String dnStr = Strings.utf8ToString( dnBytes );
98
99 try
100 {
101 Dn dn = new Dn( dnStr );
102 newRdn = dn.getRdn( dn.size() - 1 );
103 }
104 catch ( LdapInvalidDnException ine )
105 {
106 String msg = "Invalid new Rdn given : " + dnStr + " (" + Strings.dumpBytes( dnBytes )
107 + ") is invalid";
108 LOG.error( "{} : {}", msg, ine.getMessage() );
109
110 ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
111 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
112 modifyDnRequest.getName(), ine );
113 }
114
115 modifyDnRequest.setNewRdn( newRdn );
116 }
117
118 if ( IS_DEBUG )
119 {
120 LOG.debug( "Modifying with new Rdn {}", newRdn );
121 }
122 }
123 }