简体   繁体   English

Wildfly 10 Windows身份验证

[英]Wildfly 10 Windows authentication

I got stuck on servlet's and security filter for a java web application. 我陷入了Java Web应用程序的servlet和安全过滤器的困境。 so I got my web.xml which looks like this: 所以我得到了如下所示的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>

I got this setup because I stumbled across this little post: Multiple filters with same url mapping 我得到这个设置是因为我偶然发现了这个小帖子: 具有相同网址映射的多个过滤器

and then I found this post which helped me to get in the correct direction: java-sso-with-wildfly-8-java-1-8-0-45-and-active-directory 然后我发现了这篇文章,这有助于我朝正确的方向发展: java-sso-with-wildfly-8-java-1-8-0-45-and-active-directory

so I try to access this part right here throug the filter WaffleSSOFilter. 因此,我尝试通过过滤器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;
  }

The difficult part on this for me is that the first filter "com.company.xxx.xxx.xxx.SecurityFilter" is needed on every URL, because our application is broken without it and nothing works then. 对我而言,这方面的困难之处在于,每个URL都需要第一个过滤器“ com.company.xxx.xxx.xxx.SecurityFilter”,因为没有它,我们的应用程序将被破坏,然后将无法使用。 but I need a special POST URL for my WaffleSSOFilter to enable the ability to authenticate over the logged in windows user on the remote machine accessing the website. 但是我需要为WaffleSSOFilter提供一个特殊的POST URL,以便能够通过访问网站的远程计算机上的已登录Windows用户进行身份验证。

The goal is to have the login page with the normal username and password form and have a checkbox to enable the windows authentication. 目的是使登录页面具有正常的用户名和密码格式,并具有一个复选框以启用Windows身份验证。

With this setup I can login normally with username and password. 通过此设置,我可以使用用户名和密码正常登录。 the application is working, which is good so far. 该应用程序正在运行,到目前为止还不错。 Now, if I make a POST request to my special URL to test the windows authentication, I get a java.lang.NullPointerException on the previous source code excactly at accessing servletRequest.getUserPrincipal().toString() 现在,如果我对自己的特殊URL发出POST请求以测试Windows身份验证,则在访问servletRequest.getUserPrincipal().toString() ,在上一个源代码上将得到一个java.lang.NullPointerException servletRequest.getUserPrincipal().toString()

Question: Where is my error in the filter setup or what is wrong with the source code? 问题:我的过滤器设置错误在哪里,或者源代码有什么问题?

PS: Yes I configured my browsers to enable the request as mentioned in the link on the second post. PS:是的,我将浏览器配置为启用请求,如第二篇文章中的链接所述。 PPS: When I remove our first filter and route everything through the waffle filter the login works and I don't get a NullPointerException, the application is completely broken though. PPS:当我删除第一个过滤器并通过华夫过滤器路由所有内容时,登录有效,但没有收到NullPointerException,但应用程序已完全损坏。

Alright so I kept diging and after a night of sleep I thought about trying something new. 好吧,所以我一直在吃东西,经过一夜的睡眠,我想到了尝试一些新事物。

Since I got the problem of already having a custom securityFilter that blocks waffle to perform correctly (even with filter jumping with dispatcher etc). 因为我遇到了已经存在一个自定义securityFilter的问题,该自定义securityFilter会阻止华夫饼干正确执行(即使使用调度程序跳跃过滤器等)。 My eyes caught something interesting. 我的眼睛发现了一些有趣的东西。

Waffle set a Header with the name "WWW-Authenticate", so why not try around in that direction. 华夫饼设置的标题为“ WWW-Authenticate”,所以为什么不尝试该方向。 after a couple of hours I got it working. 几个小时后,我开始工作了。 I am performing my own NTLM handshake and read out what I need from the token. 我正在执行自己的NTLM握手,并从令牌中读出所需的内容。 get username from NTLM auth header helped my quite a lot in understanding how to perform my own NTLM handshake. 从NTLM身份验证标头获取用户名有助于我在很大程度上了解如何执行自己的NTLM握手。 Basically I customized the source code found there with the help of this masterpeace NTLM Authentication Scheme for HTTP . 基本上,我借助用于HTTP的 masterpeace NTLM身份验证方案自定义了在那里找到的源代码。 Now after seeing how the tokens and packages are built I digged into it and forced my server to requesting this authentication and then after getting the NTLM V3 token, reading out what I need to log in the user. 现在,在了解了令牌和程序包的构建方式之后,我深入其中,并强迫我的服务器请求此身份验证,然后在获取NTLM V3令牌之后,读出我需要登录用户的内容。

With this solution I can keep my structure. 使用此解决方案,我可以保持自己的结构。 Only one filter, no wildfly customization but just pure web app logic to get it working. 只有一个过滤器,没有Wildfly定制,只有纯Web应用程序逻辑才能使它工作。

What is important, is that I still need to configurate the browsers to trust the website I browse, so I don't get the popup asking for credentials. 重要的是,我仍然需要配置浏览器以信任我浏览的网站,因此我不会看到弹出窗口要求提供凭据。 This can be found here Waffle Doc but I had to add network.negotiate-auth.trusted-uris for firefox and then add the domain (ex: http://localhost ) to get the popup to dissapear. 可以在此处找到Waffle Doc,但是我必须为firefox添加network.negotiate-auth.trusted-uris ,然后添加域(例如: http:// localhost )以使弹出窗口消失。

Just thought I would share this if somebody has a similar problem with that sorrounding. 只是想如果有人对此问题有类似的问题,我将与您分享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM