Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/jndi/ldap/DeadSSLSocketFactory.java
41153 views
1
/*
2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import javax.net.SocketFactory;
25
import javax.net.ssl.SSLSocket;
26
import javax.net.ssl.SSLSocketFactory;
27
import java.io.IOException;
28
import java.net.InetAddress;
29
import java.net.Socket;
30
import java.util.concurrent.atomic.AtomicBoolean;
31
import java.util.concurrent.atomic.AtomicReference;
32
33
/*
34
* A custom socket factory used to override the default socket factory and track the LDAP client connection.
35
* Factory can create only one SSLSocket. See the DeadServerTimeoutSSLTest test.
36
*/
37
public class DeadSSLSocketFactory extends SocketFactory {
38
// Client socket that is used by LDAP connection
39
public static AtomicReference<SSLSocket> firstCreatedSocket = new AtomicReference<>();
40
41
// Boolean to track if connection socket has been opened
42
public static AtomicBoolean isConnectionOpened = new AtomicBoolean(false);
43
44
// Default SSLSocketFactory that will be used for SSL socket creation
45
final SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
46
47
// Create unconnected socket
48
public Socket createSocket() throws IOException {
49
if (!isConnectionOpened.getAndSet(true)) {
50
System.err.println("DeadSSLSocketFactory: Creating unconnected socket");
51
firstCreatedSocket.set((SSLSocket) factory.createSocket());
52
return firstCreatedSocket.get();
53
} else {
54
throw new RuntimeException("DeadSSLSocketFactory only allows creation of one SSL socket");
55
}
56
}
57
58
public DeadSSLSocketFactory() {
59
System.err.println("DeadSSLSocketFactory: Constructor call");
60
}
61
62
public static SocketFactory getDefault() {
63
System.err.println("DeadSSLSocketFactory: acquiring DeadSSLSocketFactory as default socket factory");
64
return new DeadSSLSocketFactory();
65
}
66
67
@Override
68
public Socket createSocket(String host, int port) throws IOException {
69
// Not used by DeadSSLLdapTimeoutTest
70
return factory.createSocket(host, port);
71
}
72
73
@Override
74
public Socket createSocket(String host, int port, InetAddress localHost,
75
int localPort) throws IOException {
76
// Not used by DeadSSLLdapTimeoutTest
77
return factory.createSocket(host, port, localHost, localPort);
78
}
79
80
@Override
81
public Socket createSocket(InetAddress host, int port) throws IOException {
82
// Not used by DeadSSLLdapTimeoutTest
83
return factory.createSocket(host, port);
84
}
85
86
@Override
87
public Socket createSocket(InetAddress address, int port,
88
InetAddress localAddress, int localPort) throws IOException {
89
// Not used by DeadSSLLdapTimeoutTest
90
return factory.createSocket(address, port, localAddress, localPort);
91
}
92
}
93
94
95