Source Code Cross Referenced for RWGroupCrypt.java in  » Portal » Open-Portal » com » sun » portal » netlet » client » common » 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.netlet.client.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // %Z%%M% %I%     "%W% %E% Sun Microsystems"
002:
003:        package com.sun.portal.netlet.client.common;
004:
005:        import com.sun.portal.netlet.econnection.*;
006:
007:        import java.net.Socket;
008:        import java.io.*;
009:        import java.awt.event.ActionListener;
010:        import java.awt.event.ActionEvent;
011:        import java.awt.*;
012:
013:        class RWGroupCrypt extends ReaderWriterLock implements  KeyConstants,
014:                ActionListener {
015:
016:            volatile boolean done = false;
017:            private int srcPort;
018:            private String serverPort;
019:            private String serverHost;
020:            private Socket in_s;
021:            private Socket out_s;
022:            // Added for Lihue Pluggable Cipher
023:            private String cipherName;
024:            // End
025:            private ReaderWriterEncrypt src_to_dst;
026:            private ReaderWriterDecrypt dst_to_src;
027:
028:            private ProxySConn sconn;
029:            private Thread s2dThread;
030:            private Thread d2sThread;
031:            private SClient sc;
032:            public String newFtpAddrPort;
033:            private NetletErrorDialog ned;
034:
035:            RWGroupCrypt(Socket in, int connectionType, int sport, int srvport,
036:                    String srvhost, SClientMgr scm, SClient sclient,
037:                    String ciphername, int keylength) {
038:                this (in, connectionType, sport, new String("" + srvport),
039:                        srvhost, scm, sclient, ciphername, keylength);
040:            }
041:
042:            /*
043:             *  Constructor modified for RFE - 4645450 ( Lihue Netlet PRD 2.2 )
044:             */
045:
046:            RWGroupCrypt(Socket in, int connectionType, int sport,
047:                    String srvport, String srvhost, SClientMgr scm,
048:                    SClient sclient, String ciphername, int keylength) {
049:                in_s = in;
050:                srcPort = sport;
051:                serverPort = srvport;
052:                serverHost = srvhost;
053:                sc = sclient;
054:                cipherName = ciphername;
055:                ned = new NetletErrorDialog(new Frame(), this , null, null);
056:
057:                System.out.println("============================");
058:                System.out.println("RWGroupCrypt sport " + sport);
059:                System.out.println("RWGroupCrypt srvport " + srvport);
060:                System.out.println("RWGroupCrypt srvhost " + srvhost);
061:                System.out.println("RWGroupCrypt ciphername " + ciphername);
062:                System.out.println("============================");
063:
064:                if (ClientConfig.isProxyMode()) {
065:                    String fail = null;
066:                    try {
067:                        // try regular connection
068:                        sconn = new ProxySConn(ClientConfig.getProxyPort(),
069:                                ClientConfig.getProxyHost(), ClientConfig
070:                                        .getDestPort(), ClientConfig
071:                                        .getDestHost(), ciphername);
072:                    } catch (ProxyAuthNeededException e) {
073:                        // try again with proxy auth
074:                        try {
075:                            sconn = new ProxySConn(ClientConfig.getProxyPort(),
076:                                    ClientConfig.getProxyHost(), ClientConfig
077:                                            .getDestPort(), ClientConfig
078:                                            .getDestHost(), true, ciphername);
079:                        } catch (ProxyAuthNeededException ee) {
080:                            fail = ee.getMessage();
081:                        } catch (ProxyAuthFailedException ee) {
082:                            fail = ee.getMessage();
083:                        }
084:                    } catch (ProxyAuthFailedException e) {
085:                        fail = e.getMessage();
086:                    }
087:
088:                    // redundant exception handler
089:                    if (fail != null) {
090:                        System.out
091:                                .println("Netlet unable to authenticate to proxy server: "
092:                                        + fail);
093:                        // Unable to connect to security proxy server:
094:                        ned.setErrorMessage(ResourceProperties
095:                                .getString("rwgroup.1")
096:                                + " "
097:                                + ClientConfig.getProxyHost()
098:                                + ":"
099:                                + ClientConfig.getProxyPort());
100:                        ned.setVisible(true);
101:                        notifyparent();
102:                        return;
103:                    }
104:                } else {
105:                    sconn = new ProxySConn(ClientConfig.getDestPort(),
106:                            ClientConfig.getDestHost(), ciphername);
107:                }
108:                // out_s :: Connection with gateway
109:                out_s = sconn.getconn();
110:
111:                /**
112:                 * Create the SSL stream for communication.
113:                 */
114:                InputStream fromServer = null;
115:                OutputStream toServer = null;
116:                try {
117:                    fromServer = out_s.getInputStream();
118:                    toServer = out_s.getOutputStream();
119:                } catch (Exception ex) {
120:                    ex.printStackTrace();
121:                    earlyExit();
122:                    return;
123:                }
124:
125:                if (out_s == null) {
126:                    if (ClientConfig.isProxyMode()) {
127:                        System.out
128:                                .println("Netlet (RWGC-a) unable to make connection to proxy: "
129:                                        + ClientConfig.getProxyHost());
130:                        ned.setErrorMessage(ResourceProperties
131:                                .getString("rwgroup.1")
132:                                + " "
133:                                + ClientConfig.getProxyHost()
134:                                + ":"
135:                                + ClientConfig.getProxyPort());
136:                    } else {
137:                        System.out
138:                                .println("Netlet (RWGC-a) unable to make connection to gateway: "
139:                                        + ClientConfig.getDestHost());
140:                        // Unable to connect to Gateway:
141:                        ned.setErrorMessage(ResourceProperties
142:                                .getString("rwgroup.2")
143:                                + " "
144:                                + ClientConfig.getDestHost()
145:                                + ":"
146:                                + ClientConfig.getDestPort());
147:                    }
148:                    ned.setVisible(true);
149:                    notifyparent();
150:                    return;
151:                }
152:
153:                ESessionMsg eMsg = new ESessionMsg(("RP1.0").getBytes());
154:                if (eMsg.writeMsg(new DataOutputStream(toServer)) != 0) {
155:                    earlyExit();
156:                    return;
157:                }
158:
159:                //  tell erproxy that it's netlet...
160:                if (encryptSessionId(ClientConfig.getSessionID().getBytes(),
161:                        ClientConfig.getSessionID().getBytes().length,
162:                        new DataOutputStream(toServer)) != 0) {
163:                    earlyExit();
164:                    return;
165:                }
166:
167:                //  didn't use to encrypt proxy conf info...so hack it in
168:                ProxyCipherMsg pMsg = new ProxyCipherMsg(srcPort, serverPort
169:                        .getBytes(), serverPort.getBytes().length, serverHost
170:                        .getBytes(), serverHost.getBytes().length);
171:                if (pMsg.writeMsg(new DataOutputStream(toServer)) != 0) {
172:                    earlyExit();
173:                    return;
174:                }
175:
176:                pMsg = null;
177:
178:                if (srvport.equals("-1")) {
179:
180:                    try {
181:                        DataInputStream dis = new DataInputStream(fromServer);
182:                        newFtpAddrPort = dis.readInt() + "," + dis.readInt()
183:                                + "," + dis.readInt() + "," + dis.readInt()
184:                                + "," + dis.readInt() + "," + dis.readInt();
185:                        System.out.println("newFtpAddrPort " + newFtpAddrPort);
186:                    } catch (Exception ex) {
187:                        earlyExit();
188:                        return;
189:                    }
190:                }
191:
192:                // in_s :: ServerSocket b/w client & server
193:                InputStream fromClient = null;
194:                OutputStream toClient = null;
195:                try {
196:                    fromClient = in_s.getInputStream();
197:                    toClient = in_s.getOutputStream();
198:                } catch (IOException ex) {
199:                    System.out
200:                            .println("Unable to get the input/output stream from the client");
201:                    ex.printStackTrace();
202:                }
203:
204:                // Needed to support FTP client active mode using the PORT command
205:                //if( sport == 30021) {
206:                if (connectionType == ClientConfig.FTP) {
207:                    src_to_dst = new ReaderWriterEncryptFtp(this , fromClient,
208:                            toServer, 0, scm);
209:                } else {
210:                    src_to_dst = new ReaderWriterEncrypt(this , fromClient,
211:                            toServer,
212:                            /* ClientConfig.netletKeepAliveInterval */0);
213:                }
214:
215:                if (connectionType == ClientConfig.EXCHANGE) {
216:                    dst_to_src = new ReaderWriterDecryptExchange(this ,
217:                            fromServer, toClient, srvhost, scm);
218:                } else if (connectionType == ClientConfig.FTP) {
219:                    dst_to_src = new ReaderWriterDecryptFtp(this , fromServer,
220:                            toClient, scm);
221:                } else {
222:                    dst_to_src = new ReaderWriterDecrypt(this , fromServer,
223:                            toClient);
224:                }
225:
226:                s2dThread = new Thread(src_to_dst);
227:                //	s2dThread.setDaemon(true);
228:                s2dThread.start();
229:
230:                d2sThread = new Thread(dst_to_src);
231:                //	d2sThread.setDaemon(true);
232:                d2sThread.start();
233:            }
234:
235:            public void notifyFinished(ReaderWriter obj) {
236:                if (obj == src_to_dst) {
237:                    // s2dThread must be set to null right away so that when
238:                    // notifyFinished is called again, it doesn't get killed while
239:                    // cleaning up
240:                    s2dThread = null;
241:
242:                    // Save the thread variable to avoid being set to null by the other
243:                    // ReaderWriter thread when this method is invoked again.
244:                    Thread d2sTemp = d2sThread;
245:                    if (d2sTemp != null) {
246:                        try {
247:                            dst_to_src.stop();
248:                            d2sTemp.stop();
249:                            d2sTemp.join();
250:                        } catch (InterruptedException e) {
251:                        }
252:                    }
253:                    d2sThread = null;
254:                } else if (obj == dst_to_src) {
255:                    // d2sThread must be set to null right away so that when
256:                    // notifyFinished is called again, it doesn't get killed while
257:                    // cleaning up
258:                    d2sThread = null;
259:
260:                    // Save the thread variable to avoid being set to null by the other
261:                    // ReaderWriter thread when this method is invoked again.
262:                    Thread s2dTemp = s2dThread;
263:                    if (s2dTemp != null) {
264:                        try {
265:                            src_to_dst.stop();
266:                            s2dTemp.stop();
267:                            s2dTemp.join();
268:                        } catch (InterruptedException e) {
269:                        }
270:                    }
271:                    s2dThread = null;
272:                }
273:                cleanup();
274:            }
275:
276:            public synchronized void stopAll() {
277:                if (!done) {
278:                    if (dst_to_src != null) {
279:                        //		dst_to_src.stop();
280:                        dst_to_src.netletstop();
281:                    }
282:                    if (src_to_dst != null) {
283:                        //		src_to_dst.stop();
284:                        src_to_dst.netletstop();
285:                    }
286:                    cleanup();
287:                }
288:            }
289:
290:            void earlyExit() {
291:                /*try {
292:                 if (sslSocket != null) {
293:                 sslSocket.close();
294:                 }
295:                 } catch (IOException e) {
296:                 }*/
297:                notifyparent();
298:            }
299:
300:            void cleanup() {
301:                if (in_s != null) {
302:                    try {
303:                        in_s.close();
304:                        in_s = null;
305:                    } catch (IOException e) {
306:                    }
307:                }
308:
309:                if (out_s != null) {
310:                    try {
311:                        out_s.close();
312:                        out_s = null;
313:                    } catch (IOException e) {
314:                    }
315:                }
316:
317:                src_to_dst = null;
318:                dst_to_src = null;
319:                sconn = null;
320:                if (sc != null) {
321:                    if (sc.isTrans()) {
322:                        sc.stopped = true;
323:                    }
324:                }
325:                notifyparent();
326:            }
327:
328:            void notifyparent() {
329:                done = true;
330:            }
331:
332:            private int encryptSessionId(byte[] id, int id_len,
333:                    DataOutputStream out) {
334:                int rc = 0;
335:
336:                /*
337:                 * Just a temp hack for 6.2. This is not getting used anywhere. Remove cipher Name
338:                 * as the part of protocol
339:                 */
340:
341:                if (cipherName == null) {
342:                    cipherName = "SSL_RSA_WITH_RC4_128_MD5";
343:                }
344:                // Sending the Dynamic Algorithm choosen by the user as a part of the header. 
345:                id = new StringBuffer(new String(id)).append("|").append(
346:                        cipherName).toString().getBytes();
347:                id_len += cipherName.length() + 1;
348:                SessionCipherMsg sMsg = new SessionCipherMsg(id, id_len);
349:
350:                if (sMsg.writeMsg(out) != 0) {
351:                    System.out
352:                            .println("Netlet (RWGC-a) unable to process session id");
353:                    rc = -1;
354:                }
355:                return (rc);
356:            }
357:
358:            /*
359:             * Added for RFE 4492648
360:             */
361:            public long getLastActivityTime() {
362:                return 0;
363:            }
364:
365:            /*
366:             * Added for Netlet PRD 1.8.1 for Lihue
367:             * dummy implementation
368:             */
369:
370:            public int getAppletSrcPort() {
371:                return 0;
372:            }
373:
374:            public long getStartTime() {
375:                return 0;
376:            }
377:
378:            public void actionPerformed(ActionEvent evt) {
379:                if ("OK".equals(evt.getActionCommand())) {
380:                    Object obj = evt.getSource();
381:                    if (obj == ned.okButton) {
382:                        ned.setVisible(false);
383:                    }
384:                }
385:            }
386:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.