I'm developing and testing an App Engine application locally. I would like the application to print out a list of all Bucket names in the projects Google Cloud Storage.
Some code:
Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Bucket> buckets = storage.list(Storage.BucketListOption.pageSize(100));
Iterator<Bucket> bucketIterator = buckets.iterateAll();
while (bucketIterator.hasNext()) {
Bucket bucket = bucketIterator.next();
System.out.println("bucket name: " + bucket.getName());
}
To access Cloud Storage, I am using the google-cloud
library for Java found here: http://googlecloudplatform.github.io/google-cloud-java/0.9.4/index.html
Running the above snippet results in a 401 Unauthorized.
As specified under the "What is it?" section in the above link, if the application is running inside App Engine or Compute Engine, authentication is automatic.
Since I am running locally, I assume automatic authentication does not work (please correct me if i'm wrong).
To authenticate, I followed one of the options listed under the Authentication section and issued the command gcloud auth application-default login
in the terminal.
I no longer get a 401 unauthorized when trying to access Cloud Storage, however do get the following:
java.security.AccessControlException: access denied ("java.io.FilePermission" "/Users/example/.config/gcloud/active_config" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
AccessControlException
?