Source Code Cross Referenced for PGPPassChecker.java in  » Mail-Clients » columba-1.4 » org » columba » mail » pgp » 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 » Mail Clients » columba 1.4 » org.columba.mail.pgp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the 
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. 
014:        //
015:        //All Rights Reserved.
016:        package org.columba.mail.pgp;
017:
018:        import java.util.Hashtable;
019:        import java.util.Map;
020:        import java.util.Properties;
021:
022:        import org.columba.mail.gui.util.PGPPassphraseDialog;
023:        import org.waffel.jscf.JSCFConnection;
024:        import org.waffel.jscf.JSCFException;
025:        import org.waffel.jscf.JSCFStatement;
026:
027:        /**
028:         * Checks via a dialog if a passphrase (given from the user over the dialog) can
029:         * be used to sign a testmessage. The dialog-test is a while loop, which breaks
030:         * only if the user cancels the dialog or the passphrase is correct.
031:         * 
032:         * @author waffel
033:         * 
034:         */
035:        public class PGPPassChecker {
036:            private static PGPPassChecker myInstance = null;
037:
038:            private Map passwordMap = new Hashtable();
039:
040:            /**
041:             * Returns the instance of the class. If no instance is created, a new
042:             * instance are created.
043:             * 
044:             * @return a instance of this class.
045:             */
046:            public static PGPPassChecker getInstance() {
047:                if (myInstance == null) {
048:                    myInstance = new PGPPassChecker();
049:                }
050:
051:                return myInstance;
052:            }
053:
054:            /**
055:             * Checks with a test string if the test String can be signed. The user is
056:             * ask for his passphrase until the passphrase is ok or the user cancels the
057:             * dialog. If the user cancels the dialog the method returns false. This
058:             * method return normal only if the user give the right passphrase.
059:             * 
060:             * @param con
061:             *            JSCFConnection used to check a passphrase given by a dialog
062:             * @return Returns true if the given passphrase (via a dialog) is correct
063:             *         and the user can sign a teststring with the passphrase from the
064:             *         dialog. Returns false if the user cancels the dialog.
065:             * @exception JSCFException
066:             *                if the concrete JSCF implementation has real probelms (for
067:             *                example a extern tool cannot be found)
068:             */
069:            public boolean checkPassphrase(JSCFConnection con)
070:                    throws JSCFException {
071:                boolean stmtCheck = false;
072:                JSCFStatement stmt = con.createStatement();
073:
074:                // loop until signing was sucessful or the user cancels the passphrase
075:                // dialog
076:                Properties props = con.getProperties();
077:
078:                while (!stmtCheck && (this .checkPassphraseDialog(con) == true)) {
079:                    stmtCheck = stmt.checkPassphrase();
080:
081:                    if (!stmtCheck) {
082:                        this .passwordMap.remove(props.get("USERID"));
083:                    }
084:                }
085:
086:                return stmtCheck;
087:            }
088:
089:            private boolean checkPassphraseDialog(JSCFConnection con) {
090:                String passphrase = "";
091:                Properties props = con.getProperties();
092:
093:                if (this .passwordMap.containsKey(props.get("USERID"))) {
094:                    passphrase = (String) this .passwordMap.get(props
095:                            .get("USERID"));
096:                }
097:
098:                props.put("PASSWORD", passphrase);
099:
100:                boolean ret = true;
101:
102:                PGPPassphraseDialog dialog = new PGPPassphraseDialog();
103:
104:                if (passphrase.length() == 0) {
105:                    dialog.showDialog((String) props.get("USERID"),
106:                            (String) props.get("PASSWORD"), false);
107:
108:                    if (dialog.success()) {
109:                        passphrase = new String(dialog.getPassword(), 0, dialog
110:                                .getPassword().length);
111:                        props.put("PASSWORD", passphrase);
112:
113:                        boolean save = dialog.getSave();
114:
115:                        // save passphrase in hash map
116:                        if (save) {
117:                            this .passwordMap.put(props.get("USERID"),
118:                                    passphrase);
119:                        }
120:
121:                        ret = true;
122:                    } else {
123:                        ret = false;
124:                    }
125:                }
126:
127:                con.setProperties(props);
128:
129:                return ret;
130:            }
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.