Source Code Cross Referenced for OpenSSHAuthorizedKeysFormat.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.OpenSSHPublicKeyFormat;
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 OpenSSHAuthorizedKeysFormat implements 
049:                AuthorizedKeysFormat {
050:            /**
051:             *
052:             *
053:             * @param keys
054:             * @param saver
055:             *
056:             * @return
057:             *
058:             * @throws IOException
059:             * @throws InvalidSshKeyException
060:             * @throws UnsupportedOperationException
061:             */
062:            public byte[] format(AuthorizedKeys keys,
063:                    AuthorizedKeysFileSaver saver) throws IOException,
064:                    InvalidSshKeyException {
065:                throw new UnsupportedOperationException(
066:                        "The OpenSSH authorized key file does not support additional key files!");
067:            }
068:
069:            /**
070:             *
071:             *
072:             * @param formatted
073:             * @param loader
074:             *
075:             * @return
076:             *
077:             * @throws IOException
078:             * @throws InvalidSshKeyException
079:             * @throws UnsupportedOperationException
080:             */
081:            public AuthorizedKeys unformat(byte[] formatted,
082:                    AuthorizedKeysFileLoader loader) throws IOException,
083:                    InvalidSshKeyException {
084:                throw new UnsupportedOperationException(
085:                        "The OpenSSH authorized key file does not support additional key files!");
086:            }
087:
088:            /**
089:             *
090:             *
091:             * @param keys
092:             *
093:             * @return
094:             *
095:             * @throws IOException
096:             * @throws InvalidSshKeyException
097:             */
098:            public byte[] format(AuthorizedKeys keys) throws IOException,
099:                    InvalidSshKeyException {
100:                ByteArrayOutputStream out = new ByteArrayOutputStream();
101:                SshPublicKeyFile pubfile;
102:                OpenSSHPublicKeyFormat openssh = new OpenSSHPublicKeyFormat();
103:                Map.Entry entry;
104:
105:                for (Iterator it = keys.getAuthorizedKeys().entrySet()
106:                        .iterator(); (it != null) && it.hasNext();) {
107:                    entry = (Map.Entry) it.next();
108:                    openssh.setComment((String) entry.getValue());
109:                    pubfile = SshPublicKeyFile.create((SshPublicKey) entry
110:                            .getKey(), openssh);
111:                    out.write(pubfile.toString().getBytes("US-ASCII"));
112:                    out.write('\n');
113:                }
114:
115:                return out.toByteArray();
116:            }
117:
118:            /**
119:             *
120:             *
121:             * @param formatted
122:             *
123:             * @return
124:             *
125:             * @throws IOException
126:             * @throws InvalidSshKeyException
127:             */
128:            public AuthorizedKeys unformat(byte[] formatted)
129:                    throws IOException, InvalidSshKeyException {
130:                AuthorizedKeys keys = new AuthorizedKeys();
131:                BufferedReader reader = new BufferedReader(
132:                        new InputStreamReader(new ByteArrayInputStream(
133:                                formatted)));
134:                String line;
135:                SshPublicKeyFile pubfile;
136:
137:                while ((line = reader.readLine()) != null) {
138:                    pubfile = SshPublicKeyFile.parse(line.getBytes("US-ASCII"));
139:                    keys.addKey(pubfile.getComment(), pubfile.toPublicKey());
140:                }
141:
142:                return keys;
143:            }
144:
145:            /**
146:             *
147:             *
148:             * @return
149:             */
150:            public boolean requiresKeyFiles() {
151:                return false;
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.