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.compareRequest;
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.CompareRequestDecorator;
30 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
31 import org.apache.directory.api.ldap.model.message.CompareRequest;
32 import org.apache.directory.api.ldap.model.message.CompareResponseImpl;
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 StoreCompareRequestEntryName extends GrammarAction<LdapMessageContainer<CompareRequestDecorator>>
50 {
51
52 private static final Logger LOG = LoggerFactory.getLogger( StoreCompareRequestEntryName.class );
53
54
55 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
56
57
58
59
60
61 public StoreCompareRequestEntryName()
62 {
63 super( "Store CompareRequest entry Name" );
64 }
65
66
67
68
69
70 public void action( LdapMessageContainer<CompareRequestDecorator> container ) throws DecoderException
71 {
72 CompareRequest compareRequest = container.getMessage();
73
74
75 TLV tlv = container.getCurrentTLV();
76 Dn entry = null;
77
78
79
80 if ( tlv.getLength() == 0 )
81 {
82
83 throw new DecoderException( I18n.err( I18n.ERR_04089 ) );
84 }
85 else
86 {
87 byte[] dnBytes = tlv.getValue().getData();
88 String dnStr = Strings.utf8ToString( dnBytes );
89
90 try
91 {
92 entry = new Dn( dnStr );
93 }
94 catch ( LdapInvalidDnException ine )
95 {
96 String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes( dnBytes )
97 + ") is invalid";
98 LOG.error( "{} : {}", msg, ine.getMessage() );
99
100 CompareResponseImpl response = new CompareResponseImpl( compareRequest.getMessageId() );
101 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
102 Dn.EMPTY_DN, ine );
103 }
104
105 compareRequest.setName( entry );
106 }
107
108 if ( IS_DEBUG )
109 {
110 LOG.debug( "Comparing Dn {}", entry );
111 }
112 }
113 }