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.ldapResult;
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.model.exception.LdapInvalidDnException;
29 import org.apache.directory.api.ldap.model.message.LdapResult;
30 import org.apache.directory.api.ldap.model.message.Message;
31 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
32 import org.apache.directory.api.ldap.model.name.Dn;
33 import org.apache.directory.api.ldap.model.name.DnFactory;
34 import org.apache.directory.api.util.Strings;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class StoreMatchedDN extends GrammarAction<LdapMessageContainer<Message>>
51 {
52
53 private static final Logger LOG = LoggerFactory.getLogger( StoreMatchedDN.class );
54
55
56
57
58 public StoreMatchedDN()
59 {
60 super( "Store matched Dn" );
61 }
62
63
64
65
66
67 @Override
68 public void action( LdapMessageContainer<Message> container ) throws DecoderException
69 {
70
71 TLV tlv = container.getCurrentTLV();
72 Dn matchedDn;
73 ResultCodeEnum resultCode;
74
75 LdapResult ldapResult = container.getLdapResult();
76 resultCode = ldapResult.getResultCode();
77
78
79
80 if ( tlv.getLength() == 0 )
81 {
82 matchedDn = Dn.EMPTY_DN;
83 }
84 else
85 {
86
87
88
89
90 switch ( resultCode )
91 {
92 case NO_SUCH_OBJECT:
93 case ALIAS_PROBLEM:
94 case INVALID_DN_SYNTAX:
95 case ALIAS_DEREFERENCING_PROBLEM:
96 byte[] dnBytes = tlv.getValue().getData();
97 String dnStr = Strings.utf8ToString( dnBytes );
98
99 try
100 {
101 DnFactory dnFactory = container.getDnFactory();
102
103 if ( dnFactory == null )
104 {
105 matchedDn = new Dn( dnStr );
106 }
107 else
108 {
109 matchedDn = dnFactory.create( dnStr );
110 }
111 }
112 catch ( LdapInvalidDnException ine )
113 {
114
115 String msg = I18n.err( I18n.ERR_05106_INCORRECT_DN_GIVEN_INVALID, dnStr, Strings.dumpBytes( dnBytes ), ine
116 .getLocalizedMessage() );
117 LOG.error( msg );
118
119 throw new DecoderException( I18n.err( I18n.ERR_05107_INCORRECT_DN_GIVEN, ine.getLocalizedMessage() ), ine );
120 }
121
122 break;
123
124 default:
125 if ( LOG.isWarnEnabled() )
126 {
127 LOG.warn( I18n.msg( I18n.MSG_05107_NO_SUCH_OBJECT_MATCHED_DN_NOT_SET ) );
128 }
129
130 matchedDn = Dn.EMPTY_DN;
131 break;
132 }
133 }
134
135 if ( LOG.isDebugEnabled() )
136 {
137 LOG.debug( I18n.msg( I18n.MSG_05108_MATCHED_DN_IS, matchedDn ) );
138 }
139
140 ldapResult.setMatchedDn( matchedDn );
141 }
142 }