Skip to content

Commit

Permalink
Remove uses of SecurityManager and AccessController dependencies (#3440)
Browse files Browse the repository at this point in the history
* Remove SecurityManager and AccessController dependencies in preparation for their deprecation in JDK 17.

* Reverted changes in GRPC core package since it requires updating public APIs.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas authored Oct 1, 2021
1 parent 2233758 commit ebcc6da
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates.
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,8 +37,7 @@ class ConfigThreadFactory implements ThreadFactory {
* @param type name of type of thread factory used just to customize thread name
*/
ConfigThreadFactory(String type) {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
group = Thread.currentThread().getThreadGroup();
namePrefix = "config-" + POOL_NUMBER.getAndIncrement() + ":" + type + "-";
ccl = Thread.currentThread().getContextClassLoader();
daemon = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.function.BooleanSupplier;

import com.oracle.svm.core.annotate.Substitute;
Expand All @@ -35,32 +33,10 @@ static final class ReflectionUtilSubstitution {
@SuppressWarnings("unchecked")
@Substitute
static <T> T createProxyInstance(Class<T> restClientClass) {
return AccessController.doPrivileged(new ProxyPrivilegedAction<>(restClientClass));
}
}

/**
* Only for native image.
* @param <T> type
*/
public static class ProxyPrivilegedAction<T> implements PrivilegedAction<T> {
private final Class<T> proxyInterface;

/**
* Only for native image.
* @param proxyInterface never call directly
*/
public ProxyPrivilegedAction(Class<T> proxyInterface) {
this.proxyInterface = proxyInterface;
}

@SuppressWarnings("unchecked")
@Override
public T run() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return (T) Proxy.newProxyInstance(cl,
new Class[] {proxyInterface},
new DefaultMethodProxyHandler());
new Class[] {restClientClass},
new DefaultMethodProxyHandler());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessController;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -60,8 +59,8 @@
*/
class HelidonConnector implements Connector {

private static final String HELIDON_VERSION = "Helidon/" + Version.VERSION + " (java " + AccessController
.doPrivileged(PropertiesHelper.getSystemProperty("java.runtime.version")) + ")";
private static final String HELIDON_VERSION = "Helidon/" + Version.VERSION + " (java "
+ PropertiesHelper.getSystemProperty("java.runtime.version") + ")";
static final Logger LOGGER = Logger.getLogger(HelidonConnector.class.getName());

private final WebClient webClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package io.helidon.microprofile.cdi;

import java.lang.invoke.MethodHandles;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.IdentityHashMap;
Expand Down Expand Up @@ -204,7 +202,7 @@ private ClassDefiningCl wrapCl(ClassLoader origCl) {
}

private ClassDefiningCl createCl(ClassLoader parent) {
return AccessController.doPrivileged((PrivilegedAction<ClassDefiningCl>) () -> new ClassDefiningCl(parent));
return new ClassDefiningCl(parent);
}

// a classloader that exposes define class methods
Expand Down

0 comments on commit ebcc6da

Please sign in to comment.