I'm trying to get a reference to a file in Cloud Endpoints (GAE Java) but I keep getting this error server side:
com.me.myapp.backend.utilities.Logger logError: [04/04/2016 6:32:24 PM] Exception in GoogleCloudStorageHelper.
java.security.AccessControlException: access denied ("java.io.FilePermission" "/WEB-INF/service-account-credentials.p12" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:382)
at java.security.AccessController.checkPermission(AccessController.java:572)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:55)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.io.FileInputStream.<init>(FileInputStream.java:156)
at java.io.FileInputStream.<init>(FileInputStream.java:117)
at com.me.myapp.backend.gcs.GoogleCloudStorageHelper.loadKeyFromPkcs12(GoogleCloudStorageHelper.java:67)
What I am trying to do is reference a .p12
file I have in my project to get a private key in order to create a signed URL to a Cloud Storage object:
final String SERVICE_ACCOUNT_PKCS12_FILE_PATH = "/WEB-INF/service-account-credentials.p12";
PrivateKey key = loadKeyFromPkcs12(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret".toCharArray());
private static PrivateKey loadKeyFromPkcs12(String filename, char[] password) throws Exception {
FileInputStream fis = new FileInputStream(filename);
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(fis, password);
return (PrivateKey) ks.getKey("privatekey", password);
}
But I guess I do not have permission to access my file? I read elsewhere that maybe I do not have the path correct to the file - if so, what should the path be..? My file is in the WEB-INF
directory.