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.panel; 22 23 import java.awt.BorderLayout; 24 import java.awt.GridLayout; 25 import java.awt.event.ActionEvent; 26 import java.awt.event.ActionListener; 27 import java.io.File; 28 29 import javax.swing.JButton; 30 import javax.swing.JCheckBox; 31 import javax.swing.JComboBox; 32 import javax.swing.JLabel; 33 import javax.swing.JPanel; 34 import javax.swing.JTextField; 35 import javax.swing.border.TitledBorder; 36 37 import org.apache.log4j.Logger; 38 39 import base.jdbs.ConfigurationManager; 40 import base.jdbs.SecurityLevel; 41 42 @SuppressWarnings("serial") 43 public class SecurityConfigurationPanel extends JPanel { 44 45 private static final transient Logger logger = Logger 46 .getLogger(SecurityConfigurationPanel.class.getName()); 47 48 private JPanel keyStoreLocationPanel; 49 50 private JTextField keyStoreLocationTextField; 51 52 private JPanel buttonPanel; 53 54 private JButton keyStoreLoadButton; 55 56 private JButton keyStoreCreateButton; 57 58 private JPanel authenticatePeerDownloadPanel; 59 60 private JCheckBox authenticatePeerDownloadCheckBox; 61 62 private JPanel securityLevelPanel; 63 64 private JComboBox securityLevelComboBox; 65 66 public SecurityConfigurationPanel() { 67 initialize(); 68 } 69 70 protected void initialize() { 71 this.setBorder(new TitledBorder("Security Configuration Parameters")); 72 this.setLayout(new GridLayout(3, 1)); 73 this.add(this.getKeyStoreLocationPanel()); 74 this.add(this.getSecurityLevelPanel()); 75 this.add(this.getAuthenticatePeerDownloadPanel()); 76 } 77 78 /*** 79 * @return the keyStoreLocationPanel 80 */ 81 protected JPanel getKeyStoreLocationPanel() { 82 if (this.keyStoreLocationPanel == null) { 83 this.keyStoreLocationPanel = new JPanel(); 84 this.keyStoreLocationPanel.setBorder(new TitledBorder( 85 "Asymetric Key Ring Location")); 86 this.keyStoreLocationPanel.setLayout(new BorderLayout()); 87 this.keyStoreLocationPanel.add(this.getKeyStoreLocationTextField(), 88 BorderLayout.CENTER); 89 this.keyStoreLocationPanel.add(this.getButtonPanel(), 90 BorderLayout.SOUTH); 91 92 } 93 return keyStoreLocationPanel; 94 } 95 96 /*** 97 * @return the buttonPanel 98 */ 99 protected JPanel getButtonPanel() { 100 if (this.buttonPanel == null) { 101 this.buttonPanel = new JPanel(); 102 this.buttonPanel.setLayout(new GridLayout(1, 4)); 103 this.buttonPanel.add(new JLabel()); 104 this.buttonPanel.add(this.getKeyStoreLoadButton()); 105 this.buttonPanel.add(this.getKeyStoreCreateButton()); 106 this.buttonPanel.add(new JLabel()); 107 } 108 return buttonPanel; 109 } 110 111 /*** 112 * @return the keyStoreLoadButton 113 */ 114 protected JButton getKeyStoreLoadButton() { 115 if (this.keyStoreLoadButton == null) { 116 this.keyStoreLoadButton = new JButton("Change"); 117 this.keyStoreLoadButton 118 .addActionListener(new ActionListener() { 119 120 public void actionPerformed(ActionEvent arg0) { 121 javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(); 122 chooser 123 .setDialogTitle("Select the keyring file to be loaded..."); 124 chooser 125 .setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY); 126 chooser.setApproveButtonText("Select"); 127 if (chooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) { 128 ConfigurationManager.getInstance() 129 .setKeyRingLocation( 130 new File(chooser 131 .getSelectedFile() 132 .getAbsolutePath())); 133 getKeyStoreLocationTextField().setText( 134 chooser.getSelectedFile() 135 .getAbsolutePath()); 136 } 137 } 138 139 }); 140 } 141 return keyStoreLoadButton; 142 } 143 144 /*** 145 * @return the keyStoreCreateButton 146 */ 147 protected JButton getKeyStoreCreateButton() { 148 if (this.keyStoreCreateButton == null) { 149 this.keyStoreCreateButton = new JButton("Create"); 150 this.keyStoreCreateButton 151 .addActionListener(new ActionListener() { 152 153 public void actionPerformed(ActionEvent arg0) { 154 155 156 } 157 158 }); 159 } 160 return keyStoreLoadButton; 161 } 162 163 /*** 164 * @return the keyStoreLocationTextField 165 */ 166 protected JTextField getKeyStoreLocationTextField() { 167 if (this.keyStoreLocationTextField == null) { 168 this.keyStoreLocationTextField = new JTextField(); 169 this.keyStoreLocationTextField.setEditable(false); 170 this.keyStoreLocationTextField.setText(!("" + ConfigurationManager 171 .getInstance().getKeyRingLocation()) 172 .equalsIgnoreCase("null") ? "" 173 + ConfigurationManager.getInstance().getKeyRingLocation() 174 : "A key ring in not yet defined!"); 175 } 176 return keyStoreLocationTextField; 177 } 178 179 /*** 180 * @return the securityLevelComboBox 181 */ 182 protected JComboBox getSecurityLevelComboBox() { 183 if (this.securityLevelComboBox == null) { 184 this.securityLevelComboBox = new JComboBox(); 185 for (int i = 0; i < SecurityLevel.level.length; i++) { 186 this.securityLevelComboBox.addItem(SecurityLevel.level[i]); 187 if (ConfigurationManager.getInstance() 188 .getDefaultBackupSecurityLevel().toString() 189 .equalsIgnoreCase(SecurityLevel.level[i])) 190 this.securityLevelComboBox 191 .setSelectedItem(SecurityLevel.level[i]); 192 } 193 this.securityLevelComboBox 194 .setToolTipText("If private each created backuo will be encrypted and signed, will be not otherwise."); 195 } 196 return securityLevelComboBox; 197 } 198 199 /*** 200 * @return the securityLevelPanel 201 */ 202 protected JPanel getSecurityLevelPanel() { 203 if (this.securityLevelPanel == null) { 204 this.securityLevelPanel = new JPanel(); 205 this.securityLevelPanel.setBorder(new TitledBorder( 206 "Backup Security Level")); 207 this.securityLevelPanel.setLayout(new BorderLayout()); 208 this.securityLevelPanel.add(this.getSecurityLevelComboBox(), 209 BorderLayout.CENTER); 210 211 } 212 return securityLevelPanel; 213 } 214 215 /*** 216 * @return Returns the authenticatePeerDownloadCheckBox. 217 */ 218 protected JCheckBox getAuthenticatePeerDownloadCheckBox() { 219 if (this.authenticatePeerDownloadCheckBox == null) { 220 this.authenticatePeerDownloadCheckBox = new JCheckBox(); 221 this.authenticatePeerDownloadCheckBox 222 .setToolTipText("Enables an X509Certificate check between the peer that is trying to download a backup and its owner."); 223 this.authenticatePeerDownloadCheckBox 224 .setSelected(ConfigurationManager.getInstance() 225 .isEnabledPeerDownloadAuthentication()); 226 this.authenticatePeerDownloadCheckBox 227 .addActionListener(new ActionListener() { 228 229 public void actionPerformed(ActionEvent arg0) { 230 ConfigurationManager.getInstance() 231 .setEnabledPeerDownloadAuthentication( 232 authenticatePeerDownloadCheckBox 233 .isSelected()); 234 235 } 236 }); 237 } 238 return authenticatePeerDownloadCheckBox; 239 } 240 241 /*** 242 * @return Returns the authenticatePeerDownloadPanel. 243 */ 244 protected JPanel getAuthenticatePeerDownloadPanel() { 245 if (this.authenticatePeerDownloadPanel == null) { 246 this.authenticatePeerDownloadPanel = new JPanel(); 247 this.authenticatePeerDownloadPanel.setBorder(new TitledBorder( 248 "Download Authentication")); 249 this.authenticatePeerDownloadPanel.setLayout(new BorderLayout()); 250 this.authenticatePeerDownloadPanel 251 .add(this.getAuthenticatePeerDownloadCheckBox(), 252 BorderLayout.CENTER); 253 } 254 return authenticatePeerDownloadPanel; 255 } 256 }