KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > wfxml > WfXMLAuthenticator


1 /* WfXMLAuthenticator.java */
2 package org.enhydra.jawe.wfxml;
3
4 import java.awt.GridLayout JavaDoc;
5 import java.net.Authenticator JavaDoc;
6 import java.net.PasswordAuthentication JavaDoc;
7
8 import javax.swing.*;
9
10 /**
11  * WfXMLAuthenticator
12  *
13  * @author V.Puskas
14  * @version 0.1
15  */

16 public class WfXMLAuthenticator extends Authenticator JavaDoc {
17
18    private JDialog parent;
19
20    private JTextField jtf;
21
22    private JTextField jpf;
23
24    private JPanel jp;
25
26    private JLabel jl;
27
28    /**
29     * @param d
30     */

31    public WfXMLAuthenticator(JDialog d) {
32       super();
33       parent = d;
34       jtf = new JTextField();
35       jpf = new JPasswordField();
36       jl = new JLabel();
37       jp = new JPanel(new GridLayout JavaDoc(3, 2, 5, 3));
38       jp.add(new JLabel("Requesting Prompt:"));
39       jp.add(jl);
40       jp.add(new JLabel("Username:"));
41       jp.add(jtf);
42       jp.add(new JLabel("Password:"));
43       jp.add(jpf);
44    }
45
46    protected PasswordAuthentication JavaDoc getPasswordAuthentication() {
47       jl.setText(this.getRequestingPrompt());
48       int a = JOptionPane.showConfirmDialog(parent,
49                                             jp,
50                                             "Enter credentials, please!",
51                                             JOptionPane.OK_CANCEL_OPTION,
52                                             JOptionPane.QUESTION_MESSAGE);
53       //System.err.println("answer:\t"+a+"\njtfu:\t"+jtf.getText()+"\njtfp:\t"+jpf.getText());
54
if (JOptionPane.OK_OPTION == a) {
55          return new PasswordAuthentication JavaDoc(jtf.getText(), jpf.getText()
56             .toCharArray());
57       } else {
58          return null;
59       }
60    }
61 }
Popular Tags