HADOOP-6805. add buildDTServiceName method to SecurityUtil (as part of MAPREDUCE-1718)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@965556 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Boris Shkolnik 2010-07-19 16:51:16 +00:00
parent 02b87fc6b3
commit 75e78e0484
2 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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();
}
}