如何使用 Waffle 获取客户端用户名?
How to get the client username with Waffle?
我 运行 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
为什么?如何纠正这个?
魔法是:$pageContext.request.remoteUser
首先,将 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
资源Link:
我 运行 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
为什么?如何纠正这个?
魔法是:$pageContext.request.remoteUser
首先,将 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