]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/UiUserInfo.java
1 package org
.argeo
.slc
.jsch
;
3 import java
.awt
.Container
;
4 import java
.awt
.GridLayout
;
6 import java
.awt
.event
.ActionEvent
;
7 import java
.awt
.event
.ActionListener
;
8 import java
.util
.Arrays
;
10 import javax
.swing
.JButton
;
11 import javax
.swing
.JDialog
;
12 import javax
.swing
.JFrame
;
13 import javax
.swing
.JLabel
;
14 import javax
.swing
.JPanel
;
15 import javax
.swing
.JPasswordField
;
17 public class UiUserInfo
extends SimpleUserInfo
{
19 private Boolean alwaysPrompt
= false;
21 public boolean promptPassphrase(String message
) {
22 if (passphrase
!= null)
25 if (!alwaysPrompt
&& passphraseSafe
!= null)
28 PasswordDialog dialog
= new PasswordDialog(message
) {
29 private static final long serialVersionUID
= 3266299327166418364L;
32 protected void useCredentials(char[] password
) {
33 passphraseSafe
= new char[password
.length
];
34 System
.arraycopy(password
, 0, passphraseSafe
, 0,
36 // passphraseSafe = Arrays.copyOf(password, password.length);
39 dialog
.setVisible(true);
40 return dialog
.getWasProvided();
43 public boolean promptPassword(String message
) {
47 if (!alwaysPrompt
&& passwordSafe
!= null)
50 PasswordDialog dialog
= new PasswordDialog(message
) {
51 private static final long serialVersionUID
= 3266299327166418364L;
54 protected void useCredentials(char[] password
) {
55 // passwordSafe = Arrays.copyOf(password, password.length);
56 passwordSafe
= new char[password
.length
];
57 System
.arraycopy(password
, 0, passwordSafe
, 0, password
.length
);
60 dialog
.setVisible(true);
61 return dialog
.getWasProvided();
64 public void setAlwaysPrompt(Boolean alwaysPrompt
) {
65 this.alwaysPrompt
= alwaysPrompt
;
68 protected static class PasswordDialog
extends JDialog
implements
70 private static final long serialVersionUID
= 3399155607980846207L;
72 private static final String OK
= "ok";
74 private JPasswordField password
= new JPasswordField("", 10);
76 private JButton okButton
;
77 private JButton cancelButton
;
79 private Boolean wasProvided
= false;
81 public PasswordDialog(String title
) {
84 setLocationRelativeTo(null);
85 setDefaultCloseOperation(JFrame
.DISPOSE_ON_CLOSE
);
87 JPanel p1
= new JPanel(new GridLayout(1, 2, 3, 3));
88 p1
.add(new JLabel("Password"));
89 password
.setActionCommand(OK
);
90 password
.addActionListener(this);
94 Panel p2
= new Panel();
95 okButton
= addButton(p2
, "OK");
96 okButton
.setActionCommand(OK
);
97 cancelButton
= addButton(p2
, "Cancel");
104 /** To be overridden */
105 protected void useCredentials(char[] password
) {
109 private JButton
addButton(Container c
, String name
) {
110 JButton button
= new JButton(name
);
111 button
.addActionListener(this);
116 public final void actionPerformed(ActionEvent evt
) {
117 Object source
= evt
.getSource();
118 if (source
== okButton
|| evt
.getActionCommand().equals(OK
)) {
119 char[] p
= password
.getPassword();
124 } else if (source
== cancelButton
)
128 private void cleanUp() {
129 password
.setText("");
133 public Boolean
getWasProvided() {