我正在Tomcat 7
上运行Windows 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
计算机用户名。我在很多client
台计算机上试过它,它总是打印server
但不打印client
用户ID
为什么呢?怎么纠正这个?
答案 0 :(得分:2)
首先,将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 :(得分:1)
神奇的是:$pageContext.request.remoteUser