summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/base/JDialogPasswordCallback.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/base/JDialogPasswordCallback.java')
-rw-r--r--pki/base/common/src/com/netscape/cmscore/base/JDialogPasswordCallback.java92
1 files changed, 47 insertions, 45 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/base/JDialogPasswordCallback.java b/pki/base/common/src/com/netscape/cmscore/base/JDialogPasswordCallback.java
index 4b17248f..cd695967 100644
--- a/pki/base/common/src/com/netscape/cmscore/base/JDialogPasswordCallback.java
+++ b/pki/base/common/src/com/netscape/cmscore/base/JDialogPasswordCallback.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.base;
+
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
@@ -43,18 +44,19 @@ import org.mozilla.jss.util.Password;
import org.mozilla.jss.util.PasswordCallback;
import org.mozilla.jss.util.PasswordCallbackInfo;
+
/**
* A class to retrieve passwords through a modal Java dialog box
*/
public class JDialogPasswordCallback implements PasswordCallback {
public Password getPasswordFirstAttempt(PasswordCallbackInfo info)
- throws PasswordCallback.GiveUpException {
+ throws PasswordCallback.GiveUpException {
return getPW(info, false);
}
public Password getPasswordAgain(PasswordCallbackInfo info)
- throws PasswordCallback.GiveUpException {
+ throws PasswordCallback.GiveUpException {
return getPW(info, true);
}
@@ -86,27 +88,27 @@ public class JDialogPasswordCallback implements PasswordCallback {
}
/**
- * This method does the work of displaying the dialog box, extracting the
- * information, and returning it.
+ * This method does the work of displaying the dialog box,
+ * extracting the information, and returning it.
*/
private Password getPW(PasswordCallbackInfo info, boolean retry)
- throws PasswordCallback.GiveUpException {
+ throws PasswordCallback.GiveUpException {
// These need to final so they can be accessed from action listeners
final PWHolder pwHolder = new PWHolder();
final JFrame f = new JFrame("Password Dialog");
final JPasswordField pwField = new JPasswordField(15);
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
// Panel
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
JPanel contentPane = new JPanel(new GridBagLayout());
contentPane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
GridBagConstraints c = new GridBagConstraints();
- // //////////////////////////////////////////////////
+ ////////////////////////////////////////////////////
// Labels
- // //////////////////////////////////////////////////
+ ////////////////////////////////////////////////////
if (retry) {
JLabel warning = new JLabel("Password incorrect.");
@@ -117,47 +119,47 @@ public class JDialogPasswordCallback implements PasswordCallback {
c.gridwidth = GridBagConstraints.REMAINDER;
// Setting this to NULL causes nasty Exception stack traces
// to be printed, although the program still seems to work
- // warning.setHighlighter(null);
+ //warning.setHighlighter(null);
contentPane.add(warning, c);
}
-
+
String prompt = getPrompt(info);
JLabel label = new JLabel(prompt);
label.setForeground(Color.black);
// Setting this to NULL causes nasty Exception stack traces
// to be printed, although the program still seems to work
- // label.setHighlighter(null);
+ //label.setHighlighter(null);
resetGBC(c);
c.anchor = GridBagConstraints.NORTHWEST;
c.gridwidth = GridBagConstraints.REMAINDER;
contentPane.add(label, c);
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
// Password text field
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
// Listener for the text field
ActionListener getPasswordListener = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- // input = (JPasswordField)e.getSource();
+ public void actionPerformed(ActionEvent e) {
+ //input = (JPasswordField)e.getSource();
- // XXX!!! Change to char[] in JDK 1.2
- String pwString = pwField.getText();
+ // XXX!!! Change to char[] in JDK 1.2
+ String pwString = pwField.getText();
- pwHolder.password = new Password(pwString.toCharArray());
- pwHolder.cancelled = false;
- f.dispose();
- }
- };
+ pwHolder.password = new Password(pwString.toCharArray());
+ pwHolder.cancelled = false;
+ f.dispose();
+ }
+ };
// There is a bug in JPasswordField. The cursor is advanced by the
// width of the character you type, but a '*' is echoed, so the
// cursor does not stay lined up with the end of the text.
// We use a monospaced font to workaround this.
- pwField.setFont(new Font("Monospaced", Font.PLAIN, pwField.getFont()
- .getSize()));
+ pwField.setFont(new Font("Monospaced", Font.PLAIN,
+ pwField.getFont().getSize()));
pwField.setEchoChar('*');
pwField.addActionListener(getPasswordListener);
resetGBC(c);
@@ -165,12 +167,12 @@ public class JDialogPasswordCallback implements PasswordCallback {
c.fill = GridBagConstraints.NONE;
c.insets = new Insets(16, 0, 0, 0);
c.gridwidth = GridBagConstraints.REMAINDER;
- // c.gridy++;
+ //c.gridy++;
contentPane.add(pwField, c);
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
// Cancel button
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
JPanel buttonPanel = new JPanel(new GridBagLayout());
@@ -186,11 +188,11 @@ public class JDialogPasswordCallback implements PasswordCallback {
JButton cancel = new JButton("Cancel");
ActionListener buttonListener = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- pwHolder.cancelled = true;
- f.dispose();
- }
- };
+ public void actionPerformed(ActionEvent e) {
+ pwHolder.cancelled = true;
+ f.dispose();
+ }
+ };
cancel.addActionListener(buttonListener);
resetGBC(c);
@@ -209,16 +211,16 @@ public class JDialogPasswordCallback implements PasswordCallback {
c.insets = new Insets(0, 0, 0, 0);
contentPane.add(buttonPanel, c);
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
// Create modal dialog
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
JDialog d = new JDialog(f, "Fedora Certificate System", true);
WindowListener windowListener = new WindowAdapter() {
- public void windowOpened(WindowEvent e) {
- pwField.requestFocus();
- }
- };
+ public void windowOpened(WindowEvent e) {
+ pwField.requestFocus();
+ }
+ };
d.addWindowListener(windowListener);
@@ -228,17 +230,17 @@ public class JDialogPasswordCallback implements PasswordCallback {
Dimension paneSize = d.getSize();
d.setLocation((screenSize.width - paneSize.width) / 2,
- (screenSize.height - paneSize.height) / 2);
+ (screenSize.height - paneSize.height) / 2);
d.getRootPane().setDefaultButton(ok);
// toFront seems to cause the dialog to go blank on unix!
- // d.toFront();
+ //d.toFront();
d.show();
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
// Return results
- // /////////////////////////////////////////////////
+ ///////////////////////////////////////////////////
if (pwHolder.cancelled) {
throw new PasswordCallback.GiveUpException();
}
@@ -251,8 +253,8 @@ public class JDialogPasswordCallback implements PasswordCallback {
try {
CryptoManager manager;
- CryptoManager.InitializationValues iv = new CryptoManager.InitializationValues(
- args[0]);
+ CryptoManager.InitializationValues iv = new
+ CryptoManager.InitializationValues(args[0]);
CryptoManager.initialize(iv);
manager = CryptoManager.getInstance();