Source Code Cross Referenced for DAVAuthenticatorImpl.java in  » Net » SkunkDAV » org » skunk » dav » client » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » SkunkDAV » org.skunk.dav.client.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (c) 2000, Jacob Smullyan.
003:         *
004:         *  This is part of SkunkDAV, a WebDAV client.  See http://skunkdav.sourceforge.net/ 
005:         *  for the latest version.
006:         * 
007:         *  SkunkDAV is free software; you can redistribute it and/or
008:         *  modify it under the terms of the GNU General Public License as published
009:         *  by the Free Software Foundation; either version 2, or (at your option)
010:         *  any later version.
011:         * 
012:         *  SkunkDAV  is distributed in the hope that it will be useful,
013:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *  General Public License for more details.
016:         * 
017:         *  You should have received a copy of the GNU General Public License
018:         *  along with SkunkDAV; see the file COPYING.  If not, write to the Free
019:         *  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020:         *  02111-1307, USA.
021:         */
022:
023:        package org.skunk.dav.client.gui;
024:
025:        import java.awt.GridBagConstraints;
026:        import java.awt.GridBagLayout;
027:        import java.awt.Insets;
028:        import java.io.IOException;
029:        import java.net.PasswordAuthentication;
030:        import javax.swing.JCheckBox;
031:        import javax.swing.JLabel;
032:        import javax.swing.JOptionPane;
033:        import javax.swing.JPanel;
034:        import javax.swing.JPasswordField;
035:        import javax.swing.JTextField;
036:        import org.skunk.dav.client.DAVAuthenticator;
037:        import org.skunk.trace.Debug;
038:
039:        public class DAVAuthenticatorImpl extends DAVAuthenticator {
040:            public static final String LOGIN_TITLE = ResourceManager
041:                    .getMessage(ResourceManager.LOGIN_TITLE);
042:            private String loginMessage, username, password;
043:            private boolean rememberPassword;
044:            private boolean testedOnce = false;
045:            private ServerData sd;
046:
047:            //private boolean showRemember=true;
048:
049:            public DAVAuthenticatorImpl() {
050:                loginMessage = LOGIN_TITLE;
051:            }
052:
053:            public DAVAuthenticatorImpl(String host, int port,
054:                    String initialPath) {
055:                //mea culpa -- this needs to be internationalized
056:                loginMessage = ResourceManager.getMessage(
057:                        ResourceManager.LOGIN_MESSAGE, new Object[] { host
058:                                + ":" + port + initialPath });
059:                //"Login to "+host+":"+port+initialPath;
060:                username = null;
061:                password = null;
062:                rememberPassword = false;
063:            }
064:
065:            public DAVAuthenticatorImpl(ServerData sd) {
066:                this (sd.getHost(), sd.getPort(), sd.getInitialPath());
067:                username = sd.getUsername();
068:                rememberPassword = sd.getRememberPassword();
069:                password = rememberPassword ? sd.getPassword() : null;
070:                this .sd = sd;
071:            }
072:
073:            //     public DAVAuthenticatorImpl(String host, int port, String initialPath, boolean showRemember)
074:            //     {
075:            // 	this(host, port, initialPath);
076:            // 	this.showRemember=false;
077:            //     }
078:
079:            public void reset() {
080:                testedOnce = false;
081:            }
082:
083:            protected PasswordAuthentication getPasswordAuthentication() {
084:                if (username == null || password == null || username.equals("")
085:                        || password.equals("") || !testedOnce) {
086:                    AuthenticatorPanel messagePanel = new AuthenticatorPanel(
087:                            username, password, rememberPassword);
088:                    // 	    if (!showRemember)
089:                    // 		messagePanel.setShowRemember(false);
090:                    int result = JOptionPane.showConfirmDialog(Explorer
091:                            .guessActiveExplorer(), messagePanel,
092:                            getLoginMessage(), JOptionPane.OK_CANCEL_OPTION,
093:                            JOptionPane.PLAIN_MESSAGE);
094:                    if (result == JOptionPane.OK_OPTION) {
095:                        String oldUsername = username;
096:                        username = messagePanel.getUsername();
097:                        String oldPassword = password;
098:                        password = messagePanel.getPassword();
099:                        boolean oldRememberPassword = rememberPassword;
100:                        rememberPassword = messagePanel.getRememberPassword();
101:                        boolean changed = false;
102:                        if (sd != null) {
103:                            if (oldUsername != null
104:                                    && !oldUsername.equals(username)) {
105:                                sd.setUsername(username);
106:                                changed = true;
107:                            }
108:                            if (rememberPassword) {
109:                                if (!oldRememberPassword) {
110:                                    sd.setRememberPassword(true);
111:                                    changed = true;
112:                                }
113:                                if (oldPassword != null
114:                                        && !oldPassword.equals(password)) {
115:                                    sd.setPassword(password);
116:                                    changed = true;
117:                                }
118:                            } else {
119:                                if (oldRememberPassword) {
120:                                    sd.setRememberPassword(false);
121:                                    changed = true;
122:                                }
123:                                if (oldPassword != null) {
124:                                    sd.setPassword(null);
125:                                    changed = true;
126:                                }
127:                            }
128:                        }
129:                        if (changed) {
130:                            try {
131:                                ServerData.saveServers();
132:                            } catch (IOException oyVeh) {
133:                                Debug.trace(this , Debug.DP2, oyVeh);
134:                            }
135:                        }
136:                    } else
137:                        return null;
138:                }
139:                testedOnce = true;
140:                return new PasswordAuthentication(username, password
141:                        .toCharArray());
142:            }
143:
144:            protected String getLoginMessage() {
145:                return loginMessage;
146:            }
147:
148:            class AuthenticatorPanel extends JPanel {
149:                JTextField usernameField = null;
150:                JTextField passwordField = null;
151:                JCheckBox rememberBox = null;
152:                String username, password;
153:                boolean rememberPassword;
154:                final String USERNAME_PROMPT = ResourceManager
155:                        .getMessage(ResourceManager.USERNAME_PROMPT);
156:                final String PASSWORD_PROMPT = ResourceManager
157:                        .getMessage(ResourceManager.PASSWORD_PROMPT);
158:                final String REMEMBER_PASSWORD_PROMPT = ResourceManager
159:                        .getMessage(ResourceManager.REMEMBER_PASSWORD_PROMPT);
160:
161:                //making it possible to turn off the rememberbox
162:                //boolean showRemember=true;
163:
164:                AuthenticatorPanel(String username, String password,
165:                        boolean rememberPassword) {
166:                    super ();
167:                    this .username = username;
168:                    this .password = password;
169:                    this .rememberPassword = rememberPassword;
170:                    initComponents();
171:                }
172:
173:                AuthenticatorPanel(String username, String password) {
174:                    this (username, password, true);
175:                }
176:
177:                // 	void setShowRemember(boolean showRemember)
178:                // 	{
179:                // 	    this.showRemember=showRemember;
180:                // 	}
181:
182:                private void initComponents() {
183:                    JLabel usernameLbl = new JLabel(USERNAME_PROMPT);
184:                    JLabel passwordLbl = new JLabel(PASSWORD_PROMPT);
185:
186:                    usernameField = new JTextField(18);
187:                    if (username != null)
188:                        usernameField.setText(username);
189:                    passwordField = new JPasswordField(18);
190:                    if (password != null)
191:                        passwordField.setText(password);
192:                    rememberBox = new JCheckBox(REMEMBER_PASSWORD_PROMPT,
193:                            this .rememberPassword);
194:
195:                    setLayout(new GridBagLayout());
196:                    GridBagConstraints gbc = new GridBagConstraints();
197:                    gbc.gridx = 0;
198:                    gbc.gridy = 0;
199:                    gbc.gridwidth = 1;
200:                    gbc.gridheight = 1;
201:                    gbc.weightx = 0.1;
202:                    gbc.insets = new Insets(2, 2, 2, 2);
203:                    gbc.fill = gbc.NONE;
204:                    gbc.ipadx = 1;
205:                    gbc.ipady = 1;
206:                    add(usernameLbl, gbc);
207:                    gbc.gridx++;
208:                    gbc.weightx = 0.5;
209:                    add(usernameField, gbc);
210:                    gbc.weightx = 0;
211:                    gbc.gridx = 0;
212:                    gbc.gridy++;
213:                    add(passwordLbl, gbc);
214:                    gbc.gridx++;
215:                    add(passwordField, gbc);
216:                    gbc.gridx = 0;
217:                    gbc.gridy++;
218:                    gbc.gridwidth = 2;
219:                    gbc.anchor = GridBagConstraints.CENTER;
220:                    //if (showRemember)
221:                    add(rememberBox, gbc);
222:
223:                }
224:
225:                String getUsername() {
226:                    if (usernameField != null)
227:                        return usernameField.getText().trim();
228:                    return new String();
229:                }
230:
231:                String getPassword() {
232:                    if (passwordField != null)
233:                        return passwordField.getText().trim();
234:                    return new String();
235:                }
236:
237:                boolean getRememberPassword() {
238:                    if (rememberBox != null)
239:                        return rememberBox.isSelected();
240:                    return false;
241:                }
242:            }
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.