Skip to content

Commit c2a31ea

Browse files
srinjoyraygae-java-bot
authored andcommitted
Removing AccessController calls from the following directories:
PiperOrigin-RevId: 726767193 Change-Id: I8438d16bd2279d183da439f75c285bccfd575f71
1 parent 0210a43 commit c2a31ea

6 files changed

Lines changed: 67 additions & 123 deletions

File tree

api/src/main/java/com/google/appengine/spi/ServiceFactoryFactory.java

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package com.google.appengine.spi;
1818

1919
import com.google.common.base.Preconditions;
20-
import java.security.AccessController;
21-
import java.security.PrivilegedAction;
2220
import java.util.ArrayList;
2321
import java.util.Collections;
2422
import java.util.List;
@@ -137,44 +135,36 @@ private static final class RuntimeRegistry {
137135
}
138136
}
139137

140-
/**
141-
* Retrieves the list of factory providers from the classpath
142-
*/
138+
/** Retrieves the list of factory providers from the classpath */
143139
private static List<FactoryProvider<?>> getProvidersUsingServiceLoader() {
144-
return AccessController.doPrivileged(
145-
new PrivilegedAction<List<FactoryProvider<?>>>() {
146-
@Override
147-
public List<FactoryProvider<?>> run() {
148-
List<FactoryProvider<?>> result = new ArrayList<FactoryProvider<?>>();
149-
150-
// Sandboxed applications use the classloader of this class (ServiceFactoryFactory).
151-
// VM runtime applications use the thread context classloader (if not null) and fall
152-
// back to
153-
// the ServiceFactoryFactory classloader otherwise.
154-
//
155-
ClassLoader classLoader = null;
156-
if (Boolean.getBoolean(USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY)) {
157-
classLoader = Thread.currentThread().getContextClassLoader();
158-
}
159-
if (classLoader == null) {
160-
// If the classloader isn't set (or set to null). Use the classloader of this class.
161-
classLoader = ServiceFactoryFactory.class.getClassLoader();
162-
}
163-
164-
// Can't use parameterized types in ServiceLoader.load
165-
//
166-
@SuppressWarnings("rawtypes")
167-
ServiceLoader<FactoryProvider> providers =
168-
ServiceLoader.load(FactoryProvider.class, classLoader);
169-
170-
if (providers != null) {
171-
for (FactoryProvider<?> provider : providers) {
172-
result.add(provider);
173-
}
174-
}
175-
176-
return result;
177-
}
178-
});
140+
List<FactoryProvider<?>> result = new ArrayList<FactoryProvider<?>>();
141+
142+
// Sandboxed applications use the classloader of this class (ServiceFactoryFactory).
143+
// VM runtime applications use the thread context classloader (if not null) and fall
144+
// back to
145+
// the ServiceFactoryFactory classloader otherwise.
146+
//
147+
ClassLoader classLoader = null;
148+
if (Boolean.getBoolean(USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY)) {
149+
classLoader = Thread.currentThread().getContextClassLoader();
150+
}
151+
if (classLoader == null) {
152+
// If the classloader isn't set (or set to null). Use the classloader of this class.
153+
classLoader = ServiceFactoryFactory.class.getClassLoader();
154+
}
155+
156+
// Can't use parameterized types in ServiceLoader.load
157+
//
158+
@SuppressWarnings("rawtypes")
159+
ServiceLoader<FactoryProvider> providers =
160+
ServiceLoader.load(FactoryProvider.class, classLoader);
161+
162+
if (providers != null) {
163+
for (FactoryProvider<?> provider : providers) {
164+
result.add(provider);
165+
}
166+
}
167+
168+
return result;
179169
}
180170
}

local_runtime_shared_jetty12/src/main/java/com/google/apphosting/utils/servlet/ModulesServlet.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import com.google.common.collect.ImmutableMap;
2424
import com.google.common.collect.Iterables;
2525
import java.io.IOException;
26-
import java.security.AccessController;
27-
import java.security.PrivilegedAction;
2826
import java.util.Map;
2927
import java.util.logging.Logger;
3028
import javax.servlet.ServletException;
@@ -125,23 +123,15 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
125123
final String action = req.getParameter(ACTION_MODULE);
126124

