Skip to content

Commit f42bf84

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 2001 b: refs/heads/pubsub-alpha c: af94b53 h: refs/heads/master i: 1999: 717c839
1 parent 08f3e30 commit f42bf84

3 files changed

Lines changed: 20 additions & 22 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: 12078e04dabf1790f02ea17888bde24a7515d8bf
6+
refs/heads/pubsub-alpha: af94b5312daa978b693ce38b5f2314a335f3d531
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ private static class AppEngineCredentials extends GoogleCredentials {
4646
private final Method getAccessToken;
4747
private final Method getAccessTokenResult;
4848
private final Collection<String> scopes;
49-
private final boolean scopesRequired;
5049

5150
AppEngineCredentials() {
5251
try {
@@ -61,19 +60,16 @@ private static class AppEngineCredentials extends GoogleCredentials {
6160
this.getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class);
6261
this.getAccessToken = tokenResultClass.getMethod("getAccessToken");
6362
this.scopes = null;
64-
this.scopesRequired = true;
6563
} catch (Exception e) {
66-
throw new RuntimeException("Could not create AppEngineCredentials using reflection.");
64+
throw new RuntimeException("Could not create AppEngineCredentials.", e);
6765
}
6866
}
6967

70-
AppEngineCredentials(Collection<String> scopes, Object appIdentityService,
71-
Method getAccessToken, Method getAccessTokenResult) {
72-
this.appIdentityService = appIdentityService;
73-
this.getAccessToken = getAccessToken;
74-
this.getAccessTokenResult = getAccessTokenResult;
68+
AppEngineCredentials(Collection<String> scopes, AppEngineCredentials unscoped) {
69+
this.appIdentityService = unscoped.appIdentityService;
70+
this.getAccessToken = unscoped.getAccessToken;
71+
this.getAccessTokenResult = unscoped.getAccessTokenResult;
7572
this.scopes = scopes;
76-
this.scopesRequired = (scopes == null || scopes.isEmpty());
7773
}
7874

7975
/**
@@ -89,19 +85,18 @@ public AccessToken refreshAccessToken() throws IOException {
8985
String accessToken = (String) getAccessToken.invoke(accessTokenResult);
9086
return new AccessToken(accessToken, null);
9187
} catch (Exception e) {
92-
throw new RuntimeException("Could not get the access token using reflection.");
88+
throw new IOException("Could not get the access token.", e);
9389
}
9490
}
9591

9692
@Override
9793
public boolean createScopedRequired() {
98-
return scopesRequired;
94+
return scopes == null || scopes.isEmpty();
9995
}
10096

10197
@Override
10298
public GoogleCredentials createScoped(Collection<String> scopes) {
103-
return new AppEngineCredentials(
104-
scopes, appIdentityService, getAccessToken, getAccessTokenResult);
99+
return new AppEngineCredentials(scopes, this);
105100
}
106101
}
107102

@@ -308,6 +303,7 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden
308303
tempServiceAccountCredentials.getClientEmail(),
309304
tempServiceAccountCredentials.getPrivateKey());
310305
}
311-
throw new IOException("The given JSON Credentials Stream is not a service account credential.");
306+
throw new IOException(
307+
"The given JSON Credentials Stream is not for a service account credential.");
312308
}
313309
}

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,16 +562,18 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio
562562
for (SignUrlOption option : options) {
563563
optionMap.put(option.option(), option.value());
564564
}
565-
ServiceAccountAuthCredentials cred =
565+
ServiceAccountAuthCredentials serviceAccountAuthCred =
566566
(ServiceAccountAuthCredentials) optionMap.get(SignUrlOption.Option.SERVICE_ACCOUNT_CRED);
567-
if (cred == null) {
568-
AuthCredentials authCredentials = this.options().authCredentials();
567+
ServiceAccountCredentials cred = (ServiceAccountCredentials) (serviceAccountAuthCred != null
568+
? serviceAccountAuthCred.credentials() : null);
569+
if (serviceAccountAuthCred == null) {
570+
AuthCredentials authCred = this.options().authCredentials();
569571
GoogleCredentials serviceCred =
570-
authCredentials != null ? authCredentials.credentials() : null;
572+
authCred != null ? authCred.credentials() : null;
571573
checkArgument(
572574
serviceCred instanceof ServiceAccountCredentials,
573575
"Signing key was not provided and could not be derived");
574-
cred = (ServiceAccountAuthCredentials) authCredentials;
576+
cred = (ServiceAccountCredentials) serviceCred;
575577
}
576578
// construct signature - see https://cloud.google.com/storage/docs/access-control#Signed-URLs
577579
StringBuilder stBuilder = new StringBuilder();
@@ -607,12 +609,12 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio
607609
stBuilder.append(path);
608610
try {
609611
Signature signer = Signature.getInstance("SHA256withRSA");
610-
signer.initSign(cred.privateKey());
612+
signer.initSign(cred.getPrivateKey());
611613
signer.update(stBuilder.toString().getBytes(UTF_8));
612614
String signature =
613615
URLEncoder.encode(BaseEncoding.base64().encode(signer.sign()), UTF_8.name());
614616
stBuilder = new StringBuilder("https://storage.googleapis.com").append(path);
615-
stBuilder.append("?GoogleAccessId=").append(cred.account());
617+
stBuilder.append("?GoogleAccessId=").append(cred.getClientEmail());
616618
stBuilder.append("&Expires=").append(expiration);
617619
stBuilder.append("&Signature=").append(signature);
618620
return new URL(stBuilder.toString());

0 commit comments

Comments
 (0)