View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20  
21   */
22  package openr66.configuration;
23  
24  import goldengate.common.crypto.Des;
25  import goldengate.common.crypto.ssl.GgSecureKeyStore;
26  import goldengate.common.crypto.ssl.GgSslContextFactory;
27  import goldengate.common.database.DbAdmin;
28  import goldengate.common.database.data.AbstractDbData.UpdatedInfo;
29  import goldengate.common.database.exception.GoldenGateDatabaseException;
30  import goldengate.common.database.exception.GoldenGateDatabaseNoConnectionException;
31  import goldengate.common.digest.FilesystemBasedDigest;
32  import goldengate.common.digest.FilesystemBasedDigest.DigestAlgo;
33  import goldengate.common.exception.CryptoException;
34  import goldengate.common.file.DirInterface;
35  import goldengate.common.file.filesystembased.FilesystemBasedDirImpl;
36  import goldengate.common.file.filesystembased.FilesystemBasedFileParameterImpl;
37  import goldengate.common.file.filesystembased.specific.FilesystemBasedDirJdk5;
38  import goldengate.common.file.filesystembased.specific.FilesystemBasedDirJdk6;
39  import goldengate.common.logging.GgInternalLogger;
40  import goldengate.common.logging.GgInternalLoggerFactory;
41  import goldengate.common.xml.XmlDecl;
42  import goldengate.common.xml.XmlHash;
43  import goldengate.common.xml.XmlType;
44  import goldengate.common.xml.XmlUtil;
45  import goldengate.common.xml.XmlValue;
46  import goldengate.snmp.SnmpConfiguration;
47  
48  import java.io.File;
49  import java.io.IOException;
50  import java.net.InetAddress;
51  import java.net.InetSocketAddress;
52  import java.net.UnknownHostException;
53  import java.util.List;
54  
55  import openr66.context.authentication.R66Auth;
56  import openr66.context.filesystem.R66Dir;
57  import openr66.context.task.localexec.LocalExecClient;
58  import openr66.database.DbConstant;
59  import openr66.database.data.DbConfiguration;
60  import openr66.database.model.DbModelFactory;
61  import openr66.protocol.configuration.Configuration;
62  import openr66.protocol.exception.OpenR66ProtocolSystemException;
63  import openr66.protocol.networkhandler.R66ConstraintLimitHandler;
64  import openr66.protocol.networkhandler.ssl.NetworkSslServerPipelineFactory;
65  import openr66.protocol.utils.FileUtils;
66  
67  import org.dom4j.Document;
68  import org.dom4j.DocumentException;
69  import org.dom4j.io.SAXReader;
70  import org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler;
71  
72  /**
73   * File Based Configuration
74   *
75   * @author frederic bregier
76   *
77   */
78  public class FileBasedConfiguration {
79      /**
80       * Internal Logger
81       */
82      private static final GgInternalLogger logger = GgInternalLoggerFactory
83              .getLogger(FileBasedConfiguration.class);
84  
85      /**
86       * SERVER HOSTID
87       */
88      private static final String XML_SERVER_HOSTID = "hostid";
89  
90      /**
91       * SERVER SSL HOSTID
92       */
93      private static final String XML_SERVER_SSLHOSTID = "sslhostid";
94  
95      /**
96       * ADMINISTRATOR SERVER NAME (shutdown)
97       */
98      private static final String XML_SERVER_ADMIN = "serveradmin";
99  
100     /**
101      * SERVER PASSWORD (shutdown)
102      */
103     private static final String XML_SERVER_PASSWD = "serverpasswd";
104     /**
105      * Authentication
106      */
107     private static final String XML_AUTHENTIFICATION_FILE = "authentfile";
108 
109     /**
110      * SERVER PORT
111      */
112     private static final String XML_SERVER_PORT = "serverport";
113 
114     /**
115      * SERVER SSL PORT
116      */
117     private static final String XML_SERVER_SSLPORT = "serversslport";
118 
119     /**
120      * SERVER HTTP PORT
121      */
122     private static final String XML_SERVER_HTTPPORT = "serverhttpport";
123 
124     /**
125      * SERVER HTTP PORT
126      */
127     private static final String XML_SERVER_HTTPSPORT = "serverhttpsport";
128 
129     /**
130      * SERVER SSL STOREKEY PATH
131      */
132     private static final String XML_PATH_KEYPATH = "keypath";
133 
134     /**
135      * SERVER SSL KEY PASS
136      */
137     private static final String XML_PATH_KEYPASS = "keypass";
138 
139     /**
140      * SERVER SSL STOREKEY PASS
141      */
142     private static final String XML_PATH_KEYSTOREPASS = "keystorepass";
143 
144     /**
145      * SERVER SSL TRUSTSTOREKEY PATH
146      */
147     private static final String XML_PATH_TRUSTKEYPATH = "trustkeypath";
148 
149     /**
150      * SERVER SSL TRUSTSTOREKEY PASS
151      */
152     private static final String XML_PATH_TRUSTKEYSTOREPASS = "trustkeystorepass";
153 
154     /**
155      * SERVER SSL STOREKEY PATH ADMIN
156      */
157     private static final String XML_PATH_ADMIN_KEYPATH = "admkeypath";
158 
159     /**
160      * SERVER SSL KEY PASS ADMIN
161      */
162     private static final String XML_PATH_ADMIN_KEYPASS = "admkeypass";
163 
164     /**
165      * SERVER SSL STOREKEY PASS ADMIN
166      */
167     private static final String XML_PATH_ADMIN_KEYSTOREPASS = "admkeystorepass";
168 
169     /**
170      * SERVER CRYPTO for Password
171      */
172     private static final String XML_PATH_CRYPTOKEY = "cryptokey";
173     /**
174      * Base Directory
175      */
176     private static final String XML_SERVER_HOME = "serverhome";
177 
178     /**
179      * IN Directory
180      */
181     private static final String XML_INPATH = "in";
182 
183     /**
184      * OUT Directory
185      */
186     private static final String XML_OUTPATH = "out";
187 
188     /**
189      * ARCHIVE Directory
190      */
191     private static final String XML_ARCHIVEPATH = "arch";
192 
193     /**
194      * WORKING Directory
195      */
196     private static final String XML_WORKINGPATH = "work";
197 
198     /**
199      * CONFIG Directory
200      */
201     private static final String XML_CONFIGPATH = "conf";
202 
203     /**
204      * HTTP Admin Directory
205      */
206     private static final String XML_HTTPADMINPATH = "httpadmin";
207     /**
208      * Use SSL for R66 connection
209      */
210     private static final String XML_USESSL = "usessl";
211 
212     /**
213      * Use non SSL for R66 connection
214      */
215     private static final String XML_USENOSSL = "usenossl";
216 
217     /**
218      * Use HTTP compression for R66 HTTP connection
219      */
220     private static final String XML_USEHTTPCOMP = "usehttpcomp";
221 
222     /**
223      * SERVER SSL Use TrustStore for Client Authentication
224      */
225     private static final String XML_USECLIENT_AUTHENT = "trustuseclientauthenticate";
226 
227     /**
228      * Limit per session
229      */
230     private static final String XML_LIMITSESSION = "sessionlimit";
231 
232     /**
233      * Limit global
234      */
235     private static final String XML_LIMITGLOBAL = "globallimit";
236 
237     /**
238      * Delay between two checks for Limit
239      */
240     private static final String XML_LIMITDELAY = "delaylimit";
241     /**
242      * Monitoring: how long in ms to get back in monitoring
243      */
244     private static final String XML_MONITOR_PASTLIMIT = "pastlimit";
245     /**
246      * Monitoring: minimal interval in ms before redo real monitoring
247      */
248     private static final String XML_MONITOR_MINIMALDELAY = "minimaldelay";
249     /**
250      * Monitoring: snmp configuration file (if empty, no snmp support)
251      */
252     private static final String XML_MONITOR_SNMP_CONFIG = "snmpconfig";
253     /**
254      * In case of multiple OpenR66 Monitors behing a loadbalancer (ha config)
255      */
256     private static final String XML_MULTIPLE_MONITORS = "multiplemonitors";
257     /**
258      * Usage of CPU Limit
259      */
260     private static final String XML_CSTRT_USECPULIMIT = "usecpulimit";
261 
262     /**
263      * Usage of JDK CPU Limit (True) or SysMon CPU Limit
264      */
265     private static final String XML_CSTRT_USECPUJDKLIMIT = "usejdkcpulimit";
266 
267     /**
268      * CPU LIMIT between 0 and 1, where 1 stands for no limit
269      */
270     private static final String XML_CSTRT_CPULIMIT = "cpulimit";
271     /**
272      * Connection limit where 0 stands for no limit
273      */
274     private static final String XML_CSTRT_CONNLIMIT = "connlimit";
275     /**
276      * CPU LOW limit to apply increase of throttle
277      */
278     private static final String XML_CSTRT_LOWCPULIMIT = "lowcpulimit";
279     /**
280      * CPU HIGH limit to apply decrease of throttle, 0 meaning no throttle activated
281      */
282     private static final String XML_CSTRT_HIGHCPULIMIT = "highcpulimit";
283     /**
284      * PERCENTAGE DECREASE of Bandwidth
285      */
286     private static final String XML_CSTRT_PERCENTDECREASE = "percentdecrease";
287     /**
288      * Delay between 2 checks of throttle test
289      */
290     private static final String XML_CSTRT_DELAYTHROTTLE = "delaythrottle";
291     /**
292      * Bandwidth low limit to not got below
293      */
294     private static final String XML_CSTRT_LIMITLOWBANDWIDTH = "limitlowbandwidth";
295     /**
296      * Usage of checking remote address with the DbHost definition
297      */
298     private static final String XML_CHECK_ADDRESS = "checkaddress";
299     /**
300      * Usage of checking remote address also for Client
301      */
302     private static final String XML_CHECK_CLIENTADDRESS = "checkclientaddress";
303 
304     /**
305      * In case of No Db Client, Usage of saving TaskRunner into independent XML file
306      */
307     private static final String XML_SAVE_TASKRUNNERNODB = "taskrunnernodb";
308 
309     /**
310      * Use external GoldenGate Local Exec for ExecTask and ExecMoveTask
311      */
312     private static final String XML_USELOCALEXEC = "uselocalexec";
313 
314     /**
315      * Address of GoldenGate Local Exec for ExecTask and ExecMoveTask
316      */
317     private static final String XML_LEXECADDR = "lexecaddr";
318 
319     /**
320      * Port of GoldenGate Local Exec for ExecTask and ExecMoveTask
321      */
322     private static final String XML_LEXECPORT = "lexecport";
323 
324     /**
325      * Default number of threads in pool for Server.
326      */
327     private static final String XML_SERVER_THREAD = "serverthread";
328 
329     /**
330      * Default number of threads in pool for Client (truly concurrent).
331      */
332     private static final String XML_CLIENT_THREAD = "clientthread";
333 
334     /**
335      * Memory Limit to use.
336      */
337     private static final String XML_MEMORY_LIMIT = "memorylimit";
338 
339     /**
340      * Limit of number of active Runner from Commander
341      */
342     private static final String XML_LIMITRUNNING = "runlimit";
343 
344     /**
345      * Delay between two checks for Commander
346      */
347     private static final String XML_DELAYCOMMANDER = "delaycommand";
348 
349     /**
350      * Delay between two checks for Commander
351      */
352     private static final String XML_DELAYRETRY = "delayretry";
353 
354     /**
355      * Nb of milliseconds after connection is in timeout
356      */
357     private static final String XML_TIMEOUTCON = "timeoutcon";
358 
359     /**
360      * Should a file MD5 SHA1 be computed using NIO
361      */
362     private static final String XML_USENIO = "usenio";
363 
364     /**
365      * What Digest to use: CRC32=0, ADLER32=1,  
366         MD5=2, MD2=3, SHA1=4, SHA256=5, SHA384=6, SHA512=7
367      */
368     private static final String XML_DIGEST = "digest";
369     /**
370      * Should a file MD5 be computed using FastMD5
371      */
372     private static final String XML_USEFASTMD5 = "usefastmd5";
373 
374     /**
375      * If using Fast MD5, should we used the binary JNI library, empty meaning
376      * no
377      */
378     private static final String XML_FASTMD5 = "fastmd5";
379 
380     /**
381      * number of rank to go back when a transfer is restarted.
382      * restart is gaprestart*blocksize
383      */
384     private static final String XML_GAPRESTART = "gaprestart";
385     /**
386      * Size by default of block size for receive/sending files. Should be a
387      * multiple of 8192 (maximum = 64K due to block limitation to 2 bytes)
388      */
389     private static final String XML_BLOCKSIZE = "blocksize";
390     /**
391      * Database Driver as of oracle, mysql, postgresql, h2
392      */
393     private static final String XML_DBDRIVER = "dbdriver";
394 
395     /**
396      * Database Server connection string as of
397      * jdbc:type://[host:port],[failoverhost:port]
398      * .../[database][?propertyName1][
399      * =propertyValue1][&propertyName2][=propertyValue2]...
400      */
401     private static final String XML_DBSERVER = "dbserver";
402 
403     /**
404      * Database User
405      */
406     private static final String XML_DBUSER = "dbuser";
407 
408     /**
409      * Database Password
410      */
411     private static final String XML_DBPASSWD = "dbpasswd";
412     
413     /**
414      * Check version in protocol
415      */
416     private static final String XML_CHECKVERSION = "checkversion";
417     /**
418      * Check version in protocol
419      */
420     private static final String XML_BUSINESS = "business";
421     /**
422      * Check version in protocol
423      */
424     private static final String XML_BUSINESSID = "businessid";
425     
426     /**
427      * Structure of the Configuration file
428      *
429      */
430     private static final XmlDecl [] configIdentityDecls = {
431         // identity
432         new XmlDecl(XmlType.STRING, XML_SERVER_HOSTID), 
433         new XmlDecl(XmlType.STRING, XML_SERVER_SSLHOSTID),
434         new XmlDecl(XmlType.STRING, XML_PATH_CRYPTOKEY),
435         new XmlDecl(XmlType.STRING, XML_AUTHENTIFICATION_FILE)
436     };
437     /**
438      * Structure of the Configuration file
439      *
440      */
441     private static final XmlDecl [] configServerParamDecls = {
442         // server
443         new XmlDecl(XmlType.BOOLEAN, XML_USESSL), 
444         new XmlDecl(XmlType.BOOLEAN, XML_USENOSSL), 
445         new XmlDecl(XmlType.BOOLEAN, XML_USEHTTPCOMP),
446         new XmlDecl(XmlType.BOOLEAN, XML_USELOCALEXEC), 
447         new XmlDecl(XmlType.STRING, XML_LEXECADDR), 
448         new XmlDecl(XmlType.INTEGER, XML_LEXECPORT),
449         new XmlDecl(XmlType.BOOLEAN, XML_CHECK_ADDRESS),
450         new XmlDecl(XmlType.BOOLEAN, XML_CHECK_CLIENTADDRESS),
451         new XmlDecl(XmlType.STRING, XML_SERVER_ADMIN), 
452         new XmlDecl(XmlType.STRING, XML_SERVER_PASSWD),
453         new XmlDecl(XmlType.STRING, XML_HTTPADMINPATH),
454         new XmlDecl(XmlType.STRING, XML_PATH_ADMIN_KEYPATH), 
455         new XmlDecl(XmlType.STRING, XML_PATH_ADMIN_KEYSTOREPASS), 
456         new XmlDecl(XmlType.STRING, XML_PATH_ADMIN_KEYPASS),
457         new XmlDecl(XmlType.LONG, XML_MONITOR_PASTLIMIT),
458         new XmlDecl(XmlType.LONG, XML_MONITOR_MINIMALDELAY),
459         new XmlDecl(XmlType.STRING, XML_MONITOR_SNMP_CONFIG),
460         new XmlDecl(XmlType.INTEGER, XML_MULTIPLE_MONITORS)
461     };
462     /**
463      * Structure of the Configuration file
464      *
465      */
466     private static final XmlDecl [] configNetworkServerDecls = {
467         // network
468         new XmlDecl(XmlType.INTEGER, XML_SERVER_PORT),
469         new XmlDecl(XmlType.INTEGER, XML_SERVER_SSLPORT),
470         new XmlDecl(XmlType.INTEGER, XML_SERVER_HTTPPORT),
471         new XmlDecl(XmlType.INTEGER, XML_SERVER_HTTPSPORT)
472     };
473 
474     /**
475      * Structure of the Configuration file
476      *
477      */
478     private static final XmlDecl [] configSslDecls = {
479         // ssl
480         new XmlDecl(XmlType.STRING, XML_PATH_KEYPATH),
481         new XmlDecl(XmlType.STRING, XML_PATH_KEYSTOREPASS),
482         new XmlDecl(XmlType.STRING, XML_PATH_KEYPASS), 
483         new XmlDecl(XmlType.STRING, XML_PATH_TRUSTKEYPATH), 
484         new XmlDecl(XmlType.STRING, XML_PATH_TRUSTKEYSTOREPASS), 
485         new XmlDecl(XmlType.BOOLEAN, XML_USECLIENT_AUTHENT)
486     };
487     /**
488      * Structure of the Configuration file
489      *
490      */
491     private static final XmlDecl [] configDbDecls = {
492         //db
493         new XmlDecl(XmlType.STRING, XML_DBDRIVER), 
494         new XmlDecl(XmlType.STRING, XML_DBSERVER),
495         new XmlDecl(XmlType.STRING, XML_DBUSER), 
496         new XmlDecl(XmlType.STRING, XML_DBPASSWD),
497         new XmlDecl(XmlType.BOOLEAN, XML_SAVE_TASKRUNNERNODB)
498     };
499  
500     /**
501      * Structure of the Configuration file
502      *
503      */
504     private static final XmlDecl [] configLimitDecls = {
505         // limit
506         new XmlDecl(XmlType.LONG, XML_LIMITSESSION), 
507         new XmlDecl(XmlType.LONG, XML_LIMITGLOBAL), 
508         new XmlDecl(XmlType.LONG, XML_LIMITDELAY),
509         new XmlDecl(XmlType.INTEGER, XML_LIMITRUNNING), 
510         new XmlDecl(XmlType.LONG, XML_DELAYCOMMANDER), 
511         new XmlDecl(XmlType.LONG, XML_DELAYRETRY), 
512         new XmlDecl(XmlType.INTEGER, XML_SERVER_THREAD), 
513         new XmlDecl(XmlType.INTEGER, XML_CLIENT_THREAD), 
514         new XmlDecl(XmlType.LONG, XML_MEMORY_LIMIT), 
515         new XmlDecl(XmlType.BOOLEAN, XML_CSTRT_USECPULIMIT),
516         new XmlDecl(XmlType.BOOLEAN, XML_CSTRT_USECPUJDKLIMIT),
517         new XmlDecl(XmlType.DOUBLE, XML_CSTRT_CPULIMIT),
518         new XmlDecl(XmlType.INTEGER, XML_CSTRT_CONNLIMIT),
519         new XmlDecl(XmlType.DOUBLE, XML_CSTRT_LOWCPULIMIT),
520         new XmlDecl(XmlType.DOUBLE, XML_CSTRT_HIGHCPULIMIT),
521         new XmlDecl(XmlType.DOUBLE, XML_CSTRT_PERCENTDECREASE),
522         new XmlDecl(XmlType.LONG, XML_CSTRT_LIMITLOWBANDWIDTH),
523         new XmlDecl(XmlType.LONG, XML_CSTRT_DELAYTHROTTLE),
524         new XmlDecl(XmlType.LONG, XML_TIMEOUTCON),
525         new XmlDecl(XmlType.BOOLEAN, XML_USENIO),
526         new XmlDecl(XmlType.INTEGER, XML_DIGEST), 
527         new XmlDecl(XmlType.BOOLEAN, XML_USEFASTMD5), 
528         new XmlDecl(XmlType.STRING, XML_FASTMD5), 
529         new XmlDecl(XmlType.INTEGER, XML_GAPRESTART),
530         new XmlDecl(XmlType.INTEGER, XML_BLOCKSIZE),
531         new XmlDecl(XmlType.BOOLEAN, XML_CHECKVERSION)
532     };
533     /**
534      * Structure of the Configuration file
535      *
536      */
537     private static final XmlDecl [] configSubmitLimitDecls = {
538         // limit
539         new XmlDecl(XmlType.INTEGER, XML_BLOCKSIZE)
540     };
541     /**
542      * Structure of the Configuration file
543      *
544      */
545     private static final XmlDecl [] configClientParamDecls = {
546         // client
547         new XmlDecl(XmlType.BOOLEAN, XML_SAVE_TASKRUNNERNODB), 
548     };
549     /**
550      * Structure of the Configuration file
551      *
552      */
553     private static final XmlDecl [] configDirectoryDecls = {
554         // directory
555         new XmlDecl(XmlType.STRING, XML_SERVER_HOME), 
556         new XmlDecl(XmlType.STRING, XML_INPATH), 
557         new XmlDecl(XmlType.STRING, XML_OUTPATH), 
558         new XmlDecl(XmlType.STRING, XML_ARCHIVEPATH), 
559         new XmlDecl(XmlType.STRING, XML_WORKINGPATH),
560         new XmlDecl(XmlType.STRING, XML_CONFIGPATH)
561     };
562 
563     /**
564      * Overall structure of the Configuration file
565      */
566     private static final String XML_ROOT = "/config/";
567     private static final String XML_IDENTITY = "identity";
568     private static final String XML_SERVER = "server";
569     private static final String XML_CLIENT = "client";
570     private static final String XML_DIRECTORY = "directory";
571     private static final String XML_LIMIT = "limit";
572     private static final String XML_NETWORK = "network";
573     private static final String XML_SSL = "ssl";
574     private static final String XML_DB = "db";
575     
576     /**
577      * Global Structure for Server Configuration
578      */
579     private static final XmlDecl[] configServer = {
580         new XmlDecl(XML_IDENTITY, XmlType.XVAL, XML_ROOT+XML_IDENTITY, configIdentityDecls, false),
581         new XmlDecl(XML_SERVER, XmlType.XVAL, XML_ROOT+XML_SERVER, configServerParamDecls, false),
582         new XmlDecl(XML_NETWORK, XmlType.XVAL, XML_ROOT+XML_NETWORK, configNetworkServerDecls, false),
583         new XmlDecl(XML_SSL, XmlType.XVAL, XML_ROOT+XML_SSL, configSslDecls, false),
584         new XmlDecl(XML_DIRECTORY, XmlType.XVAL, XML_ROOT+XML_DIRECTORY, configDirectoryDecls, false),
585         new XmlDecl(XML_LIMIT, XmlType.XVAL, XML_ROOT+XML_LIMIT, configLimitDecls, false),
586         new XmlDecl(XML_DB, XmlType.XVAL, XML_ROOT+XML_DB, configDbDecls, false),
587         new XmlDecl(XML_BUSINESS, XmlType.STRING, XML_ROOT+XML_BUSINESS+"/"+XML_BUSINESSID, true)
588     };
589     /**
590      * Global Structure for Client Configuration
591      */
592     private static final XmlDecl[] configClient = {
593         new XmlDecl(XML_IDENTITY, XmlType.XVAL, XML_ROOT+XML_IDENTITY, configIdentityDecls, false),
594         new XmlDecl(XML_CLIENT, XmlType.XVAL, XML_ROOT+XML_CLIENT, configClientParamDecls, false),
595         new XmlDecl(XML_SSL, XmlType.XVAL, XML_ROOT+XML_SSL, configSslDecls, false),
596         new XmlDecl(XML_DIRECTORY, XmlType.XVAL, XML_ROOT+XML_DIRECTORY, configDirectoryDecls, false),
597         new XmlDecl(XML_LIMIT, XmlType.XVAL, XML_ROOT+XML_LIMIT, configLimitDecls, false),
598         new XmlDecl(XML_DB, XmlType.XVAL, XML_ROOT+XML_DB, configDbDecls, false),
599         new XmlDecl(XML_BUSINESS, XmlType.STRING, XML_ROOT+XML_BUSINESS+"/"+XML_BUSINESSID, true)
600     };
601     /**
602      * Global Structure for Submit only Client Configuration
603      */
604     private static final XmlDecl[] configSubmitClient = {
605         new XmlDecl(XML_IDENTITY, XmlType.XVAL, XML_ROOT+XML_IDENTITY, configIdentityDecls, false),
606         new XmlDecl(XML_LIMIT, XmlType.XVAL, XML_ROOT+XML_LIMIT, configSubmitLimitDecls, false),
607         new XmlDecl(XML_DB, XmlType.XVAL, XML_ROOT+XML_DB, configDbDecls, false)
608     };
609     private static XmlValue[] configuration = null;
610     private static XmlHash hashConfig = null; 
611     
612     private static boolean loadIdentity(Configuration config) {
613         XmlValue value = hashConfig.get(XML_SERVER_HOSTID);
614         if (value != null && (!value.isEmpty())) {
615             config.HOST_ID = value.getString();
616         } else {
617             logger.error("Unable to find Host ID in Config file");
618             return false;
619         }
620         value = hashConfig.get(XML_SERVER_SSLHOSTID);
621         if (value != null && (!value.isEmpty())) {
622             config.HOST_SSLID = value.getString();
623         } else {
624             logger
625                     .warn("Unable to find Host SSL ID in Config file so no SSL support will be used");
626             config.useSSL = false;
627             config.HOST_SSLID = null;
628         }
629         return setCryptoKey(config);
630     }
631     
632     private static boolean loadAuthentication(Configuration config) {
633         if (!DbConstant.admin.isConnected) {
634             // if no database, must load authentication from file
635             XmlValue value = hashConfig.get(XML_AUTHENTIFICATION_FILE);
636             if (value != null && (!value.isEmpty())) {
637                 String fileauthent = value.getString();
638                 if (!AuthenticationFileBasedConfiguration
639                         .loadAuthentication(config, fileauthent)) {
640                     return false;
641                 }
642             } else {
643                 logger.warn("Unable to find Authentication file in Config file");
644                 return false;
645             }
646         }
647         return true;
648     }
649     
650     private static boolean loadServerParam(Configuration config) {
651         XmlValue value = hashConfig.get(XML_USESSL);
652         if (value != null && (!value.isEmpty())) {
653             config.useSSL = value.getBoolean();
654         }
655         value = hashConfig.get(XML_USENOSSL);
656         if (value != null && (!value.isEmpty())) {
657             config.useNOSSL = value.getBoolean();
658         }
659         value = hashConfig.get(XML_USEHTTPCOMP);
660         if (value != null && (!value.isEmpty())) {
661             config.useHttpCompression = value.getBoolean();
662         }
663         value = hashConfig.get(XML_USELOCALEXEC);
664         if (value != null && (!value.isEmpty())) {
665             config.useLocalExec = value.getBoolean();
666             if (config.useLocalExec) {
667                 value = hashConfig.get(XML_LEXECADDR);
668                 String saddr;
669                 InetAddress addr;
670                 if (value != null && (!value.isEmpty())) {
671                     saddr = value.getString();
672                     try {
673                         addr = InetAddress.getByName(saddr);
674                     } catch (UnknownHostException e) {
675                         logger.error("Unable to find LocalExec Address in Config file");
676                         return false;
677                     }
678                 } else {
679                     logger.warn("Unable to find LocalExec Address in Config file");
680                     try {
681                         addr = InetAddress.getByAddress(new byte[]{127,0,0,1});
682                     } catch (UnknownHostException e) {
683                         logger.error("Unable to find LocalExec Address in Config file");
684                         return false;
685                     }
686                 }
687                 value = hashConfig.get(XML_LEXECPORT);
688                 int port;
689                 if (value != null && (!value.isEmpty())) {
690                     port = value.getInteger();
691                 } else {
692                     port = 9999;
693                 }
694                 LocalExecClient.address = new InetSocketAddress(addr, port);
695             }
696         }
697         value = hashConfig.get(XML_CHECK_ADDRESS);
698         if (value != null && (!value.isEmpty())) {
699             config.checkRemoteAddress = value.getBoolean();
700         }
701         value = hashConfig.get(XML_CHECK_CLIENTADDRESS);
702         if (value != null && (!value.isEmpty())) {
703             config.checkClientAddress = value.getBoolean();
704         }
705         value = hashConfig.get(XML_SERVER_ADMIN);
706         if (value != null && (!value.isEmpty())) {
707             config.ADMINNAME = value.getString();
708         } else {
709             logger.error("Unable to find Administrator name in Config file");
710             return false;
711         }
712         if (config.cryptoKey == null) {
713             if (! setCryptoKey(config)) {
714                 logger.error("Unable to find Crypto Key in Config file");
715                 return false;
716             }
717         }
718         String passwd;
719         value = hashConfig.get(XML_SERVER_PASSWD);
720         if (value != null && (!value.isEmpty())) {
721             passwd = value.getString();
722         } else {
723             logger.error("Unable to find Password in Config file");
724             return false;
725         }
726         byte[] decodedByteKeys = null;
727         try {
728             decodedByteKeys =
729                 config.cryptoKey.decryptHexInBytes(passwd);
730         } catch (Exception e) {
731             logger.error(
732                     "Unable to Decrypt Server Password in Config file from: " +
733                             passwd, e);
734             return false;
735         }
736         config.setSERVERKEY(decodedByteKeys);
737         value = hashConfig.get(XML_HTTPADMINPATH);
738         if (value == null || (value.isEmpty())) {
739             logger.error("Unable to find Http Admin Base in Config file");
740             return false;
741         }
742         String path = value.getString();
743         if (path == null || path.length() == 0) {
744             logger.error("Unable to set correct Http Admin Base in Config file");
745             return false;
746         }
747         File file = new File(path);
748         if (!file.isDirectory()) {
749             logger.error("Http Admin is not a directory in Config file");
750             return false;
751         }
752         try {
753             config.httpBasePath =
754                 FilesystemBasedDirImpl.normalizePath(file.getCanonicalPath())+ 
755                 DirInterface.SEPARATOR;
756         } catch (IOException e1) {
757             logger.error("Unable to set Http Admin Path in Config file");
758             return false;
759         }
760 
761         // Key for HTTPS
762         value = hashConfig.get(XML_PATH_ADMIN_KEYPATH);
763         if (value != null && (!value.isEmpty())) {
764             String keypath = value.getString();
765             if ((keypath == null) || (keypath.length() == 0)) {
766                 logger.error("Bad Key Path");
767                 return false;
768             }
769             value = hashConfig.get(XML_PATH_ADMIN_KEYSTOREPASS);
770             if (value == null || (value.isEmpty())) {
771                 logger.error("Unable to find KeyStore Passwd");
772                 return false;
773             }
774             String keystorepass = value.getString();
775             if ((keystorepass == null) || (keystorepass.length() == 0)) {
776                 logger.error("Bad KeyStore Passwd");
777                 return false;
778             }
779             value = hashConfig.get(XML_PATH_ADMIN_KEYPASS);
780             if (value == null || (value.isEmpty())) {
781                 logger.error("Unable to find Key Passwd");
782                 return false;
783             }
784             String keypass = value.getString();
785             if ((keypass == null) || (keypass.length() == 0)) {
786                 logger.error("Bad Key Passwd");
787                 return false;
788             }
789             try {
790                 Configuration.ggSecureKeyStore =
791                     new GgSecureKeyStore(keypath, keystorepass,
792                             keypass);
793             } catch (CryptoException e) {
794                 logger.error("Bad SecureKeyStore construction for AdminSsl");
795                 return false;
796             }
797             // No client authentication
798             Configuration.ggSecureKeyStore.initEmptyTrustStore();
799             Configuration.ggSslContextFactory =
800                 new GgSslContextFactory(
801                         Configuration.ggSecureKeyStore, true);
802         }
803         value = hashConfig.get(XML_MONITOR_PASTLIMIT);
804         if (value != null && (!value.isEmpty())) {
805             config.pastLimit = (value.getLong()/10)*10;
806         }
807         value = hashConfig.get(XML_MONITOR_MINIMALDELAY);
808         if (value != null && (!value.isEmpty())) {
809             config.minimalDelay = (value.getLong()/10)*10;
810         }
811         value = hashConfig.get(XML_MONITOR_SNMP_CONFIG);
812         if (value != null && (!value.isEmpty())) {
813             config.snmpConfig = value.getString();
814             File snmpfile = new File(config.snmpConfig);
815             if (snmpfile.canRead()) {
816                 if (!SnmpConfiguration.setConfigurationFromXml(snmpfile)) {
817                     config.snmpConfig = null;
818                 }
819             } else {
820                 config.snmpConfig = null;
821             }
822         }
823         value = hashConfig.get(XML_MULTIPLE_MONITORS);
824         if (value != null && (!value.isEmpty())) {
825             config.multipleMonitors = value.getInteger();
826             logger.warn("Multiple Monitor configuration active for "
827                     +config.multipleMonitors
828                     +" servers in HA behind a Load Balancer in TCP");
829         } else {
830             config.multipleMonitors = 1;
831             logger.warn("Multiple Monitor configuration unactive");
832         }
833         return true;
834     }
835     private static boolean loadClientParam(Configuration config) {
836         XmlValue value = hashConfig.get(XML_SAVE_TASKRUNNERNODB);
837         if (value != null && (!value.isEmpty())) {
838             config.saveTaskRunnerWithNoDb = value.getBoolean();
839         }
840         return true;
841     }
842     private static boolean loadDirectory(Configuration config) {
843         XmlValue value = hashConfig.get(XML_SERVER_HOME);
844         if (value == null || (value.isEmpty())) {
845             logger.error("Unable to find Home in Config file");
846             return false;
847         }
848         String path = value.getString();
849         File file = new File(path);
850         if (!file.isDirectory()) {
851             logger.error("Home is not a directory in Config file");
852             return false;
853         }
854         try {
855             config.baseDirectory = FilesystemBasedDirImpl
856                     .normalizePath(file.getCanonicalPath());
857         } catch (IOException e1) {
858             logger.error("Unable to set Home in Config file");
859             return false;
860         }
861         try {
862             config.configPath = FilesystemBasedDirImpl
863                     .normalizePath(getSubPath(config, XML_CONFIGPATH));
864         } catch (OpenR66ProtocolSystemException e2) {
865             logger.error("Unable to set Config in Config file");
866             return false;
867         }
868         try {
869             config.inPath = FilesystemBasedDirImpl
870                     .normalizePath(getSubPath(config, XML_INPATH));
871         } catch (OpenR66ProtocolSystemException e2) {
872             logger.error("Unable to set In in Config file");
873             return false;
874         }
875         try {
876             config.outPath = FilesystemBasedDirImpl
877                     .normalizePath(getSubPath(config, XML_OUTPATH));
878         } catch (OpenR66ProtocolSystemException e2) {
879             logger.error("Unable to set Out in Config file");
880             return false;
881         }
882         try {
883             config.workingPath = FilesystemBasedDirImpl
884                     .normalizePath(getSubPath(config, XML_WORKINGPATH));
885         } catch (OpenR66ProtocolSystemException e2) {
886             logger.error("Unable to set Working in Config file");
887             return false;
888         }
889         try {
890             config.archivePath = FilesystemBasedDirImpl
891                     .normalizePath(getSubPath(config, XML_ARCHIVEPATH));
892         } catch (OpenR66ProtocolSystemException e2) {
893             logger.error("Unable to set Archive in Config file");
894             return false;
895         }
896         return true;
897     }
898     private static boolean alreadySetLimit = false;
899     private static boolean loadLimit(Configuration config, boolean updateLimit) {
900         if (alreadySetLimit) {
901             return true;
902         }
903         XmlValue value = hashConfig.get(XML_LIMITGLOBAL);
904         if (value != null && (!value.isEmpty())) {
905             config.serverGlobalReadLimit = value.getLong();
906             if (config.serverGlobalReadLimit <= 0) {
907                 config.serverGlobalReadLimit = 0;
908             }
909             config.serverGlobalWriteLimit = config.serverGlobalReadLimit;
910             logger.info("Global Limit: {}",
911                     config.serverGlobalReadLimit);
912         }
913         value = hashConfig.get(XML_LIMITSESSION);
914         if (value != null && (!value.isEmpty())) {
915             config.serverChannelReadLimit = value.getLong();
916             if (config.serverChannelReadLimit <= 0) {
917                 config.serverChannelReadLimit = 0;
918             }
919             config.serverChannelWriteLimit = config.serverChannelReadLimit;
920             logger.info("SessionInterface Limit: {}",
921                     config.serverChannelReadLimit);
922         }
923         config.anyBandwidthLimitation = 
924             (config.serverGlobalReadLimit > 0 || config.serverGlobalWriteLimit > 0 || 
925                     config.serverChannelReadLimit > 0 || config.serverChannelWriteLimit > 0);
926         config.delayLimit = AbstractTrafficShapingHandler.DEFAULT_CHECK_INTERVAL;
927         value = hashConfig.get(XML_LIMITDELAY);
928         if (value != null && (!value.isEmpty())) {
929             config.delayLimit = (value.getLong()/10)*10;
930             if (config.delayLimit <= 0) {
931                 config.delayLimit = 0;
932             }
933             logger.info("Delay Limit: {}",
934                     config.delayLimit);
935         }
936         value = hashConfig.get(XML_LIMITRUNNING);
937         if (value != null && (!value.isEmpty())) {
938             config.RUNNER_THREAD = value.getInteger();
939         }
940         if (config.RUNNER_THREAD < 10) {
941             config.RUNNER_THREAD = 10;
942         }
943         logger.info("Limit of Runner: {}",
944                 config.RUNNER_THREAD);
945         value = hashConfig.get(XML_DELAYCOMMANDER);
946         if (value != null && (!value.isEmpty())) {
947             config.delayCommander = (value.getLong()/10)*10;
948             if (config.delayCommander <= 100) {
949                 config.delayCommander = 100;
950             }
951             logger.info("Delay Commander: {}",
952                     config.delayCommander);
953         }
954         value = hashConfig.get(XML_DELAYRETRY);
955         if (value != null && (!value.isEmpty())) {
956             config.delayRetry = (value.getLong()/10)*10;
957             if (config.delayRetry <= 1000) {
958                 config.delayRetry = 1000;
959             }
960             logger.info("Delay Retry: {}",
961                     config.delayRetry);
962         }
963         if (DbConstant.admin.isConnected && updateLimit) {
964             value = hashConfig.get(XML_SERVER_HOSTID);
965             if (value != null && (!value.isEmpty())) {
966                 config.HOST_ID = value.getString();
967                 DbConfiguration configuration = new DbConfiguration(
968                         DbConstant.admin.session,
969                         config.HOST_ID,
970                         config.serverGlobalReadLimit,
971                         config.serverGlobalWriteLimit,
972                         config.serverChannelReadLimit,
973                         config.serverChannelWriteLimit,
974                         config.delayLimit);
975                 configuration.changeUpdatedInfo(UpdatedInfo.TOSUBMIT);
976                 try {
977                     if (configuration.exist()) {
978                         configuration.update();
979                     } else {
980                         configuration.insert();
981                     }
982                 } catch (GoldenGateDatabaseException e) {
983                 }
984             }
985         }
986         boolean useCpuLimit = false;
987         boolean useCpuLimitJDK = false; 
988         double cpulimit = 1.0;
989         value = hashConfig.get(XML_CSTRT_USECPULIMIT);
990         if (value != null && (!value.isEmpty())) {
991             useCpuLimit = value.getBoolean();
992             value = hashConfig.get(XML_CSTRT_USECPUJDKLIMIT);
993             if (value != null && (!value.isEmpty())) {
994                 useCpuLimitJDK = value.getBoolean();
995             }
996             value = hashConfig.get(XML_CSTRT_CPULIMIT);
997             if (value != null && (!value.isEmpty())) {
998                 cpulimit = value.getDouble();
999             }
1000         }
1001         int connlimit = 0;
1002         value = hashConfig.get(XML_CSTRT_CONNLIMIT);
1003         if (value != null && (!value.isEmpty())) {
1004             connlimit = value.getInteger();
1005         }
1006         double lowcpuLimit = 0;
1007         double highcpuLimit = 0;
1008         double percentageDecrease = 0;
1009         long delay = 1000000;
1010         long limitLowBandwidth = 4096;
1011         value = hashConfig.get(XML_CSTRT_LOWCPULIMIT);
1012         if (value != null && (!value.isEmpty())) {
1013             lowcpuLimit = value.getDouble();
1014         }
1015         value = hashConfig.get(XML_CSTRT_HIGHCPULIMIT);
1016         if (value != null && (!value.isEmpty())) {
1017             highcpuLimit = value.getDouble();
1018         }
1019         value = hashConfig.get(XML_CSTRT_PERCENTDECREASE);
1020         if (value != null && (!value.isEmpty())) {
1021             percentageDecrease = value.getDouble();
1022         }
1023         value = hashConfig.get(XML_CSTRT_DELAYTHROTTLE);
1024         if (value != null && (!value.isEmpty())) {
1025             delay = (value.getLong()/10)*10;
1026         }
1027         value = hashConfig.get(XML_CSTRT_LIMITLOWBANDWIDTH);
1028         if (value != null && (!value.isEmpty())) {
1029             limitLowBandwidth = value.getLong();
1030         }
1031         if (highcpuLimit > 0) {
1032             config.constraintLimitHandler =
1033                 new R66ConstraintLimitHandler(useCpuLimit, useCpuLimitJDK, cpulimit, connlimit,
1034                         lowcpuLimit, highcpuLimit, percentageDecrease, null, delay, limitLowBandwidth);
1035         } else {
1036             config.constraintLimitHandler =
1037                 new R66ConstraintLimitHandler(useCpuLimit, useCpuLimitJDK, cpulimit, connlimit);
1038         }
1039         value = hashConfig.get(XML_SERVER_THREAD);
1040         if (value != null && (!value.isEmpty())) {
1041             config.SERVER_THREAD = value.getInteger();
1042         }
1043         value = hashConfig.get(XML_CLIENT_THREAD);
1044         if (value != null && (!value.isEmpty())) {
1045             config.CLIENT_THREAD = value.getInteger();
1046         }
1047         value = hashConfig.get(XML_MEMORY_LIMIT);
1048         if (value != null && (!value.isEmpty())) {
1049             config.maxGlobalMemory = value.getLong();
1050         }
1051         Configuration.getFileParameter().deleteOnAbort = false;
1052         value = hashConfig.get(XML_USENIO);
1053         if (value != null && (!value.isEmpty())) {
1054             FilesystemBasedFileParameterImpl.useNio = value.getBoolean();
1055         }
1056         value = hashConfig.get(XML_DIGEST);
1057         if (value != null && (!value.isEmpty())) {
1058             int val = value.getInteger();
1059             if (val < 0 || val >= DigestAlgo.values().length) {
1060                 val = 0;
1061             }
1062             config.digest = DigestAlgo.values()[val];
1063         }
1064         logger.warn("DigestAlgo used: {}", config.digest);
1065         value = hashConfig.get(XML_USEFASTMD5);
1066         if (value != null && (!value.isEmpty())) {
1067             FilesystemBasedDigest.useFastMd5 = value.getBoolean();
1068             if (FilesystemBasedDigest.useFastMd5) {
1069                 value = hashConfig.get(XML_FASTMD5);
1070                 if (value != null && (!value.isEmpty())) {
1071                     FilesystemBasedDigest.fastMd5Path = value.getString();
1072                     if (FilesystemBasedDigest.fastMd5Path == null ||
1073                             FilesystemBasedDigest.fastMd5Path.length() == 0) {
1074                         logger.info("FastMD5 init lib to null");
1075                         FilesystemBasedDigest.initializeMd5(false, null);
1076                     } else {
1077                         logger.info("FastMD5 init lib to {}",
1078                                 FilesystemBasedDigest.fastMd5Path);
1079                         FilesystemBasedDigest.initializeMd5(true, 
1080                                 FilesystemBasedDigest.fastMd5Path);
1081                     }
1082                 }
1083             } else {
1084                 FilesystemBasedDigest.initializeMd5(false, null);
1085             }
1086         } else {
1087             FilesystemBasedDigest.useFastMd5 = false;
1088             FilesystemBasedDigest.initializeMd5(false, null);
1089         }
1090         value = hashConfig.get(XML_GAPRESTART);
1091         if (value != null && (!value.isEmpty())) {
1092             Configuration.RANKRESTART = value.getInteger();
1093             if (Configuration.RANKRESTART <= 0) {
1094                 Configuration.RANKRESTART = 1;
1095             }
1096         }
1097         value = hashConfig.get(XML_BLOCKSIZE);
1098         if (value != null && (!value.isEmpty())) {
1099             config.BLOCKSIZE = value.getInteger();
1100         }
1101         value = hashConfig.get(XML_TIMEOUTCON);
1102         if (value != null && (!value.isEmpty())) {
1103             config.TIMEOUTCON = (value.getLong()/10)*10;
1104         }
1105         if (Configuration.USEJDK6) {
1106             R66Dir.initJdkDependent(new FilesystemBasedDirJdk6());
1107         } else {
1108             R66Dir.initJdkDependent(new FilesystemBasedDirJdk5());
1109         }
1110         value = hashConfig.get(XML_CHECKVERSION);
1111         if (value != null && (!value.isEmpty())) {
1112             config.extendedProtocol = value.getBoolean();
1113             logger.warn("ExtendedProtocol= "+config.extendedProtocol);
1114         }
1115         alreadySetLimit = true;
1116         return true;
1117     }
1118     private static boolean loadSsl(Configuration config) {
1119         // StoreKey for Server
1120         XmlValue value = hashConfig.get(XML_PATH_KEYPATH);
1121         if (value == null || (value.isEmpty())) {
1122             logger.info("Unable to find Key Path");
1123             try {
1124                 NetworkSslServerPipelineFactory.ggSecureKeyStore =
1125                     new GgSecureKeyStore("secret", "secret");
1126             } catch (CryptoException e) {
1127                 logger.error("Bad SecureKeyStore construction");
1128                 return false;
1129             }
1130         } else {
1131             String keypath = value.getString();
1132             if ((keypath == null) || (keypath.length() == 0)) {
1133                 logger.error("Bad Key Path");
1134                 return false;
1135             }
1136             value = hashConfig.get(XML_PATH_KEYSTOREPASS);
1137             if (value == null || (value.isEmpty())) {
1138                 logger.error("Unable to find KeyStore Passwd");
1139                 return false;
1140             }
1141             String keystorepass = value.getString();
1142             if ((keystorepass == null) || (keystorepass.length() == 0)) {
1143                 logger.error("Bad KeyStore Passwd");
1144                 return false;
1145             }
1146             value = hashConfig.get(XML_PATH_KEYPASS);
1147             if (value == null || (value.isEmpty())) {
1148                 logger.error("Unable to find Key Passwd");
1149                 return false;
1150             }
1151             String keypass = value.getString();
1152             if ((keypass == null) || (keypass.length() == 0)) {
1153                 logger.error("Bad Key Passwd");
1154                 return false;
1155             }
1156             try {
1157                 NetworkSslServerPipelineFactory.ggSecureKeyStore =
1158                     new GgSecureKeyStore(keypath, keystorepass,
1159                             keypass);
1160             } catch (CryptoException e) {
1161                 logger.error("Bad SecureKeyStore construction");
1162                 return false;
1163             }
1164 
1165         }
1166         // TrustedKey for OpenR66 server
1167         value = hashConfig.get(XML_PATH_TRUSTKEYPATH);
1168         if (value == null || (value.isEmpty())) {
1169             logger.info("Unable to find TRUST Key Path");
1170             NetworkSslServerPipelineFactory.ggSecureKeyStore.initEmptyTrustStore();
1171         } else {
1172             String keypath = value.getString();
1173             if ((keypath == null) || (keypath.length() == 0)) {
1174                 logger.error("Bad TRUST Key Path");
1175                 return false;
1176             }
1177             value = hashConfig.get(XML_PATH_TRUSTKEYSTOREPASS);
1178             if (value == null || (value.isEmpty())) {
1179                 logger.error("Unable to find TRUST KeyStore Passwd");
1180                 return false;
1181             }
1182             String keystorepass = value.getString();
1183             if ((keystorepass == null) || (keystorepass.length() == 0)) {
1184                 logger.error("Bad TRUST KeyStore Passwd");
1185                 return false;
1186             }
1187             boolean useClientAuthent = false;
1188             value = hashConfig.get(XML_USECLIENT_AUTHENT);
1189             if (value != null && (!value.isEmpty())) {
1190                 useClientAuthent = value.getBoolean();
1191             }
1192             try {
1193                 NetworkSslServerPipelineFactory.ggSecureKeyStore.initTrustStore(keypath,
1194                         keystorepass, useClientAuthent);
1195             } catch (CryptoException e) {
1196                 logger.error("Bad TrustKeyStore construction");
1197                 return false;
1198             }
1199         }
1200         NetworkSslServerPipelineFactory.ggSslContextFactory =
1201             new GgSslContextFactory(
1202                     NetworkSslServerPipelineFactory.ggSecureKeyStore);
1203         return true;
1204     }
1205     private static boolean loadNetworkServer(Configuration config) {
1206         XmlValue value = hashConfig.get(XML_SERVER_PORT);
1207         int port = 6666;
1208         if (value != null && (!value.isEmpty())) {
1209             port = value.getInteger();
1210         } else {
1211             port = 6666;
1212         }
1213         config.SERVER_PORT = port;
1214         value = hashConfig.get(XML_SERVER_SSLPORT);
1215         int sslport = 6667;
1216         if (value != null && (!value.isEmpty())) {
1217             sslport = value.getInteger();
1218         } else {
1219             sslport = 6667;
1220         }
1221         config.SERVER_SSLPORT = sslport;
1222         value = hashConfig.get(XML_SERVER_HTTPPORT);
1223         int httpport = 8066;
1224         if (value != null && (!value.isEmpty())) {
1225             httpport = value.getInteger();
1226         }
1227         config.SERVER_HTTPPORT = httpport;
1228         value = hashConfig.get(XML_SERVER_HTTPSPORT);
1229         int httpsport = 8067;
1230         if (value != null && (!value.isEmpty())) {
1231             httpsport = value.getInteger();
1232         }
1233         config.SERVER_HTTPSPORT = httpsport;
1234         return true;
1235     }
1236     /**
1237      * Set the Crypto Key from the Document
1238      * @param document
1239      * @return True if OK
1240      */
1241     private static boolean setCryptoKey(Configuration config) {
1242         XmlValue value = hashConfig.get(XML_PATH_CRYPTOKEY);
1243         if (value == null || (value.isEmpty())) {
1244             logger.error("Unable to find CryptoKey in Config file");
1245             return false;
1246         }
1247         String filename = value.getString();
1248         File key = new File(filename);
1249         Des des = new Des();
1250         try {
1251             des.setSecretKey(key);
1252         } catch (CryptoException e) {
1253             logger.error("Unable to load CryptoKey from Config file");
1254             return false;
1255         } catch (IOException e) {
1256             logger.error("Unable to load CryptoKey from Config file");
1257             return false;
1258         }
1259         config.cryptoKey = des;
1260         return true;
1261     }
1262     /**
1263      * Load data from database or from files if not connected
1264      *
1265      * @param document
1266      * @return True if OK
1267      */
1268     private static boolean loadFromDatabase(Configuration config) {
1269         if (DbConstant.admin.isConnected) {
1270             // load from database the limit to apply
1271             try {
1272                 DbConfiguration configuration = new DbConfiguration(
1273                         DbConstant.admin.session,
1274                         config.HOST_ID);
1275                 configuration.updateConfiguration();
1276             } catch (GoldenGateDatabaseException e) {
1277                 logger.warn("Cannot load configuration from database", e);
1278             }
1279         } else {
1280             if (config.baseDirectory != null &&
1281                     config.configPath != null) {
1282                 // load Rules from files
1283                 File dirConfig = new File(
1284                         config.baseDirectory +
1285                                 config.configPath);
1286                 if (dirConfig.isDirectory()) {
1287                     try {
1288                         RuleFileBasedConfiguration.importRules(dirConfig);
1289                     } catch (OpenR66ProtocolSystemException e) {
1290                         logger.error("Cannot load Rules", e);
1291                         return false;
1292                     } catch (GoldenGateDatabaseException e) {
1293                         logger.error("Cannot load Rules", e);
1294                         return false;
1295                     }
1296                 } else {
1297                     logger.error("Config Directory is not a directory: " +
1298                             config.baseDirectory +
1299                             config.configPath);
1300                     return false;
1301                 }
1302             }
1303             // load if possible the limit to apply
1304             loadLimit(config, false);
1305         }
1306         return true;
1307     }
1308 
1309     /**
1310      * Load database parameter
1311      *
1312      * @param document
1313      * @return True if OK
1314      */
1315     private static boolean loadDatabase(Configuration config) {
1316         XmlValue value = hashConfig.get(XML_DBDRIVER);
1317         if (value == null || (value.isEmpty())) {
1318             logger.error("Unable to find DBDriver in Config file");
1319             DbConstant.admin = new DbAdmin(); // no database support
1320             DbConstant.noCommitAdmin = DbConstant.admin;
1321         } else {
1322             String dbdriver = value.getString();
1323             value = hashConfig.get(XML_DBSERVER);
1324             if (value == null || (value.isEmpty())) {
1325                 logger.error("Unable to find DBServer in Config file");
1326                 return false;
1327             }
1328             String dbserver = value.getString();
1329             value = hashConfig.get(XML_DBUSER);
1330             if (value == null || (value.isEmpty())) {
1331                 logger.error("Unable to find DBUser in Config file");
1332                 return false;
1333             }
1334             String dbuser = value.getString();
1335             value = hashConfig.get(XML_DBPASSWD);
1336             if (value == null || (value.isEmpty())) {
1337                 logger.error("Unable to find DBPassword in Config file");
1338                 return false;
1339             }
1340             String dbpasswd = value.getString();
1341             if (dbdriver == null || dbserver == null || dbuser == null ||
1342                     dbpasswd == null || dbdriver.length() == 0 ||
1343                     dbserver.length() == 0 || dbuser.length() == 0 ||
1344                     dbpasswd.length() == 0) {
1345                 logger.error("Unable to find Correct DB data in Config file");
1346                 return false;
1347             }
1348             try {
1349                 DbConstant.admin = 
1350                     DbModelFactory.initialize(dbdriver, dbserver, dbuser, dbpasswd,
1351                         true);
1352                 if (config.multipleMonitors > 1) {
1353                     DbConstant.noCommitAdmin = 
1354                         DbModelFactory.initialize(dbdriver, dbserver, dbuser, dbpasswd,
1355                             true);
1356                     DbConstant.noCommitAdmin.session.setAutoCommit(false);
1357                 } else {
1358                     DbConstant.noCommitAdmin = DbConstant.admin;
1359                 }
1360                 logger.info("Database connection: "+(DbConstant.admin != null)+":"+(DbConstant.noCommitAdmin != null));
1361             } catch (GoldenGateDatabaseNoConnectionException e2) {
1362                 logger.error("Unable to Connect to DB", e2);
1363                 return false;
1364             }
1365         }
1366         value = hashConfig.get(XML_SAVE_TASKRUNNERNODB);
1367         if (value != null && (!value.isEmpty())) {
1368             config.saveTaskRunnerWithNoDb = value.getBoolean();
1369         }
1370         return true;
1371     }
1372     /**
1373      * Load white list for Business if any
1374      *
1375      * @param document
1376      */
1377     private static void loadBusinessWhiteList(Configuration config) {
1378         XmlValue value = hashConfig.get(XML_BUSINESS);
1379         if (value != null && (value.getList() != null)) {
1380             @SuppressWarnings("unchecked")
1381             List<String> ids = (List<String>) value.getList();
1382             if (ids != null) {
1383                 for (String sval: ids) {
1384                     if (sval.isEmpty()) {
1385                         continue;
1386                     }
1387                     logger.warn("Business Allow: "+sval);
1388                     config.businessWhiteSet.add(sval.trim());
1389                 }
1390                 ids.clear();
1391                 ids = null;
1392             }
1393         }
1394     }
1395     /**
1396      *
1397      * @param document
1398      * @param fromXML
1399      * @return the new subpath
1400      * @throws OpenR66ProtocolSystemException
1401      */
1402     private static String getSubPath(Configuration config, String fromXML)
1403             throws OpenR66ProtocolSystemException {
1404         XmlValue value = hashConfig.get(fromXML);
1405         if (value == null || (value.isEmpty())) {
1406             logger.error("Unable to find a Path in Config file: "+fromXML);
1407             throw new OpenR66ProtocolSystemException(
1408                     "Unable to find a Path in Config file: " + fromXML);
1409         }
1410 
1411         String path = value.getString();
1412         if (path == null || path.length() == 0) {
1413             throw new OpenR66ProtocolSystemException(
1414                     "Unable to find a correct Path in Config file: " + fromXML);
1415         }
1416         path = DirInterface.SEPARATOR + path;
1417         String newpath = config.baseDirectory + path;
1418         File file = new File(newpath);
1419         if (!file.isDirectory()) {
1420             FileUtils.createDir(file);
1421         }
1422         return path;
1423     }
1424     /**
1425      * Load minimalistic Limit configuration
1426      * @param filename
1427      * @return True if OK
1428      */
1429     public static boolean setConfigurationLoadLimitFromXml(Configuration config, String filename) {
1430         Document document = null;
1431         // Open config file
1432         try {
1433             document = new SAXReader().read(filename);
1434         } catch (DocumentException e) {
1435             logger.error("Unable to read the XML Config file: " + filename, e);
1436             return false;
1437         }
1438         if (document == null) {
1439             logger.error("Unable to read the XML Config file: " + filename);
1440             return false;
1441         }
1442         configuration = XmlUtil.read(document, configServer);
1443         hashConfig = new XmlHash(configuration);
1444         if (! loadLimit(config, true)) {
1445             logger.error("Unable to read Limitation config file: " + filename);
1446             return false;
1447         }
1448         hashConfig.clear();
1449         hashConfig = null;
1450         configuration = null;
1451         return true;
1452     }
1453     /**
1454      * Load configuration for init database
1455      * @param filename
1456      * @return True if OK
1457      */
1458     public static boolean setConfigurationInitDatabase(Configuration config, String filename) {
1459         Document document = null;
1460         // Open config file
1461         try {
1462             document = new SAXReader().read(filename);
1463         } catch (DocumentException e) {
1464             logger.error("Unable to read the XML Config file: " + filename, e);
1465             return false;
1466         }
1467         if (document == null) {
1468             logger.error("Unable to read the XML Config file: " + filename);
1469             return false;
1470         }
1471         configuration = XmlUtil.read(document, configServer);
1472         hashConfig = new XmlHash(configuration);
1473         if (! loadIdentity(config)) {
1474             logger.error("Cannot load Identity");
1475             return false;
1476         }
1477         if (!loadDatabase(config)) {
1478             logger.error("Cannot load Database configuration");
1479             return false;
1480         }
1481         if (! loadDirectory(config)) {
1482             logger.error("Cannot load Directory configuration");
1483             return false;
1484         }
1485         if (! loadLimit(config, false)) {
1486             logger.error("Cannot load Limit configuration");
1487             return false;
1488         }
1489         if (!DbConstant.admin.isConnected) {
1490             // if no database, must load authentication from file
1491             if (! loadAuthentication(config)) {
1492                 logger.error("Cannot load Authentication configuration");
1493                 return false;
1494             }
1495         }
1496         hashConfig.clear();
1497         hashConfig = null;
1498         configuration = null;
1499         return true;
1500     }
1501     /**
1502      * Load minimalistic configuration
1503      * @param filename
1504      * @return True if OK
1505      */
1506     public static boolean setConfigurationServerMinimalFromXml(Configuration config, String filename) {
1507         Document document = null;
1508         // Open config file
1509         try {
1510             document = new SAXReader().read(filename);
1511         } catch (DocumentException e) {
1512             logger.error("Unable to read the XML Config file: " + filename, e);
1513             return false;
1514         }
1515         if (document == null) {
1516             logger.error("Unable to read the XML Config file: " + filename);
1517             return false;
1518         }
1519         configuration = XmlUtil.read(document, configServer);
1520         hashConfig = new XmlHash(configuration);
1521         if (! loadIdentity(config)) {
1522             logger.error("Cannot load Identity");
1523             return false;
1524         }
1525         if (!loadDatabase(config)) {
1526             logger.error("Cannot load Database configuration");
1527             return false;
1528         }
1529         if (! loadDirectory(config)) {
1530             logger.error("Cannot load Directory configuration");
1531             return false;
1532         }
1533         if (! loadLimit(config, false)) {
1534             logger.error("Cannot load Limit configuration");
1535             return false;
1536         }
1537         if (!DbConstant.admin.isConnected) {
1538             // if no database, must load authentication from file
1539             if (! loadAuthentication(config)) {
1540                 logger.error("Cannot load Authentication configuration");
1541                 return false;
1542             }
1543         }
1544         config.HOST_AUTH = R66Auth.getServerAuth(
1545                 DbConstant.admin.session, config.HOST_ID);
1546         if (config.HOST_AUTH == null &&
1547                 config.useNOSSL) {
1548             logger.error("Cannot find Authentication for current host");
1549             return false;
1550         }
1551         if (config.HOST_SSLID != null) {
1552             config.HOST_SSLAUTH = R66Auth.getServerAuth(
1553                     DbConstant.admin.session,
1554                     config.HOST_SSLID);
1555             if (config.HOST_SSLAUTH == null &&
1556                     config.useSSL) {
1557                 logger.error("Cannot find SSL Authentication for current host");
1558                 return false;
1559             }
1560         }
1561         hashConfig.clear();
1562         hashConfig = null;
1563         configuration = null;
1564         return true;
1565     }
1566     
1567     /**
1568      * Initiate the configuration from the xml file for server shutdown
1569      *
1570      * @param filename
1571      * @return True if OK
1572      */
1573     public static boolean setConfigurationServerShutdownFromXml(Configuration config, String filename) {
1574         Document document = null;
1575         // Open config file
1576         try {
1577             document = new SAXReader().read(filename);
1578         } catch (DocumentException e) {
1579             logger.error("Unable to read the XML Config file: " + filename, e);
1580             return false;
1581         }
1582         if (document == null) {
1583             logger.error("Unable to read the XML Config file: " + filename);
1584             return false;
1585         }
1586         configuration = XmlUtil.read(document, configServer);
1587         hashConfig = new XmlHash(configuration);
1588         // Now read the configuration
1589         if (! loadIdentity(config)) {
1590             logger.error("Cannot load Identity");
1591             return false;
1592         }
1593         if (!loadDatabase(config)) {
1594             logger.error("Cannot load Database configuration");
1595             return false;
1596         }
1597         if (! loadServerParam(config)) {
1598             logger.error("Cannot load Server Parameters");
1599             return false;
1600         }
1601         if (! loadDirectory(config)) {
1602             logger.error("Cannot load Directory configuration");
1603             return false;
1604         }
1605         if (! loadLimit(config, false)) {
1606             logger.error("Cannot load Limit configuration");
1607             return false;
1608         }
1609         if (config.useSSL) {
1610             if (!loadSsl(config)) {
1611                 logger.error("Cannot load SSL configuration");
1612                 return false;
1613             }
1614         }
1615         if (! loadNetworkServer(config)) {
1616             logger.error("Cannot load Network configuration");
1617             return false;
1618         }
1619         if (!DbConstant.admin.isConnected) {
1620             // if no database, must load authentication from file
1621             if (! loadAuthentication(config)) {
1622                 logger.error("Cannot load Authentication configuration");
1623                 return false;
1624             }
1625         }
1626         config.HOST_AUTH = R66Auth.getServerAuth(
1627                 DbConstant.admin.session, config.HOST_ID);
1628         if (config.HOST_AUTH == null &&
1629                 config.useNOSSL) {
1630             logger.error("Cannot find Authentication for current host");
1631             return false;
1632         }
1633         if (config.HOST_SSLID != null) {
1634             config.HOST_SSLAUTH = R66Auth.getServerAuth(
1635                     DbConstant.admin.session,
1636                     config.HOST_SSLID);
1637             if (config.HOST_SSLAUTH == null &&
1638                     config.useSSL) {
1639                 logger.error("Cannot find SSL Authentication for current host");
1640                 return false;
1641             }
1642         }
1643         hashConfig.clear();
1644         hashConfig = null;
1645         configuration = null;
1646         return true;
1647     }
1648     /**
1649      * Initiate the configuration from the xml file for server
1650      *
1651      * @param filename
1652      * @return True if OK
1653      */
1654     public static boolean setConfigurationServerFromXml(Configuration config, String filename) {
1655         Document document = null;
1656         // Open config file
1657         try {
1658             document = new SAXReader().read(filename);
1659         } catch (DocumentException e) {
1660             logger.error("Unable to read the XML Config file: " + filename, e);
1661             return false;
1662         }
1663         if (document == null) {
1664             logger.error("Unable to read the XML Config file: " + filename);
1665             return false;
1666         }
1667         configuration = XmlUtil.read(document, configServer);
1668         hashConfig = new XmlHash(configuration);
1669         // Now read the configuration
1670         if (! loadIdentity(config)) {
1671             logger.error("Cannot load Identity");
1672             return false;
1673         }
1674         if (!loadDatabase(config)) {
1675             logger.error("Cannot load Database configuration");
1676             return false;
1677         }
1678         if (! loadServerParam(config)) {
1679             logger.error("Cannot load Server Parameters");
1680             return false;
1681         }
1682         if (! loadDirectory(config)) {
1683             logger.error("Cannot load Directory configuration");
1684             return false;
1685         }
1686         if (! loadLimit(config, false)) {
1687             logger.error("Cannot load Limit configuration");
1688             return false;
1689         }
1690         if (config.useSSL) {
1691             if (!loadSsl(config)) {
1692                 logger.error("Cannot load SSL configuration");
1693                 return false;
1694             }
1695         }
1696         if (! loadNetworkServer(config)) {
1697             logger.error("Cannot load Network configuration");
1698             return false;
1699         }
1700         if (!loadFromDatabase(config)) {
1701             logger.error("Cannot load configuration from Database");
1702             return false;
1703         }
1704         if (!DbConstant.admin.isConnected) {
1705             // if no database, must load authentication from file
1706             if (! loadAuthentication(config)) {
1707                 logger.error("Cannot load Authentication configuration");
1708                 return false;
1709             }
1710         }
1711         config.HOST_AUTH = R66Auth.getServerAuth(
1712                 DbConstant.admin.session, config.HOST_ID);
1713         if (config.HOST_AUTH == null &&
1714                 config.useNOSSL) {
1715             logger.error("Cannot find Authentication for current host");
1716             return false;
1717         }
1718         if (config.HOST_SSLID != null) {
1719             config.HOST_SSLAUTH = R66Auth.getServerAuth(
1720                     DbConstant.admin.session,
1721                     config.HOST_SSLID);
1722             if (config.HOST_SSLAUTH == null &&
1723                     config.useSSL) {
1724                 logger.error("Cannot find SSL Authentication for current host");
1725                 return false;
1726             }
1727         }
1728         loadBusinessWhiteList(config);
1729         hashConfig.clear();
1730         hashConfig = null;
1731         configuration = null;
1732         return true;
1733     }
1734 
1735     /**
1736      * Initiate the configuration from the xml file for database client
1737      *
1738      * @param filename
1739      * @return True if OK
1740      */
1741     public static boolean setClientConfigurationFromXml(Configuration config, String filename) {
1742         Document document = null;
1743         // Open config file
1744         try {
1745             document = new SAXReader().read(filename);
1746         } catch (DocumentException e) {
1747             logger.error("Unable to read the XML Config file: " + filename, e);
1748             return false;
1749         }
1750         if (document == null) {
1751             logger.error("Unable to read the XML Config file: " + filename);
1752             return false;
1753         }
1754         configuration = XmlUtil.read(document, configClient);
1755         hashConfig = new XmlHash(configuration);
1756         // Client enables SSL by default but could be reverted later on
1757         config.useSSL = true;
1758         if (! loadIdentity(config)) {
1759             logger.error("Cannot load Identity");
1760             return false;
1761         }
1762         if (!loadDatabase(config)) {
1763             logger.error("Cannot load Database configuration");
1764             return false;
1765         }
1766         if (! loadClientParam(config)) {
1767             logger.error("Cannot load Client Parameters");
1768             return false;
1769         }
1770         if (! loadDirectory(config)) {
1771             logger.error("Cannot load Directory configuration");
1772             return false;
1773         }
1774         if (! loadLimit(config, false)) {
1775             logger.error("Cannot load Limit configuration");
1776             return false;
1777         }
1778         if (config.useSSL) {
1779             if (!loadSsl(config)) {
1780                 logger.error("Cannot load SSL configuration");
1781                 return false;
1782             }
1783         }
1784         if (!loadFromDatabase(config)) {
1785             logger.error("Cannot load configuration from Database");
1786             return false;
1787         }
1788         if (!DbConstant.admin.isConnected) {
1789             // if no database, must load authentication from file
1790             if (! loadAuthentication(config)) {
1791                 logger.error("Cannot load Authentication configuration");
1792                 return false;
1793             }
1794         }
1795         config.HOST_AUTH = R66Auth.getServerAuth(
1796                 DbConstant.admin.session, config.HOST_ID);
1797         if (config.HOST_AUTH == null) {
1798             logger.error("Cannot find Authentication for current host");
1799             return false;
1800         }
1801         if (config.HOST_SSLID != null) {
1802             config.HOST_SSLAUTH = R66Auth.getServerAuth(
1803                     DbConstant.admin.session,
1804                     config.HOST_SSLID);
1805             if (config.HOST_SSLAUTH == null) {
1806                 logger.error("Cannot find SSL Authentication for current host");
1807                 return false;
1808             }
1809         }
1810         loadBusinessWhiteList(config);
1811         hashConfig.clear();
1812         hashConfig = null;
1813         configuration = null;
1814         return true;
1815     }
1816     /**
1817      * Initiate the configuration from the xml file for submit database client
1818      *
1819      * @param config
1820      * @param filename
1821      * @return True if OK
1822      */
1823     public static boolean setSubmitClientConfigurationFromXml(Configuration config, String filename) {
1824         Document document = null;
1825         // Open config file
1826         try {
1827             document = new SAXReader().read(filename);
1828         } catch (DocumentException e) {
1829             logger.error("Unable to read the XML Config file: " + filename, e);
1830             return false;
1831         }
1832         if (document == null) {
1833             logger.error("Unable to read the XML Config file: " + filename);
1834             return false;
1835         }
1836         configuration = XmlUtil.read(document, configSubmitClient);
1837         hashConfig = new XmlHash(configuration);
1838         // Client enables SSL by default but could be reverted later on
1839         config.useSSL = true;
1840         if (! loadIdentity(config)) {
1841             logger.error("Cannot load Identity");
1842             return false;
1843         }
1844         if (!loadDatabase(config)) {
1845             logger.error("Cannot load Database configuration");
1846             return false;
1847         }
1848         XmlValue value = hashConfig.get(XML_BLOCKSIZE);
1849         if (value != null && (!value.isEmpty())) {
1850             config.BLOCKSIZE = value.getInteger();
1851         }
1852         config.HOST_AUTH = R66Auth.getServerAuth(
1853                 DbConstant.admin.session, config.HOST_ID);
1854         if (config.HOST_AUTH == null) {
1855             logger.error("Cannot find Authentication for current host");
1856             return false;
1857         }
1858         if (config.HOST_SSLID != null) {
1859             config.HOST_SSLAUTH = R66Auth.getServerAuth(
1860                     DbConstant.admin.session,
1861                     config.HOST_SSLID);
1862             if (config.HOST_SSLAUTH == null) {
1863                 logger.error("Cannot find SSL Authentication for current host");
1864                 return false;
1865             }
1866         }
1867         hashConfig.clear();
1868         hashConfig = null;
1869         configuration = null;
1870         return true;
1871     }
1872 }