127125
if (action != null && moduleName != null && moduleVersion != null) {
128-
AccessController.doPrivileged(
129-
new PrivilegedAction<Object>() {
130-
@Override
131-
public Object run() {
132-
try {
133-
if (action.equals("Stop")) {
134-
getModulesController().stopModule(moduleName, moduleVersion);
135-
} else if (action.equals("Start")) {
136-
getModulesController().startModule(moduleName, moduleVersion);
137-
}
138-
} catch (Exception e) {
139-
logger.severe(
140-
"Got error when performing a " + action + " of module : " + moduleName);
141-
}
142-
return null;
143-
}
144-
});
126+
try {
127+
if (action.equals("Stop")) {
128+
getModulesController().stopModule(moduleName, moduleVersion);
129+
} else if (action.equals("Start")) {
130+
getModulesController().startModule(moduleName, moduleVersion);
131+
}
132+
} catch (Exception e) {
133+
logger.severe("Got error when performing a " + action + " of module : " + moduleName);
134+
}
145135
} else {
146136
logger.severe("The post method against the modules servlet was called without all of the " +
147137
"expected post parameters, we got [moduleName = " + moduleName + ", moduleVersion = " +

local_runtime_shared_jetty12/src/main/java/com/google/apphosting/utils/servlet/ee10/ModulesServlet.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import jakarta.servlet.http.HttpServletRequest;
2828
import jakarta.servlet.http.HttpServletResponse;
2929
import java.io.IOException;
30-
import java.security.AccessController;
31-
import java.security.PrivilegedAction;
3230
import java.util.Map;
3331
import java.util.logging.Logger;
3432

@@ -125,23 +123,15 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
125123
final String action = req.getParameter(ACTION_MODULE);
126124

127125
if (action != null && moduleName != null && moduleVersion != null) {
128-
AccessController.doPrivileged(
129-
new PrivilegedAction<Object>() {
130-
@Override
131-
public Object run() {
132-
try {
133-
if (action.equals("Stop")) {
134-
getModulesController().stopModule(moduleName, moduleVersion);
135-
} else if (action.equals("Start")) {
136-
getModulesController().startModule(moduleName, moduleVersion);
137-
}
138-
} catch (Exception e) {
139-
logger.severe(
140-
"Got error when performing a " + action + " of module : " + moduleName);
141-
}
142-
return null;
143-
}
144-
});
126+
try {
127+
if (action.equals("Stop")) {
128+
getModulesController().stopModule(moduleName, moduleVersion);
129+
} else if (action.equals("Start")) {
130+
getModulesController().startModule(moduleName, moduleVersion);
131+
}
132+
} catch (Exception e) {
133+
logger.severe("Got error when performing a " + action + " of module : " + moduleName);
134+
}
145135
} else {
146136
logger.severe("The post method against the modules servlet was called without all of the " +
147137
"expected post parameters, we got [moduleName = " + moduleName + ", moduleVersion = " +

local_runtime_shared_jetty9/src/main/java/com/google/apphosting/utils/servlet/ModulesServlet.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import com.google.common.collect.ImmutableMap;
2424
import com.google.common.collect.Iterables;
2525
import java.io.IOException;
26-
import java.security.AccessController;
27-
import java.security.PrivilegedAction;
2826
import java.util.Map;
2927
import java.util.logging.Logger;
3028
import javax.servlet.ServletException;
@@ -125,23 +123,16 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
125123
final String action = req.getParameter(ACTION_MODULE);
126124

127125
if (action != null && moduleName != null && moduleVersion != null) {
128-
AccessController.doPrivileged(
129-
new PrivilegedAction<Object>() {
130-
@Override
131-
public Object run() {
132-
try {
133-
if (action.equals("Stop")) {
134-
getModulesController().stopModule(moduleName, moduleVersion);
135-
} else if (action.equals("Start")) {
136-
getModulesController().startModule(moduleName, moduleVersion);
137-
}
138-
} catch (Exception e) {
139-
logger.severe(
140-
"Got error when performing a " + action + " of module : " + moduleName);
141-
}
142-
return null;
143-
}
144-
});
126+
try {
127+
if (action.equals("Stop")) {
128+
getModulesController().stopModule(moduleName, moduleVersion);
129+
} else if (action.equals("Start")) {
130+
getModulesController().startModule(moduleName, moduleVersion);
131+
}
132+
} catch (Exception e) {
133+
logger.severe(
134+
"Got error when performing a " + action + " of module : " + moduleName);
135+
}
145136
} else {
146137
logger.severe("The post method against the modules servlet was called without all of the " +
147138
"expected post parameters, we got [moduleName = " + moduleName + ", moduleVersion = " +

runtime_shared/src/main/java/com/google/appengine/api/LifecycleManager.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package com.google.appengine.api;
1818

1919
import com.google.apphosting.api.ApiProxy;
20-
import java.security.AccessController;
21-
import java.security.PrivilegedAction;
2220
import java.util.HashMap;
2321
import java.util.List;
2422
import java.util.Map;
@@ -55,23 +53,14 @@ public synchronized void setShutdownHook(ShutdownHook hook) {
5553
hooks.put(currentAppVersionId(), hook);
5654
}
5755

58-
/**
59-
* Calls Thread.interrupt() on all threads running requests for this
60-
* application.
61-
*/
56+
/** Calls Thread.interrupt() on all threads running requests for this application. */
6257
public void interruptAllRequests() {
63-
AccessController.doPrivileged(
64-
new PrivilegedAction<Void>() {
65-
@Override public Void run() {
66-
List<Thread> threads = ApiProxy.getRequestThreads();
67-
if (threads != null) {
68-
for (Thread thread : threads) {
69-
thread.interrupt();
70-
}
71-
}
72-
return null;
73-
}
74-
});
58+
List<Thread> threads = ApiProxy.getRequestThreads();
59+
if (threads != null) {
60+
for (Thread thread : threads) {
61+
thread.interrupt();
62+
}
63+
}
7564
}
7665

7766
/**

shared_sdk/src/main/java/com/google/apphosting/runtime/SessionManagerUtil.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import java.io.ObjectStreamClass;
2727
import java.lang.reflect.Modifier;
2828
import java.lang.reflect.Proxy;
29-
import java.security.AccessController;
30-
import java.security.PrivilegedAction;
3129
import java.util.HashMap;
3230
import java.util.Map;
3331

@@ -52,12 +50,8 @@ public static Object deserialize(byte[] bytes) {
5250
// N.B.: There is most likely user code on the stack
5351
// here, but because the value we're returning is not related to
5452
// our ClassLoader we'll fail the
55-
// RuntimePermission("getClassLoader") check. We do have this
56-
// permission though, so use a doPrivileged block to get user code
57-
// off the stack.
58-
ClassLoader classLoader =
59-
AccessController.doPrivileged(
60-
(PrivilegedAction<ClassLoader>) () -> Thread.currentThread().getContextClassLoader());
53+
// RuntimePermission("getClassLoader") check.
54+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
6155
// TODO: It seems strange that we need to do this. It
6256
// would be safer and cleaner if we could find a way to have user
6357
// code initiate this serialization, rather than having

0 commit comments

Comments
 (0)