为什么Kerberos / SPNEGO身份验证不起作用?

时间:2019-06-18 09:49:03

标签: java tomcat vaadin kerberos spnego

我正在使用Vaadin框架开发Java Web应用程序。我想在不提示用户名和密码的情况下对用户进行身份验证。为此,我想实现Kerberos / SPNEGO来将东西注入我的Java代码中。 我需要做的就是让用户的域用户名连接到webApplication

我遵循了网站上的指示:https://tomcat.apache.org/tomcat-9.0-doc/windows-auth-howto.html

然后我在这里做了所有描述:http://spnego.sourceforge.net/troubleshoot_hellokeytab.html

现在我有正在工作的HelloKDC,它返回了我:

Postdated Ticket false
Renewable Ticket false
Initial Ticket false
Auth Time = Tue Jun 18 11:25:22 CEST 2019
Start Time = Tue Jun 18 11:25:22 CEST 2019
End Time = Tue Jun 18 21:25:22 CEST 2019
Renew Till = null
Client Addresses  Null 
Private Credential: C:\tomcat.keytab for 
HTTP/myserver.eu.corp.mycompany.net@EU.CORP.MYCOMPANY.NET
Connection test successful.

密钥表是使用以下命令生成的:

ktpass -out c:\tomcat.keytab /princ 
HTTP/myserver.eu.corp.mycompany.net@EU.CORP.MYCOMPANY.NET /pass myPass! 
/mapuser serviceUser /crypto AES256-SHA1 /ptype KRB5_NT_PRINCIPAL

请记住,该应用程序服务器位于myserver。 EU .CORP.MYCOMPANY.NET中,而用户来自CORP.MYCOMPANY.NET域。

protected void init(VaadinRequest request) {  
    System.out.println("5 " + request.getRemoteUser());
}

返回null。

Tomcat web.xml:

<filter>
<filter-name>SpnegoHttpFilter</filter-name>
<filter-class>net.sourceforge.spnego.SpnegoHttpFilter</filter-class>

<init-param>
    <param-name>spnego.allow.basic</param-name>
    <param-value>false</param-value>
</init-param>

<init-param>
    <param-name>spnego.allow.localhost</param-name>
    <param-value>true</param-value>
</init-param>

<init-param>
    <param-name>spnego.allow.unsecure.basic</param-name>
    <param-value>false</param-value>
</init-param>

<init-param>
    <param-name>spnego.login.client.module</param-name>
    <param-value>spnego-client</param-value>
</init-param>

<init-param>
    <param-name>spnego.krb5.conf</param-name>
    <param-value>C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin\krb5.conf</param-value>
</init-param>

<init-param>
    <param-name>spnego.login.conf</param-name>
    <param-value>C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\login.conf</param-value>
</init-param>

<init-param>
    <param-name>spnego.preauth.username</param-name>
    <param-value></param-value>
</init-param>

<init-param>
    <param-name>spnego.preauth.password</param-name>
    <param-value></param-value>
</init-param>

<init-param>
    <param-name>spnego.login.server.module</param-name>
    <param-value>spnego-server</param-value>
</init-param>

<init-param>
    <param-name>spnego.prompt.ntlm</param-name>
    <param-value>false</param-value>
</init-param>

<init-param>
    <param-name>spnego.logger.level</param-name>
    <param-value>1</param-value>
</init-param>
</filter>
   <filter-mapping>
   <filter-name>SpnegoHttpFilter</filter-name>
   <url-pattern>*.jsp</url-pattern>
</filter-mapping>

krb5.conf:

[libdefaults]
default_realm = EU.CORP.MYCOMPANY.NET
default_tkt_enctypes = aes256-cts aes256-cts-hmac-sha1-96 aes128-cts-    hmac-sha1-96 aes128-cts rc4-hmac des3-cbc-sha1 des-cbc-md5 des-cbc-crc arcfour-hmac arcfour-hmac-md5 
default_tgt_enctypes = aes256-cts aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 aes128-cts rc4-hmac des3-cbc-sha1 des-cbc-md5 des-cbc-crc arcfour-hmac arcfour-hmac-md5 
permitted_enctypes = aes256-cts aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 aes128-cts rc4-hmac des3-cbc-sha1 des-cbc-md5 des-cbc-crc arcfour-hmac arcfour-hmac-md5
forwardable=true
[realms]
EU.corp.mycompany.net = {
kdc = EUGBDC001.EU.CORP.MYCOMPANY.NET:88
default_domain = EU.CORP.MYCOMPANY.NET
}
[domain_realm]
eu.corp.mycompany.net= EU.CORP.MYCOMPANY.NET
.eu.corp.mycompany.net= EU.CORP.MYCOMPANY.NET

login.conf:

spnego-client {
com.sun.security.auth.module.Krb5LoginModule required;
};

spnego-server {
com.sun.security.auth.module.Krb5LoginModule required
storeKey=true
useKeyTab=true
keyTab="file:///C:/tomcat.keytab"
principal="HTTP/myserver.eu.corp.mycompany.net@EU.CORP.MYCOMPANY.NET";
};

似乎没有正确的身份验证。 我在做什么错了?

1 个答案:

答案 0 :(得分:0)

经过几天的寻找,我找到了解决方案。

似乎我的过滤器仅适用于* .jsp应用程序。我只是改变了:

<filter-mapping>
  <filter-name>SpnegoHttpFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>

针对:

<filter-mapping>
  <filter-name>SpnegoHttpFilter</filter-name>
  <url-pattern>*</url-pattern>
</filter-mapping>

这解决了我的问题,也许会帮助某人。