View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.dsmlv2.request;
21  
22  
23  import org.apache.directory.api.dsmlv2.DsmlLiterals;
24  import org.apache.directory.api.ldap.codec.api.LdapApiService;
25  import org.apache.directory.api.ldap.model.message.BindRequest;
26  import org.apache.directory.api.ldap.model.message.BindRequestImpl;
27  import org.apache.directory.api.ldap.model.message.BindResponse;
28  import org.apache.directory.api.ldap.model.message.Control;
29  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
30  import org.apache.directory.api.ldap.model.name.Dn;
31  import org.dom4j.Element;
32  
33  
34  /**
35   * DSML Decorator for BindRequest
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class BindRequestDsml
40      extends AbstractResultResponseRequestDsml<BindRequest, BindResponse>
41      implements BindRequest
42  {
43      /**
44       * Creates a new getDecoratedMessage() of AuthRequestDsml.
45       * 
46       * @param codec The LDAP Service to use
47       */
48      public BindRequestDsml( LdapApiService codec )
49      {
50          super( codec, new BindRequestImpl() );
51      }
52  
53  
54      /**
55       * Creates a new getDecoratedMessage() of AuthRequestDsml.
56       *
57       * @param codec The LDAP Service to use
58       * @param ldapMessage the message to decorate
59       */
60      public BindRequestDsml( LdapApiService codec, BindRequest ldapMessage )
61      {
62          super( codec, ldapMessage );
63      }
64  
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public MessageTypeEnum getType()
71      {
72          return getDecorated().getType();
73      }
74  
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      public Element toDsml( Element root )
81      {
82          Element element = super.toDsml( root );
83  
84          BindRequest request = getDecorated();
85  
86          // Principal
87          Dn dn = request.getDn();
88  
89          if ( !Dn.isNullOrEmpty( dn ) )
90          {
91              // A DN has been provided
92  
93              element.addAttribute( DsmlLiterals.PRINCIPAL, dn.getName() );
94          }
95          else
96          {
97              // No DN has been provided, let's use the name as a string instead
98  
99              String name = request.getName();
100 
101             element.addAttribute( DsmlLiterals.PRINCIPAL, name );
102         }
103 
104         return element;
105     }
106 
107 
108     /**
109      * {@inheritDoc}
110      */
111     @Override
112     public MessageTypeEnum getResponseType()
113     {
114         return getDecorated().getResponseType();
115     }
116 
117 
118     /**
119      * {@inheritDoc}
120      */
121     @Override
122     public boolean isSimple()
123     {
124         return getDecorated().isSimple();
125     }
126 
127 
128     /**
129      * {@inheritDoc}
130      */
131     @Override
132     public boolean getSimple()
133     {
134         return getDecorated().getSimple();
135     }
136 
137 
138     /**
139      * {@inheritDoc}
140      */
141     @Override
142     public BindRequest setSimple( boolean isSimple )
143     {
144         getDecorated().setSimple( isSimple );
145 
146         return this;
147     }
148 
149 
150     /**
151      * {@inheritDoc}
152      */
153     @Override
154     public byte[] getCredentials()
155     {
156         return getDecorated().getCredentials();
157     }
158 
159 
160     /**
161      * {@inheritDoc}
162      */
163     @Override
164     public BindRequest setCredentials( String credentials )
165     {
166         getDecorated().setCredentials( credentials );
167 
168         return this;
169     }
170 
171 
172     /**
173      * {@inheritDoc}
174      */
175     @Override
176     public BindRequest setCredentials( byte[] credentials )
177     {
178         getDecorated().setCredentials( credentials );
179 
180         return this;
181     }
182 
183 
184     /**
185      * {@inheritDoc}
186      */
187     @Override
188     public String getName()
189     {
190         return getDecorated().getName();
191     }
192 
193 
194     /**
195      * {@inheritDoc}
196      */
197     @Override
198     public BindRequest setName( String name )
199     {
200         getDecorated().setName( name );
201 
202         return this;
203     }
204 
205 
206     /**
207      * {@inheritDoc}
208      */
209     @Override
210     public Dn getDn()
211     {
212         return getDecorated().getDn();
213     }
214 
215 
216     /**
217      * {@inheritDoc}
218      */
219     @Override
220     public BindRequest setDn( Dn dn )
221     {
222         getDecorated().setDn( dn );
223 
224         return this;
225     }
226 
227 
228     /**
229      * {@inheritDoc}
230      */
231     @Override
232     public boolean isVersion3()
233     {
234         return getDecorated().isVersion3();
235     }
236 
237 
238     /**
239      * {@inheritDoc}
240      */
241     @Override
242     public boolean getVersion3()
243     {
244         return getDecorated().getVersion3();
245     }
246 
247 
248     /**
249      * {@inheritDoc}
250      */
251     @Override
252     public BindRequest setVersion3( boolean isVersion3 )
253     {
254         getDecorated().setVersion3( isVersion3 );
255 
256         return this;
257     }
258 
259 
260     /**
261      * {@inheritDoc}
262      */
263     @Override
264     public String getSaslMechanism()
265     {
266         return getDecorated().getSaslMechanism();
267     }
268 
269 
270     /**
271      * {@inheritDoc}
272      */
273     @Override
274     public BindRequest setSaslMechanism( String saslMechanism )
275     {
276         getDecorated().setSaslMechanism( saslMechanism );
277 
278         return this;
279     }
280 
281 
282     /**
283      * {@inheritDoc}
284      */
285     @Override
286     public BindRequest setMessageId( int messageId )
287     {
288         super.setMessageId( messageId );
289 
290         return this;
291     }
292 
293 
294     /**
295      * {@inheritDoc}
296      */
297     @Override
298     public BindRequest addControl( Control control )
299     {
300         return ( BindRequest ) super.addControl( control );
301     }
302 
303 
304     /**
305      * {@inheritDoc}
306      */
307     @Override
308     public BindRequest addAllControls( Control[] controls )
309     {
310         return ( BindRequest ) super.addAllControls( controls );
311     }
312 
313 
314     /**
315      * {@inheritDoc}
316      */
317     @Override
318     public BindRequest removeControl( Control control )
319     {
320         return ( BindRequest ) super.removeControl( control );
321     }
322 }