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 DirectoryService configuration.
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class DirectoryServiceBean extends AdsBaseBean
036{
037    /** The DS instance Id */
038    @ConfigurationElement(attributeType = SchemaConstants.ADS_DIRECTORY_SERVICE_ID, isRdn = true)
039    private String directoryServiceId;
040
041    /** The directory instance replication ID */
042    @ConfigurationElement(attributeType = SchemaConstants.ADS_DS_REPLICA_ID)
043    private int dsReplicaId;
044
045    /** The flag that tells if the AccessControl system is activated */
046    @ConfigurationElement(attributeType = "ads-dsAccessControlEnabled")
047    private boolean dsAccessControlEnabled = true;
048
049    /** The flag that tells if Anonymous connections are allowed */
050    @ConfigurationElement(attributeType = "ads-dsAllowAnonymousAccess")
051    private boolean dsAllowAnonymousAccess = false;
052
053    /** The flag that tells if Dn must be denormalized */
054    @ConfigurationElement(attributeType = "ads-dsDenormalizeOpAttrsEnabled")
055    private boolean dsDenormalizeOpAttrsEnabled = true;
056
057    /** The flag that tells if the password should be returned as a normal attribute or not */
058    @ConfigurationElement(attributeType = "ads-dsPasswordHidden")
059    private boolean dsPasswordHidden = false;
060
061    /** The delay between two flushes on disk */
062    @ConfigurationElement(attributeType = "ads-dsSyncPeriodMillis")
063    private long dsSyncPeriodMillis = 15000L;
064
065    /** The ldif entries to inject into the server at startup */
066    @ConfigurationElement(attributeType = "ads-dsTestEntries", isOptional = true)
067    private String dsTestEntries;
068
069    /** The ChangeLog component */
070    @ConfigurationElement(objectClass = "ads-changelog")
071    private ChangeLogBean changeLog;
072
073    /** The journal component */
074    @ConfigurationElement(objectClass = "ads-journal")
075    private JournalBean journal;
076
077    /** The servers */
078    @ConfigurationElement(objectClass = "ads-server", container = "servers")
079    private List<ServerBean> servers = new ArrayList<>();
080
081    /** The list of declared interceptors */
082    @ConfigurationElement(objectClass = "ads-interceptor", container = "interceptors")
083    private List<InterceptorBean> interceptors = new ArrayList<>();
084
085    /** The set of associated partitions */
086    @ConfigurationElement(objectClass = "ads-partition", container = "partitions")
087    private List<PartitionBean> partitions = new ArrayList<>();
088
089
090    /**
091     * Create a new DnsServerBean instance
092     */
093    public DirectoryServiceBean()
094    {
095    }
096
097
098    /**
099     * Sets the ID for this DirectoryService
100     * @param directoryServiceId The DirectoryService ID
101     */
102    public void setDirectoryServiceId( String directoryServiceId )
103    {
104        this.directoryServiceId = directoryServiceId;
105    }
106
107
108    /**
109     * @return The DirectoryService Id
110     */
111    public String getDirectoryServiceId()
112    {
113        return directoryServiceId;
114    }
115
116
117    /**
118     * @return the replicaId
119     */
120    public int getDsReplicaId()
121    {
122        return dsReplicaId;
123    }
124
125
126    /**
127     * @param dsReplicaId the replicaId to set
128     */
129    public void setDsReplicaId( int dsReplicaId )
130    {
131        if ( ( dsReplicaId < 0 ) || ( dsReplicaId > 999 ) )
132        {
133            this.dsReplicaId = 0;
134        }
135        else
136        {
137            this.dsReplicaId = dsReplicaId;
138        }
139    }
140
141
142    /**
143     * Returns interceptors in the server.
144     *
145     * @return the interceptors in the server.
146     */
147    public List<InterceptorBean> getInterceptors()
148    {
149        return interceptors;
150    }
151
152
153    /**
154     * Sets the interceptors in the server.
155     *
156     * @param interceptors the interceptors to be used in the server.
157     */
158    public void setInterceptors( List<InterceptorBean> interceptors )
159    {
160        this.interceptors = interceptors;
161    }
162
163
164    /**
165     * Adds the interceptors in the server.
166     *
167     * @param interceptors the interceptors to be added in the server.
168     */
169    public void addInterceptors( InterceptorBean... interceptors )
170    {
171        for ( InterceptorBean interceptor : interceptors )
172        {
173            this.interceptors.add( interceptor );
174        }
175    }
176
177
178    /**
179     * @return the dsAccessControlEnabled
180     */
181    public boolean isDsAccessControlEnabled()
182    {
183        return dsAccessControlEnabled;
184    }
185
186
187    /**
188     * @param dsAccessControlEnabled the dsAccessControlEnabled to set
189     */
190    public void setDsAccessControlEnabled( boolean dsAccessControlEnabled )
191    {
192        this.dsAccessControlEnabled = dsAccessControlEnabled;
193    }
194
195
196    /**
197     * @return the dsAllowAnonymousAccess
198     */
199    public boolean isDsAllowAnonymousAccess()
200    {
201        return dsAllowAnonymousAccess;
202    }
203
204
205    /**
206     * @param dsAllowAnonymousAccess the dsAllowAnonymousAccess to set
207     */
208    public void setDsAllowAnonymousAccess( boolean dsAllowAnonymousAccess )
209    {
210        this.dsAllowAnonymousAccess = dsAllowAnonymousAccess;
211    }
212
213
214    /**
215     * @return the dsDenormalizeOpAttrsEnabled
216     */
217    public boolean isDsDenormalizeOpAttrsEnabled()
218    {
219        return dsDenormalizeOpAttrsEnabled;
220    }
221
222
223    /**
224     * @param dsDenormalizeOpAttrsEnabled the dsDenormalizeOpAttrsEnabled to set
225     */
226    public void setDsDenormalizeOpAttrsEnabled( boolean dsDenormalizeOpAttrsEnabled )
227    {
228        this.dsDenormalizeOpAttrsEnabled = dsDenormalizeOpAttrsEnabled;
229    }
230
231
232    /**
233     * @return the dsPasswordHidden
234     */
235    public boolean isDsPasswordHidden()
236    {
237        return dsPasswordHidden;
238    }
239
240
241    /**
242     * @param dsPasswordHidden the dsPasswordHidden to set
243     */
244    public void setDsPasswordHidden( boolean dsPasswordHidden )
245    {
246        this.dsPasswordHidden = dsPasswordHidden;
247    }
248
249
250    /**
251     * @return the dsSyncPeriodMillis
252     */
253    public long getDsSyncPeriodMillis()
254    {
255        return dsSyncPeriodMillis;
256    }
257
258
259    /**
260     * @param dsSyncPeriodMillis the dsSyncPeriodMillis to set
261     */
262    public void setDsSyncPeriodMillis( long dsSyncPeriodMillis )
263    {
264        this.dsSyncPeriodMillis = dsSyncPeriodMillis;
265    }
266
267
268    /**
269     * @return the dsTestEntries
270     */
271    public String getDsTestEntries()
272    {
273        return dsTestEntries;
274    }
275
276
277    /**
278     * @param dsTestEntries the dsTestEntries to set
279     */
280    public void setDsTestEntries( String dsTestEntries )
281    {
282        this.dsTestEntries = dsTestEntries;
283    }
284
285
286    /**
287     * @return the ChangeLog
288     */
289    public ChangeLogBean getChangeLog()
290    {
291        return changeLog;
292    }
293
294
295    /**
296     * @param changeLog the ChangeLog to set
297     */
298    public void setChangeLog( ChangeLogBean changeLog )
299    {
300        this.changeLog = changeLog;
301    }
302
303
304    /**
305     * @return the journal
306     */
307    public JournalBean getJournal()
308    {
309        return journal;
310    }
311
312
313    /**
314     * @param journal the journal to set
315     */
316    public void setJournal( JournalBean journal )
317    {
318        this.journal = journal;
319    }
320
321
322    /**
323     * Clears the partitions.
324     */
325    public void clearPartitions()
326    {
327        partitions.clear();
328    }
329
330
331    /**
332     * @return the partitions
333     */
334    public List<PartitionBean> getPartitions()
335    {
336        return partitions;
337    }
338
339
340    /**
341     * @param partitions the partitions to set
342     */
343    public void setPartitions( List<PartitionBean> partitions )
344    {
345        this.partitions = partitions;
346    }
347
348
349    /**
350     * @param partitions the partitions to add
351     */
352    public void addPartitions( PartitionBean... partitions )
353    {
354        for ( PartitionBean partition : partitions )
355        {
356            this.partitions.add( partition );
357        }
358    }
359
360
361    /**
362     * @return the servers
363     */
364    public List<ServerBean> getServers()
365    {
366        return servers;
367    }
368
369
370    /**
371     * @return The LdapServerBean configuration
372     */
373    public LdapServerBean getLdapServerBean()
374    {
375        for ( ServerBean server : servers )
376        {
377            if ( server instanceof LdapServerBean )
378            {
379                return ( LdapServerBean ) server;
380            }
381        }
382
383        return null;
384    }
385
386
387    /**
388     * @return The NtpServerBean configuration
389     */
390    public NtpServerBean getNtpServerBean()
391    {
392        for ( ServerBean server : servers )
393        {
394            if ( server instanceof NtpServerBean )
395            {
396                return ( NtpServerBean ) server;
397            }
398        }
399
400        return null;
401    }
402
403
404    /**
405     * @return The DnsServerBean configuration
406     */
407    public DnsServerBean getDnsServerBean()
408    {
409        for ( ServerBean server : servers )
410        {
411            if ( server instanceof DnsServerBean )
412            {
413                return ( DnsServerBean ) server;
414            }
415        }
416
417        return null;
418    }
419
420
421    /**
422     * @return The DhcpServerBean configuration
423     */
424    public DhcpServerBean getDhcpServerBean()
425    {
426        for ( ServerBean server : servers )
427        {
428            if ( server instanceof DhcpServerBean )
429            {
430                return ( DhcpServerBean ) server;
431            }
432        }
433
434        return null;
435    }
436
437
438    /**
439     * @return The HttpServerBean configuration
440     */
441    public HttpServerBean getHttpServerBean()
442    {
443        for ( ServerBean server : servers )
444        {
445            if ( server instanceof HttpServerBean )
446            {
447                return ( HttpServerBean ) server;
448            }
449        }
450
451        return null;
452    }
453
454
455    /**
456     * @return The KdcServerBean configuration
457     */
458    public KdcServerBean getKdcServerBean()
459    {
460        for ( ServerBean server : servers )
461        {
462            if ( server instanceof KdcServerBean )
463            {
464                return ( KdcServerBean ) server;
465            }
466        }
467
468        return null;
469    }
470
471
472    /**
473     * @return The ChangePasswordServerBean configuration
474     */
475    public ChangePasswordServerBean getChangePasswordServerBean()
476    {
477        for ( ServerBean server : servers )
478        {
479            if ( server instanceof ChangePasswordServerBean )
480            {
481                return ( ChangePasswordServerBean ) server;
482            }
483        }
484
485        return null;
486    }
487
488
489    /**
490     * @param servers the servers to set
491     */
492    public void setServers( List<ServerBean> servers )
493    {
494        this.servers = servers;
495    }
496
497
498    /**
499     * @param servers the servers to add
500     */
501    public void addServers( ServerBean... servers )
502    {
503        for ( ServerBean server : servers )
504        {
505            this.servers.add( server );
506        }
507    }
508
509
510    /**
511     * {@inheritDoc}
512     */
513    @Override
514    public String toString()
515    {
516        StringBuilder sb = new StringBuilder();
517
518        sb.append( "DirectoryServiceBean : \n" );
519        sb.append( super.toString( "  " ) );
520
521        // Dump the must attributes
522        sb.append( "  directoryService ID : " ).append( directoryServiceId ).append( '\n' );
523        sb.append( "  replica ID : " ).append( dsReplicaId ).append( '\n' );
524        sb.append( toString( "  ", "accessControl enabled", dsAccessControlEnabled ) );
525        sb.append( toString( "  ", "allow anonymous access", dsAllowAnonymousAccess ) );
526        sb.append( toString( "  ", "denormalized attributes enabled", dsDenormalizeOpAttrsEnabled ) );
527        sb.append( toString( "  ", "password hidden", dsPasswordHidden ) );
528        sb.append( "  sync period millisecond : " ).append( dsSyncPeriodMillis ).append( '\n' );
529        sb.append( toString( "  ", "test entries", dsTestEntries ) );
530
531        sb.append( "  interceptors : \n" );
532
533        if ( ( interceptors != null ) && !interceptors.isEmpty() )
534        {
535            for ( InterceptorBean interceptor : interceptors )
536            {
537                sb.append( interceptor.toString( "    " ) );
538            }
539        }
540
541        sb.append( "  partitions : \n" );
542
543        if ( ( partitions != null ) && !partitions.isEmpty() )
544        {
545            for ( PartitionBean partition : partitions )
546            {
547                sb.append( partition.toString( "    " ) );
548            }
549        }
550
551        if ( journal != null )
552        {
553            sb.append( journal.toString( "  " ) );
554        }
555
556        if ( changeLog != null )
557        {
558            sb.append( changeLog.toString( "  " ) );
559        }
560
561        sb.append( "  servers : \n" );
562
563        if ( ( servers != null ) && !servers.isEmpty() )
564        {
565            for ( ServerBean server : servers )
566            {
567                sb.append( server.toString( "    " ) );
568            }
569        }
570
571        sb.append( '\n' );
572
573        return sb.toString();
574    }
575}