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 Replication Consumer configuration.
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class ReplConsumerBean extends AdsBaseBean
036{
037    /** The consumer id */
038    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_CONSUMER_ID, isRdn = true)
039    private String replConsumerId;
040
041    /** The Search Base Dn */
042    @ConfigurationElement(attributeType = SchemaConstants.ADS_SEARCH_BASE_DN)
043    private String searchBaseDn;
044
045    /** The replication provider host name */
046    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_PROV_HOST_NAME)
047    private String replProvHostName;
048
049    /** The replication provider port */
050    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_PROV_PORT)
051    private int replProvPort;
052
053    /** The Alias Dereferencing mode */
054    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_ALIAS_DEREF_MODE)
055    private String replAliasDerefMode;
056
057    /** The replication provider attribute */
058    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_ATTRIBUTES)
059    private List<String> replAttributes = new ArrayList<>();
060
061    /** The refresh interval */
062    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_REFRESH_INTERVAL)
063    private long replRefreshInterval;
064
065    /** Tells if we should persist */
066    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_REFRESH_N_PERSIST)
067    private boolean replRefreshNPersist;
068
069    /** The search scope */
070    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_SEARCH_SCOPE)
071    private String replSearchScope;
072
073    /** The replication search filter */
074    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_SEARCH_FILTER)
075    private String replSearchFilter;
076
077    /** The search size limit */
078    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_SEARCH_SIZE_LIMIT)
079    private int replSearchSizeLimit;
080
081    /** The search time limit */
082    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_SEARCH_TIMEOUT)
083    private int replSearchTimeout;
084
085    /** The replication user Dn */
086    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_USER_DN)
087    private String replUserDn;
088
089    /** The replication user password */
090    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_USER_PASSWORD)
091    private byte[] replUserPassword;
092
093    /** The replication cookie */
094    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_COOKIE, isOptional = true)
095    private String replCookie;
096
097    /** Tells if TLS should be used during replication */
098    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_USE_TLS, isOptional = true)
099    private boolean replUseTls;
100
101    /** Tells if the certificate validation should be strict or not */
102    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_STRICT_CERT_VALIDATION, isOptional = true)
103    private boolean replStrictCertValidation;
104
105    /** The FQCN of replication client implementation */
106    @ConfigurationElement(attributeType = SchemaConstants.ADS_REPL_CONSUMER_IMPL, isOptional = true)
107    private String replConsumerImpl;
108
109
110    /**
111     * Create a new Replication Consumer instance
112     */
113    public ReplConsumerBean()
114    {
115        super();
116
117        // Enabled by default
118        setEnabled( true );
119    }
120
121
122    /**
123     * @return the replConsumerId
124     */
125    public String getReplConsumerId()
126    {
127        return replConsumerId;
128    }
129
130
131    /**
132     * @param replConsumerId the replication consumer id to set
133     */
134    public void setReplConsumerId( String replConsumerId )
135    {
136        this.replConsumerId = replConsumerId;
137    }
138
139
140    /**
141     * @return the searchBaseDn
142     */
143    public String getSearchBaseDn()
144    {
145        return searchBaseDn;
146    }
147
148
149    /**
150     * @param searchBaseDn the searchBaseDn to set
151     */
152    public void setSearchBaseDn( String searchBaseDn )
153    {
154        this.searchBaseDn = searchBaseDn;
155    }
156
157
158    /**
159     * @return the replProvHostName
160     */
161    public String getReplProvHostName()
162    {
163        return replProvHostName;
164    }
165
166
167    /**
168     * @param replProvHostName the replProvHostName to set
169     */
170    public void setReplProvHostName( String replProvHostName )
171    {
172        this.replProvHostName = replProvHostName;
173    }
174
175
176    /**
177     * @return the replProvPort
178     */
179    public int getReplProvPort()
180    {
181        return replProvPort;
182    }
183
184
185    /**
186     * @param replProvPort the replProvPort to set
187     */
188    public void setReplProvPort( int replProvPort )
189    {
190        this.replProvPort = replProvPort;
191    }
192
193
194    /**
195     * @return the replAliasDerefMode
196     */
197    public String getReplAliasDerefMode()
198    {
199        return replAliasDerefMode;
200    }
201
202
203    /**
204     * @param replAliasDerefMode the replAliasDerefMode to set
205     */
206    public void setReplAliasDerefMode( String replAliasDerefMode )
207    {
208        this.replAliasDerefMode = replAliasDerefMode;
209    }
210
211
212    /**
213     * @return the replAttributes
214     */
215    public List<String> getReplAttributes()
216    {
217        return replAttributes;
218    }
219
220
221    /**
222     * @param replAttributes the replAttribute to set
223     */
224    public void setReplAttributes( List<String> replAttributes )
225    {
226        this.replAttributes = replAttributes;
227    }
228
229
230    /**
231     * @param replAttributes the replAttribute to add
232     */
233    public void addReplAttributes( String... replAttributes )
234    {
235        for ( String at : replAttributes )
236        {
237            this.replAttributes.add( at );
238        }
239    }
240
241
242    /**
243     * @return the replRefreshInterval
244     */
245    public long getReplRefreshInterval()
246    {
247        return replRefreshInterval;
248    }
249
250
251    /**
252     * @param replRefreshInterval the replRefreshInterval to set
253     */
254    public void setReplRefreshInterval( long replRefreshInterval )
255    {
256        this.replRefreshInterval = replRefreshInterval;
257    }
258
259
260    /**
261     * @return the replRefreshNPersist
262     */
263    public boolean isReplRefreshNPersist()
264    {
265        return replRefreshNPersist;
266    }
267
268
269    /**
270     * @param replRefreshNPersist the replRefreshNPersist to set
271     */
272    public void setReplRefreshNPersist( boolean replRefreshNPersist )
273    {
274        this.replRefreshNPersist = replRefreshNPersist;
275    }
276
277
278    /**
279     * @return the replSearchScope
280     */
281    public String getReplSearchScope()
282    {
283        return replSearchScope;
284    }
285
286
287    /**
288     * @param replSearchScope the replSearchScope to set
289     */
290    public void setReplSearchScope( String replSearchScope )
291    {
292        this.replSearchScope = replSearchScope;
293    }
294
295
296    /**
297     * @return the replSearchFilter
298     */
299    public String getReplSearchFilter()
300    {
301        return replSearchFilter;
302    }
303
304
305    /**
306     * @param replSearchFilter the replSearchFilter to set
307     */
308    public void setReplSearchFilter( String replSearchFilter )
309    {
310        this.replSearchFilter = replSearchFilter;
311    }
312
313
314    /**
315     * @return the replSearchSizeLimit
316     */
317    public int getReplSearchSizeLimit()
318    {
319        return replSearchSizeLimit;
320    }
321
322
323    /**
324     * @param replSearchSizeLimit the replSearchSizeLimit to set
325     */
326    public void setReplSearchSizeLimit( int replSearchSizeLimit )
327    {
328        this.replSearchSizeLimit = replSearchSizeLimit;
329    }
330
331
332    /**
333     * @return the replSearchTimeOut
334     */
335    public int getReplSearchTimeout()
336    {
337        return replSearchTimeout;
338    }
339
340
341    /**
342     * @param replSearchTimeout the replSearchTimeout to set
343     */
344    public void setReplSearchTimeout( int replSearchTimeout )
345    {
346        this.replSearchTimeout = replSearchTimeout;
347    }
348
349
350    /**
351     * @return the replUserDn
352     */
353    public String getReplUserDn()
354    {
355        return replUserDn;
356    }
357
358
359    /**
360     * @param replUserDn the replUserDn to set
361     */
362    public void setReplUserDn( String replUserDn )
363    {
364        this.replUserDn = replUserDn;
365    }
366
367
368    /**
369     * @return the replUserPassword
370     */
371    public byte[] getReplUserPassword()
372    {
373        return replUserPassword;
374    }
375
376
377    /**
378     * @param replUserPassword the replUserPassword to set
379     */
380    public void setReplUserPassword( byte[] replUserPassword )
381    {
382        this.replUserPassword = replUserPassword;
383    }
384
385
386    /**
387     * @return the replCookie
388     */
389    public String getReplCookie()
390    {
391        return replCookie;
392    }
393
394
395    /**
396     * @param replCookie the replCookie to set
397     */
398    public void setReplCookie( String replCookie )
399    {
400        this.replCookie = replCookie;
401    }
402
403
404    /**
405     * @return the replUseTls
406     */
407    public boolean isReplUseTls()
408    {
409        return replUseTls;
410    }
411
412
413    /**
414     * @param replUseTls the replUseTls to set
415     */
416    public void setReplUseTls( boolean replUseTls )
417    {
418        this.replUseTls = replUseTls;
419    }
420
421
422    /**
423     * @return the replStrictCertValidation
424     */
425    public boolean isReplStrictCertValidation()
426    {
427        return replStrictCertValidation;
428    }
429
430
431    /**
432     * @param replStrictCertValidation the replStrictCertValidation to set
433     */
434    public void setReplStrictCertValidation( boolean replStrictCertValidation )
435    {
436        this.replStrictCertValidation = replStrictCertValidation;
437    }
438
439
440    /**
441     * @return the replConsumerImpl
442     */
443    public String getReplConsumerImpl()
444    {
445        return replConsumerImpl;
446    }
447
448
449    /**
450     * @param replConsumerImpl the replConsumerImpl to set
451     */
452    public void setReplConsumerImpl( String replConsumerImpl )
453    {
454        this.replConsumerImpl = replConsumerImpl;
455    }
456
457
458    /**
459     * {@inheritDoc}
460     */
461    @Override
462    public String toString( String tabs )
463    {
464        StringBuilder sb = new StringBuilder();
465
466        sb.append( tabs ).append( "Replication provider :\n" );
467        sb.append( super.toString( tabs + "  " ) );
468
469        sb.append( tabs ).append( "  provider ID : " ).append( replConsumerId ).append( '\n' );
470        sb.append( tabs ).append( "  search base Dn : " ).append( searchBaseDn ).append( '\n' );
471        sb.append( tabs ).append( "  provider host name : " ).append( replProvHostName ).append( '\n' );
472        sb.append( tabs ).append( "  provider port : " ).append( replProvPort ).append( '\n' );
473        sb.append( toString( tabs, "  alias dereferencing mode", replAliasDerefMode ) );
474        sb.append( toString( tabs, "  attributes", String.valueOf( replAttributes ) ) );
475        sb.append( tabs ).append( "  refresh interval : " ).append( replRefreshInterval ).append( '\n' );
476        sb.append( toString( tabs, "  refresh and persist mode", replRefreshNPersist ) );
477        sb.append( toString( tabs, "  search scope", replSearchScope ) );
478        sb.append( toString( tabs, "  search filter", replSearchFilter ) );
479        sb.append( tabs ).append( "  search size limit : " ).append( replSearchSizeLimit ).append( '\n' );
480        sb.append( tabs ).append( "  search time limit : " ).append( replSearchTimeout ).append( '\n' );
481        sb.append( toString( tabs, "  user Dn", replUserDn ) );
482        sb.append( toString( tabs, "  user password", String.valueOf( replUserPassword ) ) ); // do not reveal the password, just null or not
483        sb.append( toString( tabs, "  cookie", replCookie ) );
484        sb.append( tabs ).append( "  consumer implementation's FQCN : " ).append( replConsumerImpl ).append( '\n' );
485
486        sb.append( toString( tabs, "  struct certivicate validation", replStrictCertValidation ) );
487        sb.append( toString( tabs, "  use TLS", replUseTls ) );
488
489        return sb.toString();
490    }
491
492
493    /**
494     * {@inheritDoc}
495     */
496    @Override
497    public String toString()
498    {
499        return toString( "" );
500    }
501}