diff --git a/CHANGES.txt b/CHANGES.txt index 7cf4a4c3f5b..9d85f991f3a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -71,6 +71,9 @@ Trunk (unreleased changes) HADOOP-6826. FileStatus needs unit tests. (Rodrigo Schmidt via Eli Collins) + HADOOP-6905. add buildDTServiceName method to SecurityUtil + (as part of MAPREDUCE-1718) (boryas) + OPTIMIZATIONS BUG FIXES diff --git a/src/java/org/apache/hadoop/security/SecurityUtil.java b/src/java/org/apache/hadoop/security/SecurityUtil.java index ed01b62a4ca..b6a4486ce88 100644 --- a/src/java/org/apache/hadoop/security/SecurityUtil.java +++ b/src/java/org/apache/hadoop/security/SecurityUtil.java @@ -17,6 +17,7 @@ package org.apache.hadoop.security; import java.io.IOException; +import java.net.URI; import java.net.URL; import java.security.AccessController; import java.util.Set; @@ -28,7 +29,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; -import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.net.NetUtils; import sun.security.jgss.krb5.Krb5Util; import sun.security.krb5.Credentials; @@ -106,4 +107,23 @@ public class SecurityUtil { Subject.getSubject(AccessController.getContext()).getPrivateCredentials() .add(Krb5Util.credsToTicket(serviceCred)); } + + /** + * create service name for Delegation token ip:port + * @param uri + * @param defPort + * @return "ip:port" + */ + public static String buildDTServiceName(URI uri, int defPort) { + int port = uri.getPort(); + if(port == -1) + port = defPort; + + // build the service name string "/ip:port" + // for whatever reason using NetUtils.createSocketAddr(target).toString() + // returns "localhost/ip:port" + StringBuffer sb = new StringBuffer(); + sb.append(NetUtils.normalizeHostName(uri.getHost())).append(":").append(port); + return sb.toString(); + } }