Source Code Cross Referenced for NetletJSSEWrapper.java in  » Portal » Open-Portal » com » sun » portal » proxylet » crypt » jsse » 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 » Portal » Open Portal » com.sun.portal.proxylet.crypt.jsse 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.proxylet.crypt.jsse;
002:
003:        import com.sun.portal.proxylet.crypt.jsse.NetletJSSEAuthContext;
004:
005:        import javax.net.ssl.*;
006:        import java.security.GeneralSecurityException;
007:        import java.net.Socket;
008:        import java.io.*;
009:
010:        /**
011:         *
012:         * $name:           com.sun.portal.proxylet.crypt.jsse.NetletJSSEWrapper
013:         * $description     The com.sun.portal.proxylet.crypt.jsse.NetletJSSEWrapper creates a PKCS12 store or JKS store based on the
014:         *                  store name provided by the user. It then does the handshake with
015:         *                  the server through a proxy, if proxy socket is set. The input and
016:         *                  output stream can then be used to transfer data securely.
017:         *
018:         */
019:        public class NetletJSSEWrapper {
020:            /**
021:             * The port the client will connect to
022:             */
023:            private int port = -1;
024:            /**
025:             * The host the client will connect to
026:             */
027:            private String host = null;
028:            /**
029:             * Used to generate a SocketFactory
030:             */
031:            private SSLContext sslContext = null;
032:            /**
033:             * Socket tunnel for proxy connections
034:             */
035:            private Socket tunnelSocket = null;
036:            /**
037:             * SSL Socket
038:             */
039:            private SSLSocket sslSocket = null;
040:            /**
041:             * This implements the functions needed to set the Keystore path and password.
042:             */
043:            private NetletJSSEAuthContext authContext = null;
044:            /**
045:             * InputStream to read data from
046:             */
047:            private InputStream is = null;
048:            /**
049:             * OutputStream to write data to  server
050:             */
051:            private OutputStream os = null;
052:            /**
053:             * Indicates if a handshake was performed or not
054:             */
055:            private boolean handshake = false;
056:            /**
057:             * SocketFactory object
058:             */
059:            private SSLSocketFactory sf = null;
060:
061:            /**
062:             * Constructor that sets the host and port
063:             * @param authContext
064:             * @throws java.lang.Exception
065:             */
066:            public NetletJSSEWrapper(NetletJSSEAuthContext authContext)
067:                    throws Exception {
068:                this .authContext = authContext;
069:                init();
070:            }
071:
072:            /**
073:             * init
074:             *          Initializes the context
075:             * @throws java.security.GeneralSecurityException
076:             * @throws java.io.IOException
077:             */
078:            public void init() throws GeneralSecurityException, IOException {
079:                setupSSLContext();
080:                sf = sslContext.getSocketFactory();
081:            }
082:
083:            /**
084:             * Gets the InputStream of the SSLSocket for communication
085:             * @return
086:             * @throws java.io.IOException
087:             */
088:            public InputStream getInputStream() throws IOException {
089:                return sslSocket.getInputStream();
090:            }
091:
092:            /**
093:             * Gets the outputstream of the SSLSocket for communication
094:             * @return
095:             * @throws java.io.IOException
096:             */
097:            public OutputStream getOutputStream() throws IOException {
098:                return sslSocket.getOutputStream();
099:            }
100:
101:            /**
102:             * setupSSLContext : Sets the SSL context with the trustmanager and key manager
103:             *                   The trustmanager accepts all certificates by default.
104:             * @throws java.security.GeneralSecurityException
105:             * @throws java.io.IOException
106:             */
107:            private void setupSSLContext() throws GeneralSecurityException,
108:                    IOException {
109:                NetletTrustManager tm = new NetletTrustManager();
110:                NetletKeyManager km = new NetletKeyManager(authContext);
111:
112:                KeyManager[] kmg = { km };
113:                TrustManager[] tmg = { tm };
114:                sslContext = SSLContext.getInstance("SSL");
115:                sslContext.init(kmg, tmg, null);
116:            }
117:
118:            /**
119:             * connect
120:             *          Sets the SSL context and Initializes the SSL socket.
121:             * @param host
122:             * @param port
123:             * @return
124:             * @throws Exception
125:             */
126:            public SSLSocket connect(String host, int port, Socket ts)
127:                    throws Exception {
128:                this .host = host;
129:                this .port = port;
130:                this .tunnelSocket = ts;
131:                SSLSocket socket = null;
132:                if (tunnelSocket != null)
133:                    socket = (SSLSocket) sf.createSocket(tunnelSocket, host,
134:                            port, false);
135:                else {
136:                    try {
137:                        socket = (SSLSocket) sf.createSocket(host, port);
138:                    } catch (Exception e) {
139:                        throw e;
140:                    }
141:                }
142:
143:                /*socket.addHandshakeCompletedListener(
144:                        new HandshakeCompletedListener() {
145:                            public void handshakeCompleted(HandshakeCompletedEvent event) {
146:                                System.out.println("Handshake finished!");
147:                                System.out.println(
148:                                        "\t CipherSuite:" + event.getCipherSuite());
149:                                System.out.println(
150:                                        "\t SessionId " + event.getSession());
151:                                System.out.println(
152:                                        "\t PeerHost " + event.getSession().getPeerHost());
153:                            }
154:                        }
155:                );
156:
157:                is = socket.getInputStream();
158:                os = socket.getOutputStream();*/
159:
160:                return socket;
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.