Java 在Spring中读取JAAS身份验证提供程序的配置文件时出错
这件事真是让我毛骨悚然。我为我的SpringWebApp配置了JAAS身份验证提供程序。我为它创建了一个bean定义,如下所示:Java 在Spring中读取JAAS身份验证提供程序的配置文件时出错,java,spring,jaas,Java,Spring,Jaas,这件事真是让我毛骨悚然。我为我的SpringWebApp配置了JAAS身份验证提供程序。我为它创建了一个bean定义,如下所示: <beans:bean id="jaasAuthenticationProvider" class="org.springframework.security.providers.jaas.JaasAuthenticationProvider"> <custom-authentication-provider />
<beans:bean id="jaasAuthenticationProvider"
class="org.springframework.security.providers.jaas.JaasAuthenticationProvider">
<custom-authentication-provider />
<beans:property name="loginConfig" value="file:webapps/mywebapp/WEB-INF/login.conf"/>
<beans:property name="loginContextName" value="myWebapp"/>
<beans:property name="callbackHandlers">
<beans:list>
<beans:bean class="org.springframework.security.providers.jaas.JaasNameCallbackHandler"/>
<beans:bean class="org.springframework.security.providers.jaas.JaasPasswordCallbackHandler"/>
</beans:list>
</beans:property>
</beans:bean>
当Spring初始化时,它会正确地配置bean。但是,当我尝试登录到我的webapp时,出现以下错误:
DEBUG webapp.AuthenticationProcessingFilter - Authentication request failed: org.springframework.security.AuthenticationServiceException: I/O error while reading configuration file.; nested exception is javax.security.auth.login.LoginException: I/O error while reading configuration file.
我在Spring源代码的任何地方都找不到这个错误消息,错误消息本身也没有任何帮助。知道是什么原因导致了这种情况吗?将文件放在类路径上,而不是尝试从WEB-INF目录中读取它/webapps/myapp/WEB-INF/classes/login.conf-然后在Spring配置中将行更改为:
<beans:property name="loginConfig" value="classpath:login.conf"/>
我认为您没有遇到Spring错误,但是遇到文件系统/java错误,您不允许从WEB-INF目录中读取文件。将文件放在类路径上,而不是尝试从WEB-INF目录中读取/webapps/myapp/WEB-INF/classes/login.conf-然后在Spring配置中将行更改为:
<beans:property name="loginConfig" value="classpath:login.conf"/>
我认为您没有收到Spring错误,但是收到文件系统/java错误,您不允许从目录WEB-INF读取。找到了答案。JAAS实际上正确加载了配置文件,但我在本地JDK中缺少了一个krb5.conf文件。此文件必须位于:
$JAVA_HOME/lib/security
例如:
[libdefaults]
default_realm = DOMAIN.NET
dns_lookup_kdc = true
[domain_realm]
.domain.net = DOMAIN.NET
其中,domain.net是Kerberos域的名称,domain.net仅大写。找到了答案。JAAS实际上正确加载了配置文件,但我在本地JDK中缺少了一个krb5.conf文件。此文件必须位于:
$JAVA_HOME/lib/security
例如:
[libdefaults]
default_realm = DOMAIN.NET
dns_lookup_kdc = true
[domain_realm]
.domain.net = DOMAIN.NET
其中,domain.net是Kerberos域的名称,domain.net仅大写。谢谢您的回答。我做了改变,但看到了同样的行为。相同的错误消息。不过,我还是会把零钱留着,干净多了!谢谢你的回答。我做了改变,但看到了同样的行为。相同的错误消息。不过,我还是会把零钱留着,干净多了!