1 /********************************************************************************
2 *InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20
21 package base.jdbs.ui.command;
22
23 import java.security.KeyStore;
24 import java.util.Enumeration;
25
26 import org.apache.log4j.Logger;
27
28 import ui.command.Command;
29 import base.InternetCafe;
30 import base.jdbs.Backup;
31 import base.jdbs.BackupArtifactAssembler;
32 import base.jdbs.ConfigurationManager;
33 import base.jdbs.cryptography.asymmetric.AsymmetricKeyRing;
34 import base.jdbs.cryptography.symmetric.SymmetricKey;
35
36 /***
37 * @author skunk
38 *
39 */
40 public class BuildBackupArtifactCommand extends Command {
41
42 private static final transient Logger logger = Logger.getLogger(BuildBackupArtifactCommand.class.getName());
43
44 private final Backup backup;
45
46 public BuildBackupArtifactCommand(Backup backup){
47 this.backup = backup;
48 }
49
50
51
52
53
54
55 @Override
56 protected void prologo() {
57 InternetCafe.setStatusBarMessage("Building a new backup...");
58 setStatus(EXECUTE_STATUS);
59 }
60
61
62
63
64
65
66 @Override
67 protected void execution() throws Exception {
68 switch (getStatus()) {
69 case ABORT_STATUS:
70 break;
71 case VETOED_STATUS:
72 break;
73 case EXECUTE_STATUS:
74 try{
75 AsymmetricKeyRing asymmetricKeyRing = new AsymmetricKeyRing(ConfigurationManager.getInstance().getUser());
76
77 KeyStore keyStore = asymmetricKeyRing.retrieve(ConfigurationManager.getInstance().getKeyRingLocation(),"password");
78 Enumeration aliasEnumeration = keyStore.aliases();
79 while(aliasEnumeration.hasMoreElements()){
80 System.out.println(aliasEnumeration.nextElement());
81 }
82 long start = System.currentTimeMillis();
83 BackupArtifactAssembler.buildNewBackupArtifact(ConfigurationManager.getInstance().getRepository().getLocation(),new SymmetricKey("password"),asymmetricKeyRing.getAllKeyPair()[0],backup);
84 long end = System.currentTimeMillis();
85 logger.debug("The backup artifact assemblation has taken: "+(end - start)+" ms");
86 ConfigurationManager.getInstance().getRepository().indexRepository();
87 }catch(Exception ex){
88 ex.printStackTrace();
89 }
90
91 setStatus(SUCCESS_STATUS);
92 break;
93 }
94 }
95
96
97
98
99
100
101 @Override
102 protected void epilogue() {
103 switch (getStatus()) {
104 case SUCCESS_STATUS:
105 InternetCafe.setStatusBarMessage("Backup successfully created...");
106 break;
107 case ABORT_STATUS:
108 InternetCafe.setStatusBarMessage("Command aborted by user...");
109 break;
110 case ERROR_STATUS:
111 InternetCafe.setStatusBarMessage("Command error...");
112 break;
113 case VETOED_STATUS:
114 InternetCafe.setStatusBarMessage("Command vetoed...");
115 break;
116 }
117 }
118
119 }
120