KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JXLoginPanelDemo


1 /*
2  * $Id: JXLoginPanelDemo.java,v 1.2 2005/01/28 01:35:06 bino_george Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8
9 import org.jdesktop.swing.auth.*;
10 import javax.swing.ImageIcon JavaDoc;
11 import javax.swing.JFrame JavaDoc;
12 import javax.swing.JLabel JavaDoc;
13 import javax.swing.SwingConstants JavaDoc;
14 import javax.swing.UIManager JavaDoc;
15
16 /**
17  * <p>
18  * A simple demo for the <b>JXLoginPanel</b>.
19  * In order to run it correctly, you need to create JAAS config
20  * file that contains the JAAS configuration. Here is an example
21  * of a JAAS config file :
22  * </p>
23  * <pre>
24  * test {
25  * com.sun.security.auth.module.LdapLoginModule REQUIRED
26  * userProvider="ldap://sun-ds/ou=people,dc=sun,dc=com"
27  * userFilter="(&(uid={USERNAME})(objectClass=inetOrgPerson))"
28  * authzIdentity="{EMPLOYEENUMBER}"
29  * debug=true;
30  * };
31  * <p>
32  * Also you need to specify the following option on the java command line
33  * to indicate to JAAS the config file.
34  * </p>
35  * <pre>
36  * -Djava.security.auth.login.config==test.config
37  * </pre>
38  * Where test.config is the file name.
39  *
40  *
41  * @author Bino George
42  */

43 public class JXLoginPanelDemo {
44     static JFrame JavaDoc frame = new JFrame JavaDoc();
45
46     public static void main(String JavaDoc[] args) {
47         
48         JAASLoginService loginService = new JAASLoginService("test");
49         try {
50             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
51         }
52         catch (Exception JavaDoc e) {
53             e.printStackTrace();
54         }
55         JLabel JavaDoc header = new JLabel JavaDoc(new ImageIcon JavaDoc(JXLoginPanelDemo.class
56                 .getResource("resources/jdnc.png")));
57         JLabel JavaDoc label = new JLabel JavaDoc("Enter login information:");
58         label.setHorizontalTextPosition(SwingConstants.LEFT);
59         label.setHorizontalAlignment(SwingConstants.LEFT);
60         JXLoginPanel.showLoginDialog(frame, null, null, loginService,
61                 null, header, label, JXLoginPanel.SAVE_USERNAME);
62         System.exit(0);
63     }
64 }
Popular Tags