Wildfly 10 Windows 认证

Wildfly 10 Windows authentication

我被 java Web 应用程序的 servlet 和安全过滤器卡住了。 所以我的 web.xml 看起来像这样:

<!-- <distributable/> -->

<filter>
<filter-name>com.company.xxx.xxx.xxx.SecurityFilter</filter-name>
<filter-class>com.company.xxx.xxx.xxx.SecurityFilter</filter-class>
</filter>

<filter>
<filter-name>WaffleSSOFilter</filter-name>
<filter-class>waffle.servlet.NegotiateSecurityFilter</filter-class>
<init-param>
  <param-name>securityFilterProviders</param-name>
  <param-value>
      waffle.servlet.spi.NegotiateSecurityFilterProvider
  </param-value>
 </init-param>
 <init-param>
  <param-name>allowGuestLogin</param-name>
  <param-value>false</param-value>
 </init-param>
 <init-param>
  <param-name>waffle.servlet.spi.NegotiateSecurityFilterProvider/protocols</param-name>
  <param-value>
      Negotiate
  </param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>com.company.xxx.xxx.xxx.SecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>WaffleSSOFilter</filter-name>
<url-pattern>/xxx/xxx/xxx/windowsLogin</url-pattern>
</filter-mapping>

<!-- Enabling it disables access to App from other computers -->
<context-param>
<param-name>org.jboss.weld.development</param-name>
<param-value>false</param-value>
</context-param>

<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/xxx/*</url-pattern>
</servlet-mapping>

</web-app>

我得到这个设置是因为我偶然发现了这个小 post: Multiple filters with same url mapping

然后我发现这个 post 帮助我找到了正确的方向:

所以我尝试在此处通过过滤器 WaffleSSOFilter 访问此部分。

public String getUserName( HttpServletRequest servletRequest )
  {
    Enumeration<String> headerNames = servletRequest.getHeaderNames();
    while ( headerNames.hasMoreElements() )
    {
      String headerName = headerNames.nextElement();
      String headerValue = servletRequest.getHeader( headerName );
      log.info( "Header Name:" + headerName + " " + headerValue );
    }
    String remotePrincipal = servletRequest.getRemoteUser();
    log.info( "REMOTE USER: " + remotePrincipal );
    log.info( "PRINCIPAL: " + servletRequest.getUserPrincipal().toString() );
    return remotePrincipal;
  }

这对我来说困难的部分是每个 URL 都需要第一个过滤器 "com.company.xxx.xxx.xxx.SecurityFilter",因为如果没有它,我们的应用程序就会崩溃,然后就什么也做不了了。但我需要一个特殊的 POST URL 用于我的 WaffleSSOFilter 以启用对访问该网站的远程计算机上登录的 windows 用户进行身份验证的能力。

目标是让登录页面具有正常的用户名和密码形式,并有一个复选框来启用 windows 身份验证。

通过此设置,我可以使用用户名和密码正常登录。该应用程序正在运行,到目前为止还不错。现在,如果我向我的特殊 URL 发出 POST 请求来测试 windows 身份验证,我会在访问 [=13= 时在之前的源代码中得到 java.lang.NullPointerException ]

问题:我的过滤器设置错误在哪里或者源代码有什么问题?

PS:是的,我配置了我的浏览器以启用第二个 post 中 link 中提到的请求。 PPS:当我删除我们的第一个过滤器并通过 waffle 过滤器路由所有内容时,登录有效并且我没有收到 NullPointerException,但应用程序已完全损坏。

好吧,所以我继续挖掘,经过一夜的睡眠,我想尝试一些新的东西。

因为我遇到的问题是已经有一个自定义的 securityFilter 阻止 waffle 正确执行(即使过滤器与调度程序等一起跳转)。 我的眼睛捕捉到一些有趣的东西。

Waffle 设置了一个名为 "WWW-Authenticate" 的页眉,所以为什么不朝那个方向尝试一下。几个小时后,我开始工作了。我正在执行我自己的 NTLM 握手并从令牌中读出我需要的内容。 get username from NTLM auth header helped my quite a lot in understanding how to perform my own NTLM handshake. Basically I customized the source code found there with the help of this masterpeace NTLM Authentication Scheme for HTTP。现在,在了解令牌和包的构建方式后,我深入研究并强制我的服务器请求此身份验证,然后在获得 NTLM V3 令牌后,读取我需要登录用户的内容。

有了这个解决方案,我可以保持我的结构。只有一个过滤器,没有 wildfly 定制,只有纯网络应用程序逻辑才能使其正常工作。

重要的是,我仍然需要将浏览器配置为信任我浏览的网站,这样我就不会收到要求凭据的弹出窗口。可以在此处找到 Waffle Doc but I had to add network.negotiate-auth.trusted-uris for firefox and then add the domain (ex: http://localhost) 以使弹出窗口消失。

只是想如果有人对周围环境有类似的问题,我会分享这个。