Source Code Cross Referenced for SSH2AuthorizedKeysFormat.java in  » Net » j2ssh » com » sshtools » common » automate » 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 » j2ssh » com.sshtools.common.automate 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  SSHTools - Java SSH2 API
003:         *
004:         *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
005:         *
006:         *  Contributions made by:
007:         *
008:         *  Brett Smith
009:         *  Richard Pernavas
010:         *  Erwin Bolwidt
011:         *
012:         *  This program is free software; you can redistribute it and/or
013:         *  modify it under the terms of the GNU General Public License
014:         *  as published by the Free Software Foundation; either version 2
015:         *  of the License, or (at your option) any later version.
016:         *
017:         *  This program is distributed in the hope that it will be useful,
018:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
019:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020:         *  GNU General Public License for more details.
021:         *
022:         *  You should have received a copy of the GNU General Public License
023:         *  along with this program; if not, write to the Free Software
024:         *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
025:         */
026:        package com.sshtools.common.automate;
027:
028:        import com.sshtools.j2ssh.transport.publickey.InvalidSshKeyException;
029:        import com.sshtools.j2ssh.transport.publickey.SECSHPublicKeyFormat;
030:        import com.sshtools.j2ssh.transport.publickey.SshPublicKey;
031:        import com.sshtools.j2ssh.transport.publickey.SshPublicKeyFile;
032:
033:        import java.io.BufferedReader;
034:        import java.io.ByteArrayInputStream;
035:        import java.io.ByteArrayOutputStream;
036:        import java.io.IOException;
037:        import java.io.InputStreamReader;
038:
039:        import java.util.Iterator;
040:        import java.util.Map;
041:
042:        /**
043:         *
044:         *
045:         * @author $author$
046:         * @version $Revision: 1.14 $
047:         */
048:        public class SSH2AuthorizedKeysFormat implements  AuthorizedKeysFormat {
049:            private static final String header = "# Open3SP auto-generated authorization file\n";
050:            private static final String key = "key ";
051:
052:            /**
053:             *
054:             *
055:             * @param keys
056:             *
057:             * @return
058:             *
059:             * @throws IOException
060:             * @throws InvalidSshKeyException
061:             * @throws java.lang.UnsupportedOperationException
062:             */
063:            public byte[] format(AuthorizedKeys keys) throws IOException,
064:                    InvalidSshKeyException {
065:                throw new java.lang.UnsupportedOperationException(
066:                        "SSH2 authorized keys format requries seperate key files!");
067:            }
068:
069:            /**
070:             *
071:             *
072:             * @param formatted
073:             *
074:             * @return
075:             *
076:             * @throws IOException
077:             * @throws InvalidSshKeyException
078:             * @throws java.lang.UnsupportedOperationException
079:             */
080:            public AuthorizedKeys unformat(byte[] formatted)
081:                    throws IOException, InvalidSshKeyException {
082:                throw new java.lang.UnsupportedOperationException(
083:                        "SSH2 authorized keys format requries seperate key files!");
084:            }
085:
086:            /**
087:             *
088:             *
089:             * @param keys
090:             * @param saver
091:             *
092:             * @return
093:             *
094:             * @throws IOException
095:             * @throws InvalidSshKeyException
096:             */
097:            public byte[] format(AuthorizedKeys keys,
098:                    AuthorizedKeysFileSaver saver) throws IOException,
099:                    InvalidSshKeyException {
100:                ByteArrayOutputStream out = new ByteArrayOutputStream();
101:                out.write(header.getBytes("US-ASCII"));
102:
103:                SshPublicKeyFile pubfile;
104:                SECSHPublicKeyFormat secsh = new SECSHPublicKeyFormat();
105:                Map.Entry entry;
106:
107:                for (Iterator it = keys.getAuthorizedKeys().entrySet()
108:                        .iterator(); (it != null) && it.hasNext();) {
109:                    entry = (Map.Entry) it.next();
110:
111:                    // Write out the public key file
112:                    String username = (String) entry.getValue();
113:                    String filename = username + ".pub";
114:                    secsh.setComment(username);
115:                    pubfile = SshPublicKeyFile.create((SshPublicKey) entry
116:                            .getKey(), secsh);
117:                    saver.saveFile(filename, pubfile.toString().getBytes(
118:                            "US-ASCII"));
119:
120:                    // Write out the key entry
121:                    out.write(key.getBytes("US-ASCII"));
122:                    out.write(filename.getBytes("US-ASCII"));
123:                    out.write('\n');
124:                }
125:
126:                return out.toByteArray();
127:            }
128:
129:            /**
130:             *
131:             *
132:             * @param formatted
133:             * @param loader
134:             *
135:             * @return
136:             *
137:             * @throws IOException
138:             * @throws InvalidSshKeyException
139:             */
140:            public AuthorizedKeys unformat(byte[] formatted,
141:                    AuthorizedKeysFileLoader loader) throws IOException,
142:                    InvalidSshKeyException {
143:                AuthorizedKeys keys = new AuthorizedKeys();
144:                BufferedReader reader = new BufferedReader(
145:                        new InputStreamReader(new ByteArrayInputStream(
146:                                formatted)));
147:                String line;
148:                SshPublicKeyFile pubfile;
149:                String filename;
150:                String username;
151:
152:                while ((line = reader.readLine()) != null) {
153:                    if (line.trim().startsWith("key")) {
154:                        // Get the filename and load
155:                        filename = line.substring(
156:                                line.trim().lastIndexOf(" ") + 1).trim();
157:                        pubfile = SshPublicKeyFile.parse(loader
158:                                .loadFile(filename));
159:
160:                        // Get the username from the filename - .pub
161:                        username = filename.substring(0, filename.length() - 4);
162:                        keys.addKey(username, pubfile.toPublicKey());
163:                    }
164:                }
165:
166:                return keys;
167:            }
168:
169:            /**
170:             *
171:             *
172:             * @return
173:             */
174:            public boolean requiresKeyFiles() {
175:                return true;
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.