1

I am trying to read a P12 key on App Engine ( Google ) They key is located in WEB-INF directory.

Currently I have this code :

Credential credential = new GoogleCredential.Builder()
                .setTransport(httpTransport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountId(ACCOUNT_ID_PROPERTY)
                .setServiceAccountPrivateKeyFromP12File(
                        new File("/WEB-INF/key.p12"))
                .setServiceAccountScopes(scopes).build();

But it's returning me this error :

java.security.AccessControlException: access denied ("java.io.FilePermission" "\WEB-INF\key.p12" "read")

Any idea's to fix this ?

Thanks !

David
  • 840
  • 6
  • 17
  • 37

1 Answers1

2

Please remove the forward slash from the path. Provide new File("WEB-INF/key.p12") and it should get through.

Romin
  • 8,708
  • 2
  • 24
  • 28
  • Wow, if that solves it (and Romin you're usually right) then the original exception and its message are seriously misleading, it's actually a path does not exist error. And then I wonder where one of us could bug report that. – Martin Berends Feb 25 '14 at 07:09
  • Actually due to the fact that a File class is being used, it takes the absolute path and hence it gives the error. Another way to avoid this I believe is to use InputStream is = context.getResourceAsStream("/WEB-INF/key.p12"); and it should be fine but I am not sure if that is the data type the method will accept. To look at current issues and file bugs : https://code.google.com/p/googleappengine/issues/list – Romin Feb 25 '14 at 07:25
  • Thanks and I do submit and follow AppEngine bug reports. What I meant to ask was whether bug reports about GoogleCredential.Builder() should go to AppEngine or elsewhere, or whether this is about File(). I second your getResourceAsStream suggestion. – Martin Berends Feb 25 '14 at 07:31
  • I believe this is about File(). – Romin Feb 25 '14 at 07:34
  • Fair enough. Then the File exception makes sense, it's AppEngine runtime saying "nobody is allowed to do File with me!", not just a particular path. You'd better correct your answer to use getResourceAsStream. – Martin Berends Feb 25 '14 at 07:37
  • That parameter needs to be of File type - so I am not sure about that. – Romin Feb 25 '14 at 08:30