TFS 2010 - 为什么我在模拟时会收到“TF30063您无权访问..”错误?

时间:2011-12-02 16:44:57

标签: c# tfs tfs2010 impersonation

我试图通过冒充用户来创建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();

两个帐户都设置了“代表他人发出请求”权限。

2 个答案:

答案 0 :(得分:1)

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

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

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

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

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

我希望这会有所帮助。

谢谢!

答案 1 :(得分:0)

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

我认为您的问题是您只有在模拟“服务器”的情况下才有权使用该服务器。等级,但你试图模仿集合。

这就是泰勒在他的Introducing TFS Impersonation博客文章中所说的话:

  

此权限封装在每个Team Project Collection中   并在配置服务器中。这意味着如果用户A有   在TPC1上的这个权限,他将不被允许冒充用户   与TPC2或配置服务器通信时。同样,如果用户   B在配置服务器上具有此权限她将无法使用   在与任何团队项目集合交谈时模拟用户