简体   繁体   English

Java RESTful客户端[RESTEasy或Apache HttpClient]-另一端是NTLM

[英]Java RESTful client [RESTEasy or Apache HttpClient] - NTLM on the other side

How to call RESTful webservice (from Java - using RESTEasy/Apache HttpClient) which requires NTLM authentication within Active Directory, without necessity of entering user data again (domain, username, password) - user is already authenticated in Windows? 如何调用需要在Active Directory中进行NTLM身份验证的RESTful Web服务(从Java-使用RESTEasy / Apache HttpClient),而无需再次输入用户数据(域,用户名,密码)-用户已经在Windows中进行了身份验证?

GET http://some_server/restapi/books

This works perfectly from web browsers or even java.net.URL library - user is not getting prompted for credentials, no 401 authentication errors - simply 200 OK is returned. 这在Web浏览器甚至java.net.URL库中都可以完美运行-不会提示用户输入凭据,没有401身份验证错误-仅返回200 OK

How to do the same using Apache HttpClient or RESTEasy client? 如何使用Apache HttpClient或RESTEasy客户端执行相同操作?

You can do that with this structure; 您可以使用此结构来完成;

  1. When user first enter username and password, you can check user detail on active directory and if success, create an access_token by using username and password. 用户首次输入用户名和密码时,可以检查活动目录上的用户详细信息,如果成功,则可以使用用户名和密码创建access_token。 It may be sha-256 encryption(Refer here for creating sha-256) 可能是sha-256加密(有关创建sha-256的信息,请参阅此处
  2. Save that access_token to your db and give it an expire time. 将那个access_token保存到您的数据库,并给它一个过期时间。
  3. After successful access_token creation, respond that access token to user. 成功创建access_token后,将该访问令牌响应给用户。
  4. From now, you can use access_token for service requests 从现在开始,您可以使用access_token进行服务请求

You need to save access token on client side like local storage. 您需要像本地存储一样在客户端保存访问令牌。 Same as if you are useing http client, you can give that access_token in header. 与使用http客户端一样,您可以在标头中提供该access_token。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM