aboutsummaryrefslogtreecommitdiff
path: root/auth
diff options
context:
space:
mode:
authorEric Anderson <ejona@google.com>2015-09-10 15:25:37 -0700
committerEric Anderson <ejona@google.com>2015-09-11 09:37:50 -0700
commitbccaf074973278ed62573577cad9c3d5fdb8e320 (patch)
tree9f28def4ac4b7616d66d8a7527e9d85abad06155 /auth
parent5b2a03a02e80710a2093c24e66fd5a71158f819b (diff)
downloadgrpc-grpc-java-bccaf074973278ed62573577cad9c3d5fdb8e320.tar.gz
Use real authority parsing in ClientAuthInterceptor
Diffstat (limited to 'auth')
-rw-r--r--auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java25
1 files changed, 19 insertions, 6 deletions
diff --git a/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java b/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java
index 329685a91..add337f8f 100644
--- a/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java
+++ b/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java
@@ -116,18 +116,31 @@ public final class ClientAuthInterceptor implements ClientInterceptor {
}
// Always use HTTPS, by definition.
final String scheme = "https";
- // The default port must not be present. Alternative ports should be present.
- final String suffixToStrip = ":443";
- if (authority.endsWith(suffixToStrip)) {
- authority = authority.substring(0, authority.length() - suffixToStrip.length());
- }
+ final int defaultPort = 443;
String path = "/" + MethodDescriptor.extractFullServiceName(method.getFullMethodName());
+ URI uri;
try {
- return new URI(scheme, authority, path, null, null);
+ uri = new URI(scheme, authority, path, null, null);
} catch (URISyntaxException e) {
throw Status.UNAUTHENTICATED.withDescription("Unable to construct service URI for auth")
.withCause(e).asException();
}
+ // The default port must not be present. Alternative ports should be present.
+ if (uri.getPort() == defaultPort) {
+ uri = removePort(uri);
+ }
+ return uri;
+ }
+
+ private URI removePort(URI uri) throws StatusException {
+ try {
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), -1 /* port */,
+ uri.getPath(), uri.getQuery(), uri.getFragment());
+ } catch (URISyntaxException e) {
+ throw Status.UNAUTHENTICATED.withDescription(
+ "Unable to construct service URI after removing port")
+ .withCause(e).asException();
+ }
}
private Map<String, List<String>> getRequestMetadata(URI uri) throws StatusException {