| Line | Hits | Source |
|---|---|---|
| 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.io.File; | |
| 24 | import java.security.KeyStore; | |
| 25 | ||
| 26 | import org.apache.log4j.Logger; | |
| 27 | ||
| 28 | import ui.command.Command; | |
| 29 | import base.InternetCafe; | |
| 30 | import base.jdbs.BackupDescriptor; | |
| 31 | import base.jdbs.ConfigurationManager; | |
| 32 | import base.jdbs.cryptography.asymmetric.AsymmetricKeyRing; | |
| 33 | import base.jdbs.cryptography.asymmetric.KeyPair; | |
| 34 | import base.jdbs.cryptography.symmetric.SymmetricKey; | |
| 35 | ||
| 36 | /** | |
| 37 | * @author skunk | |
| 38 | * | |
| 39 | */ | |
| 40 | 0 | public class RestoreBackupArtifactCommand extends Command { |
| 41 | ||
| 42 | 0 | private static final transient Logger logger = Logger.getLogger(RestoreBackupArtifactCommand.class.getName()); |
| 43 | ||
| 44 | private final String guId; | |
| 45 | 0 | private File outputDirectory = null; |
| 46 | ||
| 47 | 0 | public RestoreBackupArtifactCommand(String guId){ |
| 48 | 0 | this.guId = guId; |
| 49 | 0 | } |
| 50 | /* | |
| 51 | * (non-Javadoc) | |
| 52 | * | |
| 53 | * @see ui.command.Command#prologo() | |
| 54 | */ | |
| 55 | @Override | |
| 56 | protected void prologo() { | |
| 57 | 0 | InternetCafe.setStatusBarMessage("Restoring a backup from the JDBS repository..."); |
| 58 | 0 | javax.swing.JFileChooser outputDirectoryChooser = new javax.swing.JFileChooser(); |
| 59 | 0 | outputDirectoryChooser.setDialogTitle("Select the output directory where the backup must be restored..."); |
| 60 | 0 | outputDirectoryChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); |
| 61 | 0 | outputDirectoryChooser.setApproveButtonText("Select"); |
| 62 | 0 | outputDirectoryChooser.setMultiSelectionEnabled(true); |
| 63 | ||
| 64 | 0 | if (outputDirectoryChooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION){ |
| 65 | 0 | this.outputDirectory = outputDirectoryChooser.getSelectedFile(); |
| 66 | 0 | if(!outputDirectory.isDirectory()) |
| 67 | { | |
| 68 | 0 | logger.warn("Chosen output directory is not a directory!"); |
| 69 | 0 | setStatus(ERROR_STATUS); |
| 70 | } | |
| 71 | 0 | logger.debug("Output Directory: "+outputDirectory); |
| 72 | ||
| 73 | 0 | }else setStatus(ABORT_STATUS); |
| 74 | ||
| 75 | 0 | setStatus(EXECUTE_STATUS); |
| 76 | 0 | } |
| 77 | ||
| 78 | /* | |
| 79 | * (non-Javadoc) | |
| 80 | * | |
| 81 | * @see ui.command.Command#execution() | |
| 82 | */ | |
| 83 | @Override | |
| 84 | protected void execution() throws Exception { | |
| 85 | 0 | switch (getStatus()) { |
| 86 | case ABORT_STATUS: | |
| 87 | 0 | break; |
| 88 | case VETOED_STATUS: | |
| 89 | 0 | break; |
| 90 | case EXECUTE_STATUS: | |
| 91 | 0 | AsymmetricKeyRing asymmetricKeyRing = new AsymmetricKeyRing(ConfigurationManager.getInstance().getUser()); |
| 92 | 0 | KeyStore keyStore = asymmetricKeyRing.retrieve(ConfigurationManager.getInstance().getKeyRingLocation(),"password"); |
| 93 | ||
| 94 | 0 | KeyPair keyPair = asymmetricKeyRing.getAllKeyPair()[0]; |
| 95 | 0 | SymmetricKey symmetricKey = new SymmetricKey("password"); |
| 96 | 0 | BackupDescriptor backupDescriptor = ConfigurationManager.getInstance().getRepository().getBackupDescriptorByGuId(guId); |
| 97 | 0 | if(backupDescriptor != null){ |
| 98 | 0 | base.jdbs.BackupArtifactDisassembler.disassemblyBackupArtifact(symmetricKey, keyPair, backupDescriptor, this.outputDirectory); |
| 99 | 0 | setStatus(SUCCESS_STATUS); |
| 100 | 0 | } |
| 101 | 0 | else setStatus(ERROR_STATUS); |
| 102 | break; | |
| 103 | } | |
| 104 | 0 | } |
| 105 | ||
| 106 | /* | |
| 107 | * (non-Javadoc) | |
| 108 | * | |
| 109 | * @see ui.command.Command#epilogue() | |
| 110 | */ | |
| 111 | @Override | |
| 112 | protected void epilogue() { | |
| 113 | 0 | switch (getStatus()) { |
| 114 | case SUCCESS_STATUS: | |
| 115 | 0 | InternetCafe.setStatusBarMessage("JDBS Successfully exited..."); |
| 116 | 0 | break; |
| 117 | case ABORT_STATUS: | |
| 118 | 0 | InternetCafe.setStatusBarMessage("Command aborted by user..."); |
| 119 | 0 | break; |
| 120 | case ERROR_STATUS: | |
| 121 | 0 | InternetCafe.setStatusBarMessage("Command error..."); |
| 122 | 0 | break; |
| 123 | case VETOED_STATUS: | |
| 124 | 0 | InternetCafe.setStatusBarMessage("Command vetoed..."); |
| 125 | break; | |
| 126 | } | |
| 127 | 0 | } |
| 128 | ||
| 129 | } | |
| 130 |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |