简体   繁体   English

如何使用Java命令行应用程序对https://tfspreview.com(MIcrosoft托管的TFS)进行身份验证?

[英]How to authenticate to https://tfspreview.com (MIcrosoft-hosted TFS) using Java command line application?

I am trying to access https://tfspreview.com SOAP interface from my command line Java app. 我试图从我的命令行Java应用程序访问https://tfspreview.com SOAP接口。 Unlike the on-premises TFS services, this one uses Live ID authentication, which makes causes the communication to fail with a 302 redirect to their authentication service. 与本地TFS服务不同,此服务使用Live ID身份验证,这会导致通信失败,并将302重定向到其身份验证服务。 I have no idea how to proceed with authenticating there. 我不知道如何继续在那里进行身份验证。

Any pointers? 有什么指针吗?

< tl;dr > <tl; dr>

You can use Basic authentication to provide a headless experience to Team Foundation Service . 您可以使用基本身份验证Team Foundation Service提供无头体验。 Also, if you're not using the TFS SDK for Java , it may help you out. 此外,如果您没有使用TFS SDK for Java ,它可能会帮助您。

< /tl;dr > </ tl; dr>

Generally speaking, there are three types of credentials that you can use to authenticate, and that determines the mechanism you use for authentication: 一般来说,您可以使用三种类型的凭据进行身份验证,并确定用于身份验证的机制:

  1. A Live ID. 实时ID。 As you noted, this requires you to log in to a Windows Live with a web browser and use the resultant OAuth tokens to authenticate. 如您所述,这需要您使用Web浏览器登录Windows Live并使用生成的OAuth令牌进行身份验证。

  2. An additional password mapped to your Live ID, which exists for the purposes of Basic authentication. 映射到Live ID的附加密码,用于基本身份验证。 Instructions for setting up this additional mapping are available in the August 27 announcement about this feature . 有关此功能8月27日公告中提供了有关设置此附加映射的说明。

  3. A service account. 服务帐户。 In addition to the list of users (specified by Live ID), your Team Foundation Service account also has a special user account that it uses for things like build automation and the like. 除了用户列表(由Live ID指定)之外,您的Team Foundation Service帐户还有一个特殊的用户帐户,可用于构建自动化等。 There is one service account for each Team Foundation Service account and - as the name implies - this is an administrator account. 每个Team Foundation Service帐户都有一个服务帐户,顾名思义,这是一个管理员帐户。

Let's take a look at each option: 我们来看看每个选项:

Live ID : Authenticating with a Live ID using OAuth is going to be difficult for your command-line application. 实时ID :使用OAuth使用Live ID进行身份验证对于命令行应用程序来说将很困难。 What Visual Studio does here is to open Internet Explorer to tfspreview.com , which will ultimately prompt you to enter your Live ID credentials. Visual Studio在此处执行的操作是将Internet Explorer打开到tfspreview.com ,这最终将提示您输入Live ID凭据。 At that point, the various OAuth cookies will get set into your web browser. 此时,各种OAuth cookie将被设置到您的Web浏览器中。 Since Visual Studio and Internet Explorer share the same underlying HTTP connection mechanism, it can make use of these same cookies. 由于Visual Studio和Internet Explorer共享相同的底层HTTP连接机制,因此它可以使用这些相同的cookie。 With a Java command-line client, you don't have that luxury (unless you're writing this exclusively for Windows and want to write some JNI to call the system's HTTP library that is.) 使用Java命令行客户端,您没有那么奢侈(除非您专门为Windows编写此文件并希望编写一些JNI来调用系统的HTTP库。)

So what are your options? 那么你有什么选择呢? I suppose it's possible that you could follow the redirect you're given - at which point you will eventually get a login page that you could POST your credentials to and ultimately get an OAuth cookie sent back to you that you could then use for authentication. 我想你可能会按照你给出的重定向进行操作 - 此时你最终会得到一个登录页面,你可以将你的凭证发布到最终,然后将一个OAuth cookie发回给你,然后你可以用它来进行身份验证。 But I suspect that this is probably not the road you want to go down, though. 但我怀疑这可能不是你想要走下去的道路。 I strongly suspect that there's a healthy dose of JavaScript required to get you logged in. 我强烈怀疑你需要健康的JavaScript才能登录。

Basic Authentication : These require an additional step in setup, but are simple and obvious. 基本身份验证 :这些需要在设置中执行额外步骤,但这些步骤简单明了。 There's no reason not to use these. 没有理由不使用这些。

Service Accounts : Lacking a web browser, though, you are able to present a WRAP token with your service credentials. 服务帐户 :由于缺少一个网页浏览器,但是,你提出一个WRAP令牌与您的服务凭据。 You can view the service credentials for your account using the very helpful TFS Service Credential Viewer . 您可以使用非常有用的TFS服务凭据查看器查看您帐户的服务凭据 With your service account username and password you can create a WRAP cookie to authenticate with. 使用您的服务帐户用户名和密码,您可以创建一个WRAP cookie来进行身份验证。 But at this point, you're authenticating as the service account, not one of your user accounts. 但此时,您将作为服务帐户进行身份验证,而不是您的某个用户帐户。

If you don't want to mess with creating WRAP tokens yourself, you can also use the Team Foundation Server SDK for Java to build a connection. 如果您不想自己创建WRAP令牌,也可以使用Team Foundation Server SDK for Java来构建连接。 Simply hand your service credentials in as UsernamePasswordCredentials when you create a TFSTeamProjectCollection . 在创建TFSTeamProjectCollection时,只需将您的服务凭据作为UsernamePasswordCredentials TFSTeamProjectCollection Even if you don't want to use the API methods against the server, you can get the raw HTTPClient from that connection and it will have all the necessary configuration set. 即使您不想对服务器使用API​​方法,也可以从该连接获取原始HTTPClient ,并且它将具有所有必需的配置集。 Taking a dependency on the SDK will also benefit you if we add new authentication mechanisms to the Team Foundation Service in the future as the SDK's API should not change dramatically. 如果我们将来向Team Foundation Service添加新的身份验证机制,那么依赖SDK也将使您受益,因为SDK的API不会发生显着变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Azure 管道 Microsoft 托管代理上升级 java 版本? - How to upgrade java version on an Azure pipeline Microsoft-hosted agent? 如何使用 Java 类在 Jython 中设置 HTTPS 验证 header - How to set HTTPS authenticate header in Jython using Java classes Java应用程序调用IIS中承载的HTTPS WebAPI - Java Application call to HTTPS WebAPI hosted in IIS 如何使用Android SDK(Java)在Microsoft Report Server 2008上进行身份验证? - How to authenticate at Microsoft Report Server 2008 using Android SDK (Java)? 如何使用命令行在AWS实例上运行Java应用程序 - how to run java application on aws instance using command line Java 命令行应用程序 - Java Command Line Application 在命令行上运行 java 时显示错误消息“java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver” - Error message "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" is shown when run java on command line 如何使用 junit 测试命令行应用程序 - How to test a command line application using junit 在 Intellij (Java) 中使用命令行编译时如何修复“错误:com.fasterxml.jackson.databind 包不存在” - How to fix "error: package com.fasterxml.jackson.databind does not exist" when compiling using command line in Intellij (Java) 如何使用命令行编译java文件? - How to compile a java file using the command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM