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.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 StoreModifyDnRequestNewSuperior extends GrammarAction<LdapMessageContainer<ModifyDnRequestDecorator>>
50 {
51
52 private static final Logger LOG = LoggerFactory.getLogger( StoreModifyDnRequestNewSuperior.class );
53
54
55 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
56
57
58
59
60
61 public StoreModifyDnRequestNewSuperior()
62 {
63 super( "Store new superior" );
64 }
65
66
67
68
69
70 public void action( LdapMessageContainer<ModifyDnRequestDecorator> container ) throws DecoderException
71 {
72 ModifyDnRequest modifyDnRequest = container.getMessage();
73
74
75 TLV tlv = container.getCurrentTLV();
76
77
78
79 Dn newSuperior = Dn.EMPTY_DN;
80
81 if ( tlv.getLength() == 0 )
82 {
83
84 if ( modifyDnRequest.getDeleteOldRdn() )
85 {
86
87 throw new DecoderException( I18n.err( I18n.ERR_04092 ) );
88 }
89 else
90 {
91 LOG.warn( "The new superior is null, so we will change the entry" );
92 }
93
94 modifyDnRequest.setNewSuperior( newSuperior );
95 }
96 else
97 {
98 byte[] dnBytes = tlv.getValue().getData();
99 String dnStr = Strings.utf8ToString( dnBytes );
100
101 try
102 {
103 newSuperior = new Dn( dnStr );
104 }
105 catch ( LdapInvalidDnException ine )
106 {
107 String msg = "Invalid new superior Dn given : " + dnStr + " ("
108 + Strings.dumpBytes( dnBytes ) + ") is invalid";
109 LOG.error( "{} : {}", msg, ine.getMessage() );
110
111 ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
112 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
113 modifyDnRequest.getName(), ine );
114 }
115
116 modifyDnRequest.setNewSuperior( newSuperior );
117 }
118
119
120 container.setGrammarEndAllowed( true );
121
122 if ( IS_DEBUG )
123 {
124 LOG.debug( "New superior Dn {}", newSuperior );
125 }
126 }
127 }