mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8165180: Provide a shared secret to access non-public ServerSocket constructor
Reviewed-by: chegar
This commit is contained in:
parent
4a0362efff
commit
b5172ce65e
3 changed files with 80 additions and 0 deletions
|
@ -25,8 +25,13 @@
|
||||||
|
|
||||||
package java.net;
|
package java.net;
|
||||||
|
|
||||||
|
import jdk.internal.misc.JavaNetSocketAccess;
|
||||||
|
import jdk.internal.misc.SharedSecrets;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
@ -1011,4 +1016,27 @@ class ServerSocket implements java.io.Closeable {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
SharedSecrets.setJavaNetSocketAccess(
|
||||||
|
new JavaNetSocketAccess() {
|
||||||
|
@Override
|
||||||
|
public ServerSocket newServerSocket(SocketImpl impl) {
|
||||||
|
return new ServerSocket(impl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SocketImpl newSocketImpl(Class<? extends SocketImpl> implClass) {
|
||||||
|
try {
|
||||||
|
Constructor<? extends SocketImpl> ctor =
|
||||||
|
implClass.getDeclaredConstructor();
|
||||||
|
return ctor.newInstance();
|
||||||
|
} catch (NoSuchMethodException | InstantiationException |
|
||||||
|
IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jdk.internal.misc;
|
||||||
|
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.SocketImpl;
|
||||||
|
|
||||||
|
public interface JavaNetSocketAccess {
|
||||||
|
/**
|
||||||
|
* Creates a ServerSocket associated with the given SocketImpl.
|
||||||
|
*/
|
||||||
|
ServerSocket newServerSocket(SocketImpl impl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructs a SocketImpl instance of the given class.
|
||||||
|
*/
|
||||||
|
SocketImpl newSocketImpl(Class<? extends SocketImpl> implClass);
|
||||||
|
}
|
|
@ -55,6 +55,7 @@ public class SharedSecrets {
|
||||||
private static JavaNetAccess javaNetAccess;
|
private static JavaNetAccess javaNetAccess;
|
||||||
private static JavaNetInetAddressAccess javaNetInetAddressAccess;
|
private static JavaNetInetAddressAccess javaNetInetAddressAccess;
|
||||||
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
|
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
|
||||||
|
private static JavaNetSocketAccess javaNetSocketAccess;
|
||||||
private static JavaNioAccess javaNioAccess;
|
private static JavaNioAccess javaNioAccess;
|
||||||
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
|
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
|
||||||
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
|
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
|
||||||
|
@ -161,6 +162,16 @@ public class SharedSecrets {
|
||||||
return javaNetHttpCookieAccess;
|
return javaNetHttpCookieAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setJavaNetSocketAccess(JavaNetSocketAccess jnsa) {
|
||||||
|
javaNetSocketAccess = jnsa;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JavaNetSocketAccess getJavaNetSocketAccess() {
|
||||||
|
if (javaNetSocketAccess == null)
|
||||||
|
unsafe.ensureClassInitialized(java.net.ServerSocket.class);
|
||||||
|
return javaNetSocketAccess;
|
||||||
|
}
|
||||||
|
|
||||||
public static void setJavaNioAccess(JavaNioAccess jna) {
|
public static void setJavaNioAccess(JavaNioAccess jna) {
|
||||||
javaNioAccess = jna;
|
javaNioAccess = jna;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue