在 rest 客户端中验证 Tomcat 身份验证



我正在使用rest full Web服务和tomcat安全性。我想编写一个 restclient,它将提供用户名和密码,并将在服务器中进行身份验证。

请提出一些方法,我该怎么做?

最简单的方法是通过基本的HTTP身份验证。您需要修改两个文件:

1. web.xml您的申请。加:

<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>Basic authentication</realm-name>
</login-config>
<security-role>
  <description>Some role description</description>
  <role-name>role1</role-name>
</security-role>

2. tomcat-users.xml conf目录中:

<tomcat-users>
  <user name="user1" password="pass" roles="role1" />
</tomcat-users>

最新更新