我在 tomcat 7.0 服务器(称之为服务器 A)上部署了一个 servlet 应用程序。该应用程序将获取用户的凭据并将其传递到另一台服务器(服务器 B)以检索数据。
问题:
机器1的用户Alice登录到服务器A,服务器A使用Alice的凭证访问服务器B,getPasswordAuthentication()用于将Alice的凭证传递给服务器B,随后机器2的用户Bob登录到服务器A。服务器A将继续使用 Alice 的凭据访问服务器 B。我注意到没有为用户 Bob 调用 getPasswordAuthentication()。
有没有办法在每次服务器 A 尝试访问服务器 B 时强制进行身份验证? ps:如果在Server A上重启tomcat,重启后对Server B的第一个请求会进行鉴权。
非常感谢您的反馈。
最佳答案
在访问服务器 b 的资源之前,您需要使用 AuthCacheValue.setAuthCache(new AuthCacheImpl());
这是因为默认情况下会缓存凭据,并且没有指定缓存行为的配置。
import sun.net.www.protocol.http.AuthCacheValue;
import sun.net.www.protocol.http.AuthCacheImpl;
[....]
AuthCacheValue.setAuthCache(new AuthCacheImpl());
关于authentication - http服务器认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6240310/