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.server.config.beans;
21  
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.directory.api.ldap.model.constants.SchemaConstants;
27  import org.apache.directory.server.config.ConfigurationElement;
28  
29  
30  /**
31   * A class used to store the DirectoryService configuration.
32   *
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class DirectoryServiceBean extends AdsBaseBean
36  {
37      /** The DS instance Id */
38      @ConfigurationElement(attributeType = SchemaConstants.ADS_DIRECTORY_SERVICE_ID, isRdn = true)
39      private String directoryServiceId;
40  
41      /** The directory instance replication ID */
42      @ConfigurationElement(attributeType = SchemaConstants.ADS_DS_REPLICA_ID)
43      private int dsReplicaId;
44  
45      /** The flag that tells if the AccessControl system is activated */
46      @ConfigurationElement(attributeType = "ads-dsAccessControlEnabled")
47      private boolean dsAccessControlEnabled = true;
48  
49      /** The flag that tells if Anonymous connections are allowed */
50      @ConfigurationElement(attributeType = "ads-dsAllowAnonymousAccess")
51      private boolean dsAllowAnonymousAccess = false;
52  
53      /** The flag that tells if Dn must be denormalized */
54      @ConfigurationElement(attributeType = "ads-dsDenormalizeOpAttrsEnabled")
55      private boolean dsDenormalizeOpAttrsEnabled = true;
56  
57      /** The flag that tells if the password should be returned as a normal attribute or not */
58      @ConfigurationElement(attributeType = "ads-dsPasswordHidden")
59      private boolean dsPasswordHidden = false;
60  
61      /** The delay between two flushes on disk */
62      @ConfigurationElement(attributeType = "ads-dsSyncPeriodMillis")
63      private long dsSyncPeriodMillis = 15000L;
64  
65      /** The ldif entries to inject into the server at startup */
66      @ConfigurationElement(attributeType = "ads-dsTestEntries", isOptional = true)
67      private String dsTestEntries;
68  
69      /** The ChangeLog component */
70      @ConfigurationElement(objectClass = "ads-changelog")
71      private ChangeLogBean changeLog;
72  
73      /** The journal component */
74      @ConfigurationElement(objectClass = "ads-journal")
75      private JournalBean journal;
76  
77      /** The servers */
78      @ConfigurationElement(objectClass = "ads-server", container = "servers")
79      private List<ServerBean> servers = new ArrayList<>();
80  
81      /** The list of declared interceptors */
82      @ConfigurationElement(objectClass = "ads-interceptor", container = "interceptors")
83      private List<InterceptorBean> interceptors = new ArrayList<>();
84  
85      /** The set of associated partitions */
86      @ConfigurationElement(objectClass = "ads-partition", container = "partitions")
87      private List<PartitionBean> partitions = new ArrayList<>();
88  
89  
90      /**
91       * Create a new DnsServerBean instance
92       */
93      public DirectoryServiceBean()
94      {
95      }
96  
97  
98      /**
99       * 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 }