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.util.Network;
27  import org.apache.directory.server.config.ConfigurationElement;
28  
29  
30  /**
31   * A class used to store the Transport configuration.
32   *
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class TransportBean extends AdsBaseBean
36  {
37      /** The default backlog queue size */
38      private static final int DEFAULT_BACKLOG_NB = 50;
39  
40      /** The default number of threads */
41      private static final int DEFAULT_NB_THREADS = 3;
42  
43      /** The unique identifier for this transport */
44      @ConfigurationElement(attributeType = "ads-transportId", isRdn = true)
45      private String transportId;
46  
47      /** The transport address */
48      @ConfigurationElement(attributeType = "ads-transportAddress")
49      private String transportAddress;
50  
51      /** The port number */
52      @ConfigurationElement(attributeType = "ads-systemPort")
53      private int systemPort = -1;
54  
55      /** A flag set if SSL is enabled */
56      @ConfigurationElement(attributeType = "ads-transportEnableSsl", isOptional = true, defaultValue = "false")
57      private boolean transportEnableSsl = false;
58  
59      /** The number of threads to use for the IoAcceptor executor */
60      @ConfigurationElement(attributeType = "ads-transportNbThreads", isOptional = true, defaultValue = "3")
61      private int transportNbThreads = DEFAULT_NB_THREADS;
62  
63      /** The backlog for the transport services */
64      @ConfigurationElement(attributeType = "ads-transportBackLog", isOptional = true, defaultValue = "50")
65      private int transportBackLog = DEFAULT_BACKLOG_NB;
66  
67      /** The transport list of enabled ciphers */
68      @ConfigurationElement(attributeType = "ads-enabledCiphers", isOptional = true)
69      private List<String> enabledCiphers;
70  
71      /** The transport list of enabled protocols */
72      @ConfigurationElement(attributeType = "ads-enabledProtocols", isOptional = true)
73      private List<String> enabledProtocols;
74  
75      /** The transport 'need client auth' flag */
76      @ConfigurationElement(attributeType = "ads-needClientAuth", isOptional = true, defaultValue = "false")
77      private boolean needClientAuth;
78  
79      /** The transport 'want client auth' flag */
80      @ConfigurationElement(attributeType = "ads-wantClientAuth", isOptional = true, defaultValue = "false")
81      private boolean wantClientAuth;
82  
83  
84      /**
85       * Create a new TransportBean instance
86       */
87      public TransportBean()
88      {
89      }
90  
91  
92      /**
93       * @param systemPort the port to set
94       */
95      public void setSystemPort( int systemPort )
96      {
97          this.systemPort = systemPort;
98      }
99  
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 }