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   *    http://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.ldap.codec.api.LdapApiService;
24  import org.apache.directory.api.ldap.model.message.BindRequest;
25  import org.apache.directory.api.ldap.model.message.BindRequestImpl;
26  import org.apache.directory.api.ldap.model.message.BindResponse;
27  import org.apache.directory.api.ldap.model.message.Control;
28  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
29  import org.apache.directory.api.ldap.model.name.Dn;
30  import org.dom4j.Element;
31  
32  
33  /**
34   * DSML Decorator for BindRequest
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public class BindRequestDsml
39      extends AbstractResultResponseRequestDsml<BindRequest, BindResponse>
40      implements BindRequest
41  {
42      /**
43       * Creates a new getDecoratedMessage() of AuthRequestDsml.
44       */
45      public BindRequestDsml( LdapApiService codec )
46      {
47          super( codec, new BindRequestImpl() );
48      }
49  
50  
51      /**
52       * Creates a new getDecoratedMessage() of AuthRequestDsml.
53       *
54       * @param ldapMessage the message to decorate
55       */
56      public BindRequestDsml( LdapApiService codec, BindRequest ldapMessage )
57      {
58          super( codec, ldapMessage );
59      }
60  
61  
62      /**
63       * {@inheritDoc}
64       */
65      public MessageTypeEnum getType()
66      {
67          return getDecorated().getType();
68      }
69  
70  
71      /**
72       * {@inheritDoc}
73       */
74      public Element toDsml( Element root )
75      {
76          Element element = super.toDsml( root );
77  
78          BindRequest request = getDecorated();
79  
80          // Principal
81          Dn dn = request.getDn();
82  
83          if ( !Dn.isNullOrEmpty( dn ) )
84          {
85              // A DN has been provided
86  
87              element.addAttribute( "principal", dn.getName() );
88          }
89          else
90          {
91              // No DN has been provided, let's use the name as a string instead
92  
93              String name = request.getName();
94  
95              element.addAttribute( "principal", name );
96          }
97  
98          return element;
99      }
100 
101 
102     /**
103      * {@inheritDoc}
104      */
105     public MessageTypeEnum getResponseType()
106     {
107         return getDecorated().getResponseType();
108     }
109 
110 
111     /**
112      * {@inheritDoc}
113      */
114     public boolean isSimple()
115     {
116         return getDecorated().isSimple();
117     }
118 
119 
120     /**
121      * {@inheritDoc}
122      */
123     public boolean getSimple()
124     {
125         return getDecorated().getSimple();
126     }
127 
128 
129     /**
130      * {@inheritDoc}
131      */
132     public BindRequest setSimple( boolean isSimple )
133     {
134         getDecorated().setSimple( isSimple );
135 
136         return this;
137     }
138 
139 
140     /**
141      * {@inheritDoc}
142      */
143     public byte[] getCredentials()
144     {
145         return getDecorated().getCredentials();
146     }
147 
148 
149     /**
150      * {@inheritDoc}
151      */
152     public BindRequest setCredentials( String credentials )
153     {
154         getDecorated().setCredentials( credentials );
155 
156         return this;
157     }
158 
159 
160     /**
161      * {@inheritDoc}
162      */
163     public BindRequest setCredentials( byte[] credentials )
164     {
165         getDecorated().setCredentials( credentials );
166 
167         return this;
168     }
169 
170 
171     /**
172      * {@inheritDoc}
173      */
174     public String getName()
175     {
176         return getDecorated().getName();
177     }
178 
179 
180     /**
181      * {@inheritDoc}
182      */
183     public BindRequest setName( String name )
184     {
185         getDecorated().setName( name );
186 
187         return this;
188     }
189 
190 
191     /**
192      * {@inheritDoc}
193      */
194     public Dn getDn()
195     {
196         return getDecorated().getDn();
197     }
198 
199 
200     /**
201      * {@inheritDoc}
202      */
203     public BindRequest setDn( Dn dn )
204     {
205         getDecorated().setDn( dn );
206 
207         return this;
208     }
209 
210 
211     /**
212      * {@inheritDoc}
213      */
214     public boolean isVersion3()
215     {
216         return getDecorated().isVersion3();
217     }
218 
219 
220     /**
221      * {@inheritDoc}
222      */
223     public boolean getVersion3()
224     {
225         return getDecorated().getVersion3();
226     }
227 
228 
229     /**
230      * {@inheritDoc}
231      */
232     public BindRequest setVersion3( boolean isVersion3 )
233     {
234         getDecorated().setVersion3( isVersion3 );
235 
236         return this;
237     }
238 
239 
240     /**
241      * {@inheritDoc}
242      */
243     public String getSaslMechanism()
244     {
245         return getDecorated().getSaslMechanism();
246     }
247 
248 
249     /**
250      * {@inheritDoc}
251      */
252     public BindRequest setSaslMechanism( String saslMechanism )
253     {
254         getDecorated().setSaslMechanism( saslMechanism );
255 
256         return this;
257     }
258 
259 
260     /**
261      * {@inheritDoc}
262      */
263     public BindRequest setMessageId( int messageId )
264     {
265         super.setMessageId( messageId );
266 
267         return this;
268     }
269 
270 
271     /**
272      * {@inheritDoc}
273      */
274     public BindRequest addControl( Control control )
275     {
276         return ( BindRequest ) super.addControl( control );
277     }
278 
279 
280     /**
281      * {@inheritDoc}
282      */
283     public BindRequest addAllControls( Control[] controls )
284     {
285         return ( BindRequest ) super.addAllControls( controls );
286     }
287 
288 
289     /**
290      * {@inheritDoc}
291      */
292     public BindRequest removeControl( Control control )
293     {
294         return ( BindRequest ) super.removeControl( control );
295     }
296 }