Skip to content

Commit a9e6956

Browse files
srinjoyraygae-java-bot
authored andcommitted
Removing AccessController calls from appengine_standard/api_dev.
PiperOrigin-RevId: 726526586 Change-Id: I2c790f3d88387d2fabcec48adbf1b050f5174c11
1 parent 1ed7093 commit a9e6956

18 files changed

+512
-907
lines changed

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/FileBlobStorage.java

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.io.OutputStream;
27-
import java.security.AccessController;
28-
import java.security.PrivilegedAction;
29-
import java.security.PrivilegedActionException;
30-
import java.security.PrivilegedExceptionAction;
3127

3228
/**
3329
* {@code FileBlobStorage} provides durable persistence of blobs by storing blob content directly to
@@ -46,45 +42,17 @@ class FileBlobStorage implements BlobStorage {
4642
@Override
4743
public boolean hasBlob(final BlobKey blobKey) {
4844

49-
return AccessController.doPrivileged(
50-
new PrivilegedAction<Boolean>() {
51-
@Override
52-
public Boolean run() {
53-
return getFileForBlob(blobKey).exists();
54-
}
55-
});
45+
return getFileForBlob(blobKey).exists();
5646
}
5747

5848
@Override
5949
public OutputStream storeBlob(final BlobKey blobKey) throws IOException {
60-
try {
61-
return AccessController.doPrivileged(
62-
new PrivilegedExceptionAction<FileOutputStream>() {
63-
@Override
64-
public FileOutputStream run() throws IOException {
65-
return new FileOutputStream(getFileForBlob(blobKey));
66-
}
67-
});
68-
} catch (PrivilegedActionException ex) {
69-
Throwable cause = ex.getCause();
70-
throw (cause instanceof IOException) ? (IOException) cause : new IOException(cause);
71-
}
50+
return new FileOutputStream(getFileForBlob(blobKey));
7251
}
7352

7453
@Override
7554
public InputStream fetchBlob(final BlobKey blobKey) throws IOException {
76-
try {
77-
return AccessController.doPrivileged(
78-
new PrivilegedExceptionAction<FileInputStream>() {
79-
@Override
80-
public FileInputStream run() throws IOException {
81-
return new FileInputStream(getFileForBlob(blobKey));
82-
}
83-
});
84-
} catch (PrivilegedActionException ex) {
85-
Throwable cause = ex.getCause();
86-
throw (cause instanceof IOException) ? (IOException) cause : new IOException(cause);
87-
}
55+
return new FileInputStream(getFileForBlob(blobKey));
8856
}
8957

9058
@Override
@@ -98,21 +66,9 @@ public void deleteBlob(final BlobKey blobKey) throws IOException {
9866
&& blobInfoStorage.loadGsFileInfo(blobKey) == null) {
9967
throw new RuntimeException("Unknown blobkey: " + blobKey);
10068
}
101-
try {
102-
AccessController.doPrivileged(
103-
new PrivilegedExceptionAction<Void>() {
104-
@Override
105-
public Void run() throws IOException {
106-
File file = getFileForBlob(blobKey);
107-
if (!file.delete()) {
108-
throw new IOException("Could not delete: " + file);
109-
}
110-
return null;
111-
}
112-
});
113-
} catch (PrivilegedActionException ex) {
114-
Throwable cause = ex.getCause();
115-
throw (cause instanceof IOException) ? (IOException) cause : new IOException(cause);
69+
File file = getFileForBlob(blobKey);
70+
if (!file.delete()) {
71+
throw new IOException("Could not delete: " + file);
11672
}
11773
blobInfoStorage.deleteBlobInfo(blobKey);
11874
}

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/LocalBlobstoreService.java

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import java.io.File;
4444
import java.io.IOException;
4545
import java.io.InputStream;
46-
import java.security.AccessController;
47-
import java.security.PrivilegedAction;
4846
import java.util.Map;
4947
import java.util.logging.Level;
5048
import java.util.logging.Logger;
@@ -157,23 +155,18 @@ public CreateUploadURLResponse createUploadURL(Status status, CreateUploadURLReq
157155
}
158156

159157
public VoidProto deleteBlob(Status status, final DeleteBlobRequest request) {
160-
AccessController.doPrivileged(
161-
(PrivilegedAction<Object>)
162-
() -> {
163-
for (String blobKeyString : request.getBlobKeyList()) {
164-
BlobKey blobKey = new BlobKey(blobKeyString);
165-
if (blobStorage.hasBlob(blobKey)) {
166-
try {
167-
blobStorage.deleteBlob(blobKey);
168-
} catch (IOException ex) {
169-
logger.log(Level.WARNING, "Could not delete blob: " + blobKey, ex);
170-
throw new ApiProxy.ApplicationException(
171-
BlobstoreServiceError.ErrorCode.INTERNAL_ERROR_VALUE, ex.toString());
172-
}
173-
}
174-
}
175-
return null;
176-
});
158+
for (String blobKeyString : request.getBlobKeyList()) {
159+
BlobKey blobKey = new BlobKey(blobKeyString);
160+
if (blobStorage.hasBlob(blobKey)) {
161+
try {
162+
blobStorage.deleteBlob(blobKey);
163+
} catch (IOException ex) {
164+
logger.log(Level.WARNING, "Could not delete blob: " + blobKey, ex);
165+
throw new ApiProxy.ApplicationException(
166+
BlobstoreServiceError.ErrorCode.INTERNAL_ERROR_VALUE, ex.toString());
167+
}
168+
}
169+
}
177170

178171
return VoidProto.getDefaultInstance();
179172
}
@@ -222,27 +215,21 @@ public FetchDataResponse fetchData(Status status, final FetchDataRequest request
222215
} else {
223216
// Safe to cast because index will never be above MAX_BLOB_FETCH_SIZE.
224217
final byte[] data = new byte[(int) (endIndex - request.getStartIndex() + 1)];
225-
AccessController.doPrivileged(
226-
(PrivilegedAction<Object>)
227-
() -> {
228-
try {
229-
boolean swallowDueToThrow = true;
230-
InputStream stream = blobStorage.fetchBlob(blobKey);
231-
try {
232-
ByteStreams.skipFully(stream, request.getStartIndex());
233-
ByteStreams.readFully(stream, data);
234-
swallowDueToThrow = false;
235-
} finally {
236-
Closeables.close(stream, swallowDueToThrow);
237-
}
238-
} catch (IOException ex) {
239-
logger.log(Level.WARNING, "Could not fetch data: " + blobKey, ex);
240-
throw new ApiProxy.ApplicationException(
241-
BlobstoreServiceError.ErrorCode.INTERNAL_ERROR_VALUE, ex.toString());
242-
}
243-
244-
return null;
245-
});
218+
try {
219+
boolean swallowDueToThrow = true;
220+
InputStream stream = blobStorage.fetchBlob(blobKey);
221+
try {
222+
ByteStreams.skipFully(stream, request.getStartIndex());
223+
ByteStreams.readFully(stream, data);
224+
swallowDueToThrow = false;
225+
} finally {
226+
Closeables.close(stream, swallowDueToThrow);
227+
}
228+
} catch (IOException ex) {
229+
logger.log(Level.WARNING, "Could not fetch data: " + blobKey, ex);
230+
throw new ApiProxy.ApplicationException(
231+
BlobstoreServiceError.ErrorCode.INTERNAL_ERROR_VALUE, ex.toString());
232+
}
246233

247234
response.setData(ByteString.copyFrom(data));
248235
}

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/UploadBlobServlet.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@
3434
import java.io.InputStream;
3535
import java.io.InputStreamReader;
3636
import java.io.OutputStream;
37-
import java.security.AccessController;
3837
import java.security.MessageDigest;
3938
import java.security.NoSuchAlgorithmException;
40-
import java.security.PrivilegedActionException;
41-
import java.security.PrivilegedExceptionAction;
4239
import java.security.SecureRandom;
4340
import java.text.SimpleDateFormat;
4441
import java.util.ArrayList;
@@ -126,24 +123,7 @@ public void init() throws ServletException {
126123
@Override
127124
public void doPost(final HttpServletRequest req, final HttpServletResponse resp)
128125
throws ServletException, IOException {
129-
try {
130-
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
131-
@Override
132-
public Object run() throws ServletException, IOException {
133-
handleUpload(req, resp);
134-
return null;
135-
}
136-
});
137-
} catch (PrivilegedActionException ex) {
138-
Throwable cause = ex.getCause();
139-
if (cause instanceof ServletException) {
140-
throw (ServletException) cause;
141-
} else if (cause instanceof IOException) {
142-
throw (IOException) cause;
143-
} else {
144-
throw new ServletException(cause);
145-
}
146-
}
126+
handleUpload(req, resp);
147127
}
148128

149129
private String getSessionId(HttpServletRequest req) {

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/ee10/UploadBlobServlet.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@
4747
import java.io.InputStream;
4848
import java.io.InputStreamReader;
4949
import java.io.OutputStream;
50-
import java.security.AccessController;
5150
import java.security.MessageDigest;
5251
import java.security.NoSuchAlgorithmException;
53-
import java.security.PrivilegedActionException;
54-
import java.security.PrivilegedExceptionAction;
5552
import java.security.SecureRandom;
5653
import java.text.SimpleDateFormat;
5754
import java.util.ArrayList;
@@ -132,24 +129,7 @@ public void init() throws ServletException {
132129
@Override
133130
public void doPost(final HttpServletRequest req, final HttpServletResponse resp)
134131
throws ServletException, IOException {
135-
try {
136-
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
137-
@Override
138-
public Object run() throws ServletException, IOException {
139-
handleUpload(req, resp);
140-
return null;
141-
}
142-
});
143-
} catch (PrivilegedActionException ex) {
144-
Throwable cause = ex.getCause();
145-
if (cause instanceof ServletException) {
146-
throw (ServletException) cause;
147-
} else if (cause instanceof IOException) {
148-
throw (IOException) cause;
149-
} else {
150-
throw new ServletException(cause);
151-
}
152-
}
132+
handleUpload(req, resp);
153133
}
154134

155135
private String getSessionId(HttpServletRequest req) {

api_dev/src/main/java/com/google/appengine/api/datastore/dev/LocalCompositeIndexManager.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import java.io.InputStream;
5353
import java.io.InputStreamReader;
5454
import java.io.Writer;
55-
import java.security.AccessController;
56-
import java.security.PrivilegedAction;
5755
import java.text.SimpleDateFormat;
5856
import java.util.ArrayList;
5957
import java.util.Arrays;
@@ -339,20 +337,13 @@ private File getGeneratedIndexFile() {
339337
/**
340338
* Returns an input stream for the generated indexes file or {@code null} if it doesn't exist.
341339
*/
342-
// @Nullable
343340
// @VisibleForTesting
344-
InputStream getGeneratedIndexFileInputStream() {
345-
return AccessController.doPrivileged(
346-
new PrivilegedAction<InputStream>() {
347-
@Override
348-
public InputStream run() {
349-
try {
350-
return new FileInputStream(getGeneratedIndexFile());
351-
} catch (FileNotFoundException e) {
352-
return null;
353-
}
354-
}
355-
});
341+
@Nullable InputStream getGeneratedIndexFileInputStream() {
342+
try {
343+
return new FileInputStream(getGeneratedIndexFile());
344+
} catch (FileNotFoundException e) {
345+
return null;
346+
}
356347
}
357348

358349
/** Returns a writer for the generated indexes file. */

0 commit comments

Comments
 (0)