JavaDoc


001    /**
002     * Copyright (c) 2003 Daffodil Software Ltd all rights reserved,
003     * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved.
004     * This program is free software; you can redistribute it and/or modify
005     * it under the terms of version 2 of the GNU General Public License as
006     * published by the Free Software Foundation.
007     * There are special exceptions to the terms and conditions of the GPL
008     * as it is applied to this software. See the GNU General Public License for more details.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018     */
019    
020    
021    package org.dbreplicator.repconsole;
022    
023    import java.io.File;
024    import java.util.Properties;
025    import java.io.FileInputStream;
026    import org.dbreplicator.replication._Publication;
027    import org.dbreplicator.replication.RepException;
028    import org.dbreplicator.replication._ReplicationServer;
029    import org.dbreplicator.replication.ReplicationServer;
030    import org.dbreplicator.replication.RepConstants;
031    import javax.crypto.SecretKey;
032    import javax.crypto.KeyGenerator;
033    import java.security.*;
034    import java.io.ObjectInputStream;
035    import java.io.*;
036    
037    public class PubConfiguration {
038    
039      private String pubDbDriver , pubDbURL , pubDbUser , pubDbPassword,keys ;
040    
041      private String pubName;
042    
043      private String pubSysName;
044    
045      private String pubPort;
046    
047      private _ReplicationServer repPublication;
048      private _Publication pub;
049    
050      private  DesEncrypter desEncrypter;
051    
052      public PubConfiguration() {
053    
054        File f =new File("."+File.separator+"pubconfig.ini");
055           Properties p =new Properties();
056          try {
057       p.load(new FileInputStream(f));  // Try to load props
058       initialisePubInformation(p);
059        repPublication =initialiseReplicationServer();
060        pub = getPublication();
061      }
062      catch (Exception ex) {
063    //    ex.printStackTrace();
064        RepConstants.writeERROR_FILE(ex);
065      }
066      }
067    
068    
069    /* private SecretKey getSecretKey(){
070        File f =new File("."+File.separator+"secretkey.log");
071        try {
072          ObjectInputStream oos = new ObjectInputStream(new FileInputStream(f));
073         SecretKey sk =  (SecretKey)oos.readObject() ;
074         return sk;
075        }
076        catch (IOException ex) {
077        }
078        catch(ClassNotFoundException ex){
079    
080        }
081        return null;
082    
083      }
084    */
085    
086    
087    
088      private void  initialisePubInformation(Properties p) {
089    //System.out.println(" property "+ p);
090           pubDbDriver = p.getProperty("DRIVER");
091    //System.out.println(" subDbDriver ="+pubDbDriver);
092           pubDbURL =   p.getProperty("URL");
093    //System.out.println(" pubDbURL ="+pubDbURL);
094           pubDbUser =  p.getProperty("USER");
095    //System.out.println(" pubDbUser ="+pubDbUser);
096           pubDbPassword = p.getProperty("PASSWORD");
097    //       keys =p.getProperty("KEY");
098    // System.out.println("Pub Configuration  pubDbPassword  : "+pubDbPassword);
099           pubDbPassword = decryptPassword(pubDbPassword);
100    // System.out.println("Pub Configuration  pubDbPassword  : "+pubDbPassword);
101    
102    //System.out.println(" pubDbPassword ="+pubDbPassword);
103           pubName =  p.getProperty("PUBNAME");
104    //System.out.println(" pubName ="+pubName);
105           pubSysName = p.getProperty("SYSTEMNAME");
106    // System.out.println(" pubvsysname  "+ pubSysName);
107           pubPort =p.getProperty("PORT");
108    //System.out.println(" port  "+ pubPort);
109    
110    
111      }
112    
113      private _Publication getPublication() throws Exception {
114        _Publication pub = repPublication.getPublication(pubName);
115         if (pub == null) {
116           throw new RepException("REP048",new Object[]{pubName});
117         } else {
118         return pub;
119         }
120      }
121    
122      private _ReplicationServer initialiseReplicationServer() throws RepException {
123       _ReplicationServer   rep = ReplicationServer.getInstance(Integer.parseInt(pubPort),pubSysName);
124        rep.setDataSource(pubDbDriver, pubDbURL, pubDbUser,pubDbPassword);
125        return rep;
126      }
127    
128    
129        private String decryptPassword(String password){
130            SecretKey sk = getSecretKey();
131            desEncrypter = new DesEncrypter(sk);
132          return  desEncrypter.decrypt(password);
133        }
134    
135    
136        private SecretKey getSecretKey(){
137           try {
138    //   String path =File.separator + "com" +File.separator +"daffodilwoods" +File.separator + "repconsole" +File.separator +"EncryptDecrypt.properties";
139             String path ="/org.dbreplicator/repconsole/secretKey.obj";
140             java.net.URL url1 = getClass().getResource(path);
141    //System.out.println(" url1 : "+url1);
142              ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(url1.openStream()));
143             SecretKey sk = (SecretKey) ois.readObject();
144             return sk;
145             }
146             catch (IOException ex) {
147     RepConstants.writeERROR_FILE(ex);
148    //           ex.printStackTrace();
149             }
150             catch(ClassNotFoundException ex){
151    //           ex.printStackTrace();
152     RepConstants.writeERROR_FILE(ex);
153             }
154             return null;
155    
156           }
157    
158    
159      public static void main(String[] args) {
160        PubConfiguration pc  = new PubConfiguration();
161      }
162    
163    }





























































Powered by Drupal - Theme by Danger4k