001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.server.config.beans;
021
022
023import java.util.ArrayList;
024import java.util.List;
025
026import org.apache.directory.api.ldap.model.constants.SchemaConstants;
027import org.apache.directory.server.config.ConfigurationElement;
028
029
030/**
031 * A class used to store the LdapServer configuration.
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class LdapServerBean extends DSBasedServerBean
036{
037    /** */
038    @ConfigurationElement(attributeType = "ads-confidentialityRequired")
039    private boolean confidentialityRequired;
040
041    /** The maximum number of entries returned by the server */
042    @ConfigurationElement(attributeType = "ads-maxSizeLimit")
043    private int maxSizeLimit;
044
045    /** The maximum time to execute a request on the server */
046    @ConfigurationElement(attributeType = "ads-maxTimeLimit")
047    private int maxTimeLimit;
048
049    /** The maximum size of an incoming PDU */
050    @ConfigurationElement(attributeType = "ads-maxPDUSize")
051    private int maxPDUSize = 2048;
052
053    /** The SASL host */
054    @ConfigurationElement(attributeType = "ads-saslHost")
055    private String saslHost;
056
057    /** The SASL  principal */
058    @ConfigurationElement(attributeType = "ads-saslPrincipal")
059    private String saslPrincipal;
060
061    /** The SASL realms */
062    @ConfigurationElement(attributeType = "ads-saslRealms")
063    private List<String> saslRealms = new ArrayList<String>();
064
065    /** The keystore file */
066    @ConfigurationElement(attributeType = "ads-keystoreFile", isOptional = true)
067    private String keystoreFile;
068
069    /** The certificate password */
070    @ConfigurationElement(attributeType = "ads-certificatePassword", isOptional = true)
071    private String certificatePassword;
072
073    /** A flag telling if the replication is enabled */
074    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_ENABLED)
075    private boolean replEnabled = false;
076
077    /** the replication request handler, server will be in replication provider/master mode if a valid FQCN is given */
078    @ConfigurationElement(attributeType = "ads-replReqHandler", isOptional = true)
079    private String replReqHandler;
080
081    /** The replication consumer Bean */
082    @ConfigurationElement(objectClass = "ads-replConsumer", container = "replConsumers", isOptional = true)
083    private List<ReplConsumerBean> replConsumers = new ArrayList<ReplConsumerBean>();
084
085    /** The list of supported mechanisms */
086    @ConfigurationElement(objectClass = "ads-saslMechHandler", container = "saslMechHandlers", isOptional = true)
087    private List<SaslMechHandlerBean> saslMechHandlers = new ArrayList<SaslMechHandlerBean>();
088
089    /** The list of supported extended operation handlers */
090    @ConfigurationElement(objectClass = "ads-extendedOpHandler", container = "extendedOpHandlers", isOptional = true)
091    private List<ExtendedOpHandlerBean> extendedOpHandlers = new ArrayList<ExtendedOpHandlerBean>();
092
093    /** the time interval between subsequent pings to each replication provider */
094    @ConfigurationElement(attributeType = "ads-replPingerSleep")
095    private int replPingerSleep;
096
097
098    /**
099     * Create a new LdapServerBean instance
100     */
101    public LdapServerBean()
102    {
103        super();
104
105        // Enabled by default
106        setEnabled( true );
107    }
108
109
110    /**
111     * @return the ldapServerConfidentialityRequired
112     */
113    public boolean isLdapServerConfidentialityRequired()
114    {
115        return confidentialityRequired;
116    }
117
118
119    /**
120     * @param ldapServerConfidentialityRequired the ldapServerConfidentialityRequired to set
121     */
122    public void setLdapServerConfidentialityRequired( boolean ldapServerConfidentialityRequired )
123    {
124        this.confidentialityRequired = ldapServerConfidentialityRequired;
125    }
126
127
128    /**
129     * @return the ldapServerMaxSizeLimit
130     */
131    public int getLdapServerMaxSizeLimit()
132    {
133        return maxSizeLimit;
134    }
135
136
137    /**
138     * @param ldapServerMaxSizeLimit the ldapServerMaxSizeLimit to set
139     */
140    public void setLdapServerMaxSizeLimit( int ldapServerMaxSizeLimit )
141    {
142        this.maxSizeLimit = ldapServerMaxSizeLimit;
143    }
144
145
146    /**
147     * @return the ldapServerMaxTimeLimit
148     */
149    public int getLdapServerMaxTimeLimit()
150    {
151        return maxTimeLimit;
152    }
153
154
155    /**
156     * @param ldapServerMaxTimeLimit the ldapServerMaxTimeLimit to set
157     */
158    public void setLdapServerMaxTimeLimit( int ldapServerMaxTimeLimit )
159    {
160        this.maxTimeLimit = ldapServerMaxTimeLimit;
161    }
162
163
164    /**
165     * @return the ldapServerSaslHost
166     */
167    public String getLdapServerSaslHost()
168    {
169        return saslHost;
170    }
171
172
173    /**
174     * @param ldapServerSaslHost the ldapServerSaslHost to set
175     */
176    public void setLdapServerSaslHost( String ldapServerSaslHost )
177    {
178        this.saslHost = ldapServerSaslHost;
179    }
180
181
182    /**
183     * @return the ldapServerSaslPrincipal
184     */
185    public String getLdapServerSaslPrincipal()
186    {
187        return saslPrincipal;
188    }
189
190
191    /**
192     * @param ldapServerSaslPrincipal the ldapServerSaslPrincipal to set
193     */
194    public void setLdapServerSaslPrincipal( String ldapServerSaslPrincipal )
195    {
196        this.saslPrincipal = ldapServerSaslPrincipal;
197    }
198
199
200    /**
201     * @return the ldapServerSaslRealms
202     */
203    public List<String> getLdapServerSaslRealms()
204    {
205        return saslRealms;
206    }
207
208
209    /**
210     * @param ldapServerSaslRealms the ldapServerSaslRealms to set
211     */
212    public void setLdapServerSaslRealms( List<String> ldapServerSaslRealms )
213    {
214        this.saslRealms = ldapServerSaslRealms;
215    }
216
217
218    /**
219     * @param ldapServerSaslRealms the ldapServerSaslRealms to add
220     */
221    public void addSaslRealms( String... ldapServerSaslRealms )
222    {
223        for ( String saslRealm : ldapServerSaslRealms )
224        {
225            this.saslRealms.add( saslRealm );
226        }
227    }
228
229
230    /**
231     * @return the ldapServerKeystoreFile
232     */
233    public String getLdapServerKeystoreFile()
234    {
235        return keystoreFile;
236    }
237
238
239    /**
240     * @param ldapServerKeystoreFile the ldapServerKeystoreFile to set
241     */
242    public void setLdapServerKeystoreFile( String ldapServerKeystoreFile )
243    {
244        this.keystoreFile = ldapServerKeystoreFile;
245    }
246
247
248    /**
249     * @return the ldapServerCertificatePassword
250     */
251    public String getLdapServerCertificatePassword()
252    {
253        return certificatePassword;
254    }
255
256
257    /**
258     * @param ldapServerCertificatePassword the ldapServerCertificatePassword to set
259     */
260    public void setLdapServerCertificatePassword( String ldapServerCertificatePassword )
261    {
262        this.certificatePassword = ldapServerCertificatePassword;
263    }
264
265
266    /**
267     * @return the replReqHandler
268     */
269    public String getReplReqHandler()
270    {
271        return replReqHandler;
272    }
273
274
275    /**
276     * @param replReqHandler the replReqHandler to set
277     */
278    public void setReplReqHandler( String replReqHandler )
279    {
280        this.replReqHandler = replReqHandler;
281    }
282
283
284    /**
285     * @return the saslMechHandlers
286     */
287    public List<SaslMechHandlerBean> getSaslMechHandlers()
288    {
289        return saslMechHandlers;
290    }
291
292
293    /**
294     * @param saslMechHandlers the saslMechHandlers to set
295     */
296    public void setSaslMechHandlers( List<SaslMechHandlerBean> saslMechHandlers )
297    {
298        this.saslMechHandlers = saslMechHandlers;
299    }
300
301
302    /**
303     * @param saslMechHandlers the saslMechHandlers to add
304     */
305    public void setSaslMechHandlers( SaslMechHandlerBean... saslMechHandlers )
306    {
307        for ( SaslMechHandlerBean saslMechHandler : saslMechHandlers )
308        {
309            this.saslMechHandlers.add( saslMechHandler );
310        }
311    }
312
313
314    /**
315     * @return the extendedOps
316     */
317    public List<ExtendedOpHandlerBean> getExtendedOps()
318    {
319        return extendedOpHandlers;
320    }
321
322
323    /**
324     * @param extendedOps the extendedOps to set
325     */
326    public void setExtendedOps( List<ExtendedOpHandlerBean> extendedOps )
327    {
328        this.extendedOpHandlers = extendedOps;
329    }
330
331
332    /**
333     * @param extendedOps the extendedOps to add
334     */
335    public void addExtendedOps( ExtendedOpHandlerBean... extendedOps )
336    {
337        for ( ExtendedOpHandlerBean extendedOp : extendedOps )
338        {
339            this.extendedOpHandlers.add( extendedOp );
340        }
341    }
342
343
344    /**
345     * @return the Replication Consumer Bean
346     */
347    public List<ReplConsumerBean> getReplConsumers()
348    {
349        return replConsumers;
350    }
351
352
353    /**
354     * @param replConsumers the Replication Consumer Bean to set
355     */
356    public void setReplConsumer( List<ReplConsumerBean> replConsumers )
357    {
358        this.replConsumers = replConsumers;
359    }
360
361
362    /**
363     * @param replConsumers the Replication Consumer Bean to set
364     */
365    public void addReplConsumers( ReplConsumerBean... replConsumers )
366    {
367        for ( ReplConsumerBean bean : replConsumers )
368        {
369            this.replConsumers.add( bean );
370        }
371    }
372
373
374    /**
375     * @return the maxPDUSize
376     */
377    public int getMaxPDUSize()
378    {
379        return maxPDUSize;
380    }
381
382
383    /**
384     * @param maxPDUSize the maxPDUSize to set
385     */
386    public void setMaxPDUSize( int maxPDUSize )
387    {
388        this.maxPDUSize = maxPDUSize;
389    }
390
391
392    /**
393     * {@inheritDoc}
394     */
395    public String toString( String tabs )
396    {
397        StringBuilder sb = new StringBuilder();
398
399        sb.append( tabs ).append( "LdapServer :\n" );
400        sb.append( super.toString( tabs + "  " ) );
401        sb.append( tabs ).append( "  max size limit : " ).append( maxSizeLimit ).append( '\n' );
402        sb.append( tabs ).append( "  max time limit : " ).append( maxTimeLimit ).append( '\n' );
403        sb.append( "  max PDU size : " ).append( maxPDUSize ).append( '\n' );
404        sb.append( toString( tabs, "  certificate password", certificatePassword ) );
405        sb.append( toString( tabs, "  keystore file", keystoreFile ) );
406        sb.append( toString( tabs, "  sasl principal", saslPrincipal ) );
407        sb.append( tabs ).append( "  sasl host : " ).append( saslHost ).append( '\n' );
408        sb.append( toString( tabs, "  confidentiality required", confidentialityRequired ) );
409        sb.append( toString( tabs, "  enable replication provider", replReqHandler ) );
410        sb.append( toString( tabs, "  Pinger thread sleep time(in sec.)", replPingerSleep ) );
411
412        if ( ( extendedOpHandlers != null ) && ( extendedOpHandlers.size() > 0 ) )
413        {
414            sb.append( tabs ).append( "  extended operation handlers :\n" );
415
416            for ( ExtendedOpHandlerBean extendedOpHandler : extendedOpHandlers )
417            {
418                sb.append( extendedOpHandler.toString( tabs + "    " ) );
419            }
420        }
421
422        if ( saslMechHandlers != null )
423        {
424            sb.append( tabs ).append( "  SASL mechanism handlers :\n" );
425
426            for ( SaslMechHandlerBean saslMechHandler : saslMechHandlers )
427            {
428                sb.append( saslMechHandler.toString( tabs + "    " ) );
429            }
430        }
431
432        if ( ( saslRealms != null ) && ( saslRealms.size() > 0 ) )
433        {
434            sb.append( tabs ).append( "  SASL realms :\n" );
435
436            for ( String saslRealm : saslRealms )
437            {
438                sb.append( tabs ).append( "    " ).append( saslRealm ).append( "\n" );
439            }
440        }
441
442        if ( ( replConsumers != null ) && ( replConsumers.size() > 0 ) )
443        {
444            sb.append( tabs ).append( "  replication consumers :\n" );
445
446            for ( ReplConsumerBean replConsumer : replConsumers )
447            {
448                sb.append( replConsumer.toString( tabs + "    " ) );
449            }
450        }
451
452        return sb.toString();
453    }
454
455
456    /**
457     * @return True if the replication service should be enabled
458     */
459    public boolean isReplEnabled()
460    {
461        return replEnabled;
462    }
463
464
465    /**
466     * Enable or disable the replication
467     * @param replEnabled The new value
468     */
469    public void setReplEnabled( boolean replEnabled )
470    {
471        this.replEnabled = replEnabled;
472    }
473
474
475    public int getReplPingerSleep()
476    {
477        return replPingerSleep;
478    }
479
480
481    public void setReplPingerSleep( int replPingerSleep )
482    {
483        this.replPingerSleep = replPingerSleep;
484    }
485
486
487    /**
488     * {@inheritDoc}
489     */
490    public String toString()
491    {
492        return toString( "" );
493    }
494}