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.util.Network;
027import org.apache.directory.server.config.ConfigurationElement;
028
029
030/**
031 * A class used to store the Transport configuration.
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class TransportBean extends AdsBaseBean
036{
037    /** The default backlog queue size */
038    private static final int DEFAULT_BACKLOG_NB = 50;
039
040    /** The default number of threads */
041    private static final int DEFAULT_NB_THREADS = 3;
042
043    /** The unique identifier for this transport */
044    @ConfigurationElement(attributeType = "ads-transportId", isRdn = true)
045    private String transportId;
046
047    /** The transport address */
048    @ConfigurationElement(attributeType = "ads-transportAddress")
049    private String transportAddress;
050
051    /** The port number */
052    @ConfigurationElement(attributeType = "ads-systemPort")
053    private int systemPort = -1;
054
055    /** A flag set if SSL is enabled */
056    @ConfigurationElement(attributeType = "ads-transportEnableSsl", isOptional = true, defaultValue = "false")
057    private boolean transportEnableSsl = false;
058
059    /** The number of threads to use for the IoAcceptor executor */
060    @ConfigurationElement(attributeType = "ads-transportNbThreads", isOptional = true, defaultValue = "3")
061    private int transportNbThreads = DEFAULT_NB_THREADS;
062
063    /** The backlog for the transport services */
064    @ConfigurationElement(attributeType = "ads-transportBackLog", isOptional = true, defaultValue = "50")
065    private int transportBackLog = DEFAULT_BACKLOG_NB;
066
067    /** The transport list of enabled ciphers */
068    @ConfigurationElement(attributeType = "ads-enabledCiphers", isOptional = true)
069    private List<String> enabledCiphers;
070
071    /** The transport list of enabled protocols */
072    @ConfigurationElement(attributeType = "ads-enabledProtocols", isOptional = true)
073    private List<String> enabledProtocols;
074
075    /** The transport 'need client auth' flag */
076    @ConfigurationElement(attributeType = "ads-needClientAuth", isOptional = true, defaultValue = "false")
077    private boolean needClientAuth;
078
079    /** The transport 'want client auth' flag */
080    @ConfigurationElement(attributeType = "ads-wantClientAuth", isOptional = true, defaultValue = "false")
081    private boolean wantClientAuth;
082
083
084    /**
085     * Create a new TransportBean instance
086     */
087    public TransportBean()
088    {
089    }
090
091
092    /**
093     * @param systemPort the port to set
094     */
095    public void setSystemPort( int systemPort )
096    {
097        this.systemPort = systemPort;
098    }
099
100
101    /**
102     * @return the port
103     */
104    public int getSystemPort()
105    {
106        return systemPort;
107    }
108
109
110    /**
111     * @param transportAddress the address to set
112     */
113    public void setTransportAddress( String transportAddress )
114    {
115        this.transportAddress = transportAddress;
116    }
117
118
119    /**
120     * @return the address
121     */
122    public String getTransportAddress()
123    {
124        return transportAddress;
125    }
126
127
128    /**
129     * @return <code>true</code> id SSL is enabled for this transport
130     */
131    public boolean isTransportEnableSSL()
132    {
133        return transportEnableSsl;
134    }
135
136
137    /**
138     * Enable or disable SSL
139     * 
140     * @param transportEnableSSL if <code>true</code>, SSL is enabled.
141     */
142    public void setTransportEnableSSL( boolean transportEnableSSL )
143    {
144        this.transportEnableSsl = transportEnableSSL;
145    }
146
147
148    /**
149     * @return The number of threads used to handle the incoming requests
150     */
151    public int getTransportNbThreads()
152    {
153        return transportNbThreads;
154    }
155
156
157    /**
158     * Sets the number of thread to use to process incoming requests
159     * 
160     * @param transportNbThreads The number of threads
161     */
162    public void setTransportNbThreads( int transportNbThreads )
163    {
164        this.transportNbThreads = transportNbThreads;
165    }
166
167
168    /**
169     * @return the size of the incoming request waiting queue
170     */
171    public int getTransportBackLog()
172    {
173        return transportBackLog;
174    }
175
176
177    /**
178     * Sets the size of the incoming requests waiting queue
179     * 
180     * @param transportBacklog The size of waiting request queue
181     */
182    public void setTransportBackLog( int transportBacklog )
183    {
184        this.transportBackLog = transportBacklog;
185    }
186
187
188    /**
189     * @return the transportId
190     */
191    public String getTransportId()
192    {
193        return transportId;
194    }
195
196
197    /**
198     * @param transportId the transportId to set
199     */
200    public void setTransportId( String transportId )
201    {
202        this.transportId = transportId;
203    }
204
205
206    /**
207     * @param needClientAuth The flag to set when the client authentication is needed
208     */
209    public void setNeedClientAuth( boolean needClientAuth )
210    {
211        this.needClientAuth = needClientAuth;
212    }
213
214
215    /**
216     * @return the needClientAuth flag
217     */
218    public boolean getNeedClientAuth()
219    {
220        return needClientAuth;
221    }
222
223
224    /**
225     * @param wantClientAuth The flag to set when the client authentication is wanted
226     */
227    public void setWantClientAuth( boolean wantClientAuth )
228    {
229        this.wantClientAuth = wantClientAuth;
230    }
231
232
233    /**
234     * @return the wantClientAuth flag
235     */
236    public boolean getWantClientAuth()
237    {
238        return wantClientAuth;
239    }
240
241
242    /**
243     * @return the EnabledCiphers list
244     */
245    public List<String> getEnabledCiphers()
246    {
247        return enabledCiphers;
248    }
249
250
251    /**
252     * @param enabledCiphers the enabledCiphers to set
253     */
254    public void setEnabledCiphers( List<String> enabledCiphers )
255    {
256        this.enabledCiphers = enabledCiphers;
257    }
258
259
260    /**
261     * @param enabledCiphers the enabledCiphers to add
262     */
263    public void addEnabledCiphers( String... enabledCiphers )
264    {
265        if ( this.enabledCiphers == null )
266        {
267            this.enabledCiphers = new ArrayList<>();
268        }
269
270        for ( String enabledCipher : enabledCiphers )
271        {
272            this.enabledCiphers.add( enabledCipher );
273        }
274    }
275
276
277    /**
278     * @return the enabledProtocols list
279     */
280    public List<String> getEnabledProtocols()
281    {
282        return enabledProtocols;
283    }
284
285
286    /**
287     * @param enabledProtocols the enabledProtocols to set
288     */
289    public void setEnabledProtocols( List<String> enabledProtocols )
290    {
291        this.enabledProtocols = enabledProtocols;
292    }
293
294
295    /**
296     * @param enabledProtocols the enabledProtocols to add
297     */
298    public void addEnabledProtocols( String... enabledProtocols )
299    {
300        if ( this.enabledProtocols == null )
301        {
302            this.enabledProtocols = new ArrayList<>();
303        }
304
305        for ( String enabledProtocol : enabledProtocols )
306        {
307            this.enabledProtocols.add( enabledProtocol );
308        }
309    }
310
311
312    /**
313     * {@inheritDoc}
314     */
315    @Override
316    public String toString( String tabs )
317    {
318        StringBuilder sb = new StringBuilder();
319
320        sb.append( toString( tabs, "transport id", transportId ) );
321        sb.append( tabs ).append( "transport address : " );
322
323        if ( transportAddress == null )
324        {
325            sb.append( Network.LOOPBACK_HOSTNAME ).append( '\n' );
326        }
327        else
328        {
329            sb.append( transportAddress ).append( '\n' );
330        }
331
332        sb.append( tabs ).append( "transport port : " ).append( systemPort ).append( '\n' );
333        sb.append( tabs ).append( "transport backlog : " ).append( transportBackLog ).append( '\n' );
334        sb.append( tabs ).append( "transport nb threads : " ).append( transportNbThreads ).append( '\n' );
335        sb.append( toString( tabs, "SSL enabled", transportEnableSsl ) );
336        sb.append( toString( tabs, "Need Client Auth", needClientAuth ) );
337        sb.append( toString( tabs, "Want Client Auth", wantClientAuth ) );
338
339        if ( ( enabledCiphers != null ) && !enabledCiphers.isEmpty() )
340        {
341            sb.append( tabs ).append( "Enabled Ciphers :\n" );
342
343            for ( String enabledCipher : enabledCiphers )
344            {
345                sb.append( tabs ).append( "    " ).append( enabledCipher ).append( "\n" );
346            }
347        }
348
349        if ( ( enabledProtocols != null ) && !enabledProtocols.isEmpty() )
350        {
351            sb.append( tabs ).append( "  Enabled Protocols :\n" );
352
353            for ( String enabledProtocol : enabledProtocols )
354            {
355                sb.append( tabs ).append( "    " ).append( enabledProtocol ).append( "\n" );
356            }
357        }
358
359        return sb.toString();
360    }
361
362
363    /**
364     * {@inheritDoc}
365     */
366    @Override
367    public String toString()
368    {
369        return toString( "" );
370    }
371}