~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/src/com/sun/grid/jgdi/management/JGDISslRMIClientSocketFactory.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2006 by Sun Microsystems, Inc
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
/*
 
34
 * JGDISslRMIClientSocketFactory.java
 
35
 *
 
36
 * Created on May 26, 2006, 1:24 PM
 
37
 */
 
38
 
 
39
package com.sun.grid.jgdi.management;
 
40
 
 
41
 
 
42
import java.io.File;
 
43
import java.io.IOException;
 
44
import java.net.Socket;
 
45
import java.util.StringTokenizer;
 
46
import javax.net.SocketFactory;
 
47
import javax.net.ssl.SSLSocket;
 
48
import javax.rmi.ssl.SslRMIClientSocketFactory;
 
49
 
 
50
 
 
51
 
 
52
/**
 
53
 * This client socket factory creates <code>SSLSocket</code>s for RMI.
 
54
 *
 
55
 * @see javax.rmi.ssl.SslRMIClientSocketFactory
 
56
 */
 
57
public class JGDISslRMIClientSocketFactory extends SslRMIClientSocketFactory {
 
58
 
 
59
    private final static long serialVersionUID = -2008021101L;
 
60
 
 
61
    private final File caTop;
 
62
    
 
63
    public JGDISslRMIClientSocketFactory(File caTop) {
 
64
        this.caTop = caTop;
 
65
    }
 
66
    
 
67
    /**
 
68
     * <p>Creates an SSL socket.</p>
 
69
     *
 
70
     * <p>If the system property
 
71
     * <code>javax.rmi.ssl.client.enabledCipherSuites</code> is
 
72
     * specified, this method will call {@link
 
73
     * SSLSocket#setEnabledCipherSuites(String[])} before returning
 
74
     * the socket. The value of this system property is a string that
 
75
     * is a comma-separated list of SSL/TLS cipher suites to
 
76
     * enable.</p>
 
77
     *
 
78
     * <p>If the system property
 
79
     * <code>javax.rmi.ssl.client.enabledProtocols</code> is
 
80
     * specified, this method will call {@link
 
81
     * SSLSocket#setEnabledProtocols(String[])} before returning the
 
82
     * socket. The value of this system property is a string that is a
 
83
     * comma-separated list of SSL/TLS protocol versions to
 
84
     * enable.</p>
 
85
     *
 
86
     * @param host  the host
 
87
     * @param port  the port
 
88
     * @return the created socket
 
89
     * @throws java.io.IOException on any io error
 
90
     */
 
91
    @Override
 
92
    public final Socket createSocket(final String host, final int port)
 
93
            throws IOException {
 
94
 
 
95
        // Retrieve the SSLSocketFactory
 
96
        //
 
97
        final SocketFactory sslSocketFactory = SSLHelper.getInstanceByCaTop(caTop).getSocketFactory();
 
98
        
 
99
        // Create the SSLSocket
 
100
        //
 
101
        final SSLSocket sslSocket =
 
102
                (SSLSocket)sslSocketFactory.createSocket(host, port);
 
103
        
 
104
        // Set the SSLSocket Enabled Cipher Suites
 
105
        //
 
106
        final String enabledCipherSuites =
 
107
                java.lang.System.getProperty("javax.rmi.ssl.client.enabledCipherSuites");
 
108
 
 
109
        if (enabledCipherSuites != null) {
 
110
            StringTokenizer st = new StringTokenizer(enabledCipherSuites, ",");
 
111
            int tokens = st.countTokens();
 
112
            String [] enabledCipherSuitesList = new String[tokens];
 
113
 
 
114
            for (int i = 0; i < tokens; i++) {
 
115
                enabledCipherSuitesList[i] = st.nextToken();
 
116
            }
 
117
 
 
118
            try {
 
119
                sslSocket.setEnabledCipherSuites(enabledCipherSuitesList);
 
120
            } catch (IllegalArgumentException e) {
 
121
                throw (IOException)new IOException(e.getMessage()).initCause(e);
 
122
            }
 
123
        }
 
124
        // Set the SSLSocket Enabled Protocols
 
125
        //
 
126
        final String enabledProtocols =
 
127
                java.lang.System.getProperty("javax.rmi.ssl.client.enabledProtocols");
 
128
 
 
129
        if (enabledProtocols != null) {
 
130
            StringTokenizer st = new StringTokenizer(enabledProtocols, ",");
 
131
            int tokens = st.countTokens();
 
132
            String [] enabledProtocolsList = new String[tokens];
 
133
 
 
134
            for (int i = 0; i < tokens; i++) {
 
135
                enabledProtocolsList[i] = st.nextToken();
 
136
            }
 
137
 
 
138
            try {
 
139
                sslSocket.setEnabledProtocols(enabledProtocolsList);
 
140
            } catch (IllegalArgumentException e) {
 
141
                throw (IOException)
 
142
                new IOException(e.getMessage()).initCause(e);
 
143
            }
 
144
        }
 
145
        // Return the preconfigured SSLSocket
 
146
        //
 
147
        return sslSocket;
 
148
    }
 
149
 
 
150
}