/// <summary>Try to locate the required token for the server.</summary> /// <param name="authType">of the SASL client</param> /// <returns>Token<?> for server, or null if no token available</returns> /// <exception cref="System.IO.IOException">- token selector cannot be instantiated</exception> private Org.Apache.Hadoop.Security.Token.Token <object> GetServerToken(RpcHeaderProtos.RpcSaslProto.SaslAuth authType) { TokenInfo tokenInfo = SecurityUtil.GetTokenInfo(protocol, conf); Log.Debug("Get token info proto:" + protocol + " info:" + tokenInfo); if (tokenInfo == null) { // protocol has no support for tokens return(null); } TokenSelector <object> tokenSelector = null; try { tokenSelector = System.Activator.CreateInstance(tokenInfo.Value()); } catch (InstantiationException e) { throw new IOException(e.ToString()); } catch (MemberAccessException e) { throw new IOException(e.ToString()); } return(tokenSelector.SelectToken(SecurityUtil.BuildTokenService(serverAddr), ugi. GetTokens())); }
public virtual void TestBuildTokenServiceSockAddr() { SecurityUtil.SetTokenServiceUseIp(true); Assert.Equal("127.0.0.1:123", SecurityUtil.BuildTokenService(new IPEndPoint("LocalHost", 123)).ToString()); Assert.Equal("127.0.0.1:123", SecurityUtil.BuildTokenService(new IPEndPoint("127.0.0.1", 123)).ToString()); // what goes in, comes out Assert.Equal("127.0.0.1:123", SecurityUtil.BuildTokenService(NetUtils .CreateSocketAddr("127.0.0.1", 123)).ToString()); }
// check: // 1) buildTokenService honors use_ip setting // 2) setTokenService & getService works // 3) getTokenServiceAddr decodes to the identical socket addr private void VerifyTokenService(IPEndPoint addr, string host, string ip, int port , bool useIp) { //LOG.info("address:"+addr+" host:"+host+" ip:"+ip+" port:"+port); SecurityUtil.SetTokenServiceUseIp(useIp); string serviceHost = useIp ? ip : StringUtils.ToLowerCase(host); Org.Apache.Hadoop.Security.Token.Token <object> token = new Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier>(); Text service = new Text(serviceHost + ":" + port); Assert.Equal(service, SecurityUtil.BuildTokenService(addr)); SecurityUtil.SetTokenService(token, addr); Assert.Equal(service, token.GetService()); IPEndPoint serviceAddr = SecurityUtil.GetTokenServiceAddr(token); NUnit.Framework.Assert.IsNotNull(serviceAddr); VerifyValues(serviceAddr, serviceHost, ip, port); }