TFS 2010 -为什么我得到TF30063你没有被授权访问.模拟时出错

本文关键字:授权 访问 模拟 出错 为什么 2010 TF30063 TFS | 更新日期: 2023-09-27 18:16:34

我试图通过冒充用户在TFS2010中创建一个错误,但总是得到

"TF30063 You are not authorized to access.."

我首先使用一个服务帐户进行身份验证,然后尝试模拟一个单独的用户帐户。我可以成功地创建工作项使用两个帐户编程和在web UI。然而,当我尝试使用模拟帐户创建工作项时(无论哪种方式),我总是得到这个错误。我的代码是:

public int Save(List<KeyValuePair<string, string>> values, ticketType type,string user)
    {
        // get the Uri to the project collection to use
        Uri  tfsuri = new Uri("http://94.23.12.119:8085/tfs");            
        // get a reference to the team project collection (authenticate as generic service account)
        using (var tfs = new TfsTeamProjectCollection(tfsuri, new System.Net.NetworkCredential("username", "password", "servername")))
        {
            tfs.EnsureAuthenticated();
            //Now get the details of the user we want to impersonate
            TeamFoundationIdentity identity = GetImpersonatedIdentity(tfsuri,tfs,user);
            //Now connect as the impersonated user
            using (TfsTeamProjectCollection ImpersonatedTFS = new TfsTeamProjectCollection(tfsuri, identity.Descriptor))
            {
                ImpersonatedTFS.EnsureAuthenticated();
                var workItemStore = GetWorkItemStore(ImpersonatedTFS);
                // create a new work item
                WorkItem wi = new WorkItem(GetWorkItemType(type, workItemStore));
                {
                    //Values are supplied as a KVP - Field Name/Value
                    foreach (KeyValuePair<string,string> kvp in values)
                    {
                        if (wi.Fields.Contains(kvp.Key))
                        {
                            wi.Fields[kvp.Key].Value = kvp.Value;
                        }
                    }
                    ValidationResult = wi.Validate();                       
                }
                if (ValidationResult.Count == 0)
                {
                    wi.Save();
                    return wi.Id;
                }
                else
                { 
                    return 0;
                }
            }
        }
    }

它成功获得了冒充的身份,但在

上发生了故障。
ImpersonatedTFS.EnsureAuthenticated();

两个帐户都有'Make requests on behalf others'权限集

TFS 2010 -为什么我得到TF30063你没有被授权访问.模拟时出错

首先让我澄清一件事。看起来你的应用程序是一个服务器应用程序,在这种情况下,使用EnsureAuthenticated().没有任何价值,它只是一个性能调优技巧,以帮助UI/桌面客户端。

现在回到你的主要问题:-如果您的应用程序在本地访问时按预期工作,但在远程访问时失败,那么请继续阅读,否则这不是适合您的解决方案。

失败的原因是需要将SPN添加到活动目录上的服务帐户。这是进行Kerberos身份验证所必需的。

这是TFS团队需要解释的事情,因为许多开发人员会在专注于手头的工作时忘记它。希望对你有帮助。

要了解有关SPN和Kerberos基础知识的更多信息,请查看以下参考资料:

  • 繁忙管理员的Kerberos。
  • Kerberos SPN简介

我希望这对你有帮助。

谢谢!

您的用户在哪里拥有Make requests on behalf of others权限集?它是在项目集合级别(通过Team > Team Project Collection Settings > Security..访问)还是在TFS服务器级别(通过Team Foundation Administration Console > Application Tier > Security..访问)?

我认为您的问题是您只有在"服务器"级别进行模拟的权限,但您试图在集合中进行模拟。

这是Taylor在他的介绍TFS模拟博客文章中所说的:

此权限封装在每个Team Project Collection中并在配置服务器中。这意味着如果用户A有此权限在TPC1上,他将不被允许冒充用户当与TPC2或配置服务器通信时。类似地,如果UserB在配置服务器上有此权限,但她不能在与任何Team Project collection 对话时模拟用户。