gpt4 book ai didi

java - 如何使用 Waffle 获取客户端用户名?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:02 26 4
gpt4 key购买 nike

我在 Windows 7 上运行 Tomcat 7。所有客户端也都运行 Windows 7

我试图在 test.jsp 页面上打印客户端用户名,所以我使用 Waffle 。这是 WEB-INF/web.xml

 <filter>
<filter-name>SecurityFilter</filter-name>
<filter-class>waffle.servlet.NegotiateSecurityFilter</filter-class>
<init-param>
<param-name>impersonate</param-name>
<param-value>true</param-value>
</init-param>
</filter>

这是我的test.jsp

<% 
String userId = Secur32Util.getUserNameEx(Secur32.EXTENDED_NAME_FORMAT.NameSamCompatible);
out.println(userId);
%>

但是它总是打印 server computer username 。我在许多 client 机器上试过,它总是打印 server 而不是 client userid

为什么?如何纠正这个?

最佳答案

首先,将 waffle-api.jar 放在您的项目类路径中。然后将此 xml 代码放在您的 web.xml 中。

<filter>
<filter-name>SecurityFilter</filter-name>
<filter-class>waffle.servlet.NegotiateSecurityFilter</filter-class>
<init-param>
<param-name>principalFormat</param-name>
<param-value>fqn</param-value>
</init-param>
<init-param>
<param-name>roleFormat</param-name>
<param-value>both</param-value>
</init-param>
<init-param>
<param-name>allowGuestLogin</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>securityFilterProviders</param-name>
<param-value>
waffle.servlet.spi.NegotiateSecurityFilterProvider
waffle.servlet.spi.BasicSecurityFilterProvider
</param-value>
</init-param>
<init-param>
<param-name>waffle.servlet.spi.NegotiateSecurityFilterProvider/protocols</param-name>
<param-value>
Negotiate
NTLM
</param-value>
</init-param>
<init-param>
<param-name>waffle.servlet.spi.BasicSecurityFilterProvider/realm</param-name>
<param-value>WaffleFilterDemo</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

并使用下面的代码获取您的客户用户名;

HttpServletRequest request = (HttpServletRequest)Executions.getCurrent().getNativeRequest();
String user = request.getRemoteUser();

更多详情请访问:

https://github.com/dblock/waffle

归功于 klepon

资源链接:

  1. http://forum.zkoss.org/question/96532/get-clients-username/
  2. https://stackoverflow.com/a/5891022/2293534

关于java - 如何使用 Waffle 获取客户端用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40290761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com