Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 将JAAS用于具有Spring安全性的LDAP密码_Authentication_Spring Security_Ldap_Websphere_Jaas - Fatal编程技术网

Authentication 将JAAS用于具有Spring安全性的LDAP密码

Authentication 将JAAS用于具有Spring安全性的LDAP密码,authentication,spring-security,ldap,websphere,jaas,Authentication,Spring Security,Ldap,Websphere,Jaas,我有一个JavaEEWeb应用程序,它使用LDAP身份验证。我使用Spring security通过以下代码连接到LDAP: <bean id="ldapContextSource" class="com.myapp.security.authentication.MySecurityContextSource"> <constructor-arg index="0" value="${ldap.url}" /> <constructor-arg i

我有一个JavaEEWeb应用程序,它使用LDAP身份验证。我使用Spring security通过以下代码连接到LDAP:

<bean id="ldapContextSource" class="com.myapp.security.authentication.MySecurityContextSource">
    <constructor-arg index="0" value="${ldap.url}" />
    <constructor-arg index="1" ref="userConnexion" />
</bean>

<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="ldapAuthProvider" />
</security:authentication-manager>

<bean id="userConnexion" class="com.myapp.util.security.WebsphereCredentials">
    <constructor-arg value="${ldap.authJndiAlias}" />
</bean>

<bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
        <bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
            <constructor-arg ref="ldapContextSource" />
            <property name="userSearch" ref="userSearch" />
        </bean>
    </constructor-arg>
    <constructor-arg>
        <bean class="com.myapp.security.authentication.MyAuthoritiesPopulator" >
            <property name="userService" ref="userService" />
        </bean>
    </constructor-arg>
    <property name="userDetailsContextMapper" ref="myUserDetailsContextMapper"/>
    <property name="hideUserNotFoundExceptions" value="false" />
</bean>
有没有办法只使用Spring安全性并删除此依赖项

我不知道如何组合和


也许我必须完全改变我的方法并使用另一种方法?

我假设您的目标是简单地使用您在WebSphere中配置的用户名/密码来连接LDAP目录?如果是这种情况,那么您并不是在真正尝试结合LDAP和基于JAAS的身份验证。JAAS支持实际上是一种使用JAAS
LoginModule
s对用户进行身份验证的方法,而不是使用基于LDAP的身份验证

如果您希望获得用户名和密码而不需要对WebSphere具有编译时依赖性,那么您有几个选项

消除WAS上的编译时和运行时依赖关系 一个选项是以不同的方式配置密码。这可能非常简单,只需在配置文件中直接使用密码,如所示:

然后,您的配置将如下所示:

try {
    LoginContext lc = new LoginContext("DefaultPrincipalMapping", this.callbackHandler);
    lc.login();
    subject = lc.getSubject();
} catch (NotImplementedException e) {
    throw new EfritTechnicalException(EfritTechnicalExceptionEnum.LOGIN_CREDENTIAL_PROBLEM, e);
} catch (LoginException e) {
    throw new EfritTechnicalException(EfritTechnicalExceptionEnum.LOGIN_CREDENTIAL_PROBLEM, e);
}

PasswordCredential cred = (PasswordCredential) subject.getPrivateCredentials().toArray()[0];

this.user = cred.getUserName();
this.password = String.valueOf(cred.getPassword());
<bean id="userConnexion" class="com.myapp.util.security.WebsphereCredentials">
    <constructor-arg ref="wasCallbackHandler"/>
</bean>

<bean id="wasCallbackHandler"
      factory-bean="wasCallbackFactory"
      factory-method="getCallbackHandler">
    <constructor-arg>
      <map>
        <entry
            value="${ldap.authJndiAlias}">
          <key>
            <util:constant static-field="com.ibm.wsspi.security.auth.callback.Constants.MAPPING_ALIAS"/>
          </key>
        </entry>
      </map>
    </constructor-arg>
    <constructor-arg>
      <null />
    </constructor-arg>
</bean>

<bean id="wasCallbackFactory"
    class="com.ibm.wsspi.security.auth.callback.WSMappingCallbackHandlerFactory"
    factory-method="getInstance" />

免责声明
CallbackHandler
实例不是线程安全的,通常不应使用多次。因此,将
CallbackHandler
实例作为成员变量注入可能有点风险。您可能希望在检查中编程,以确保
CallbackHandler
仅使用一次

混合方法
您可以使用一种混合方法,始终删除编译时依赖项,并允许您在可能未在WebSphere上运行的实例中删除运行时依赖项。这可以通过结合这两个建议并使用来区分在WebSphere和非WebSphere机器上运行。

>庞大的IBM客户端库com.IBM.ws.admin.client-7.0.0.jar(42 Mo)=>编译速度较慢-虽然我理解需要避免如此大的jar,但通常使用它们不会减慢编译速度。Java不重新编译JAR。它们是链接的,但不是编译的。是的,你是对的。我很快就把它写下来了……我这么说是因为当我完成编译时,我会复制我的JAR用于部署。但是这个JAR是由应用服务器提供的,我已经在maven pom文件中将它标记为提供;o) 谢谢你的回复!事实上,是的,我想删除配置文件中的密码。我向我的部署团队提供配置文件,但我不知道生产密码,这就是为什么我不能拥有密码。适用于本地和开发环境。根据我的环境,我已经使用了Jasypt和spring profil。我喜欢在spring配置中定义依赖项的想法。对不起,没有。我已经建议我的部署团队将密码存储在JNDI中,但他们不想要它;o(.非常感谢您的回复。小改动,我删除了bean userConnexion中的第一个factory方法=“getCallbackHandler”。其余的都没问题,再次感谢您的帮助。我更新了帖子以反映您提到的小改动。
try {
    LoginContext lc = new LoginContext("DefaultPrincipalMapping", this.callbackHandler);
    lc.login();
    subject = lc.getSubject();
} catch (NotImplementedException e) {
    throw new EfritTechnicalException(EfritTechnicalExceptionEnum.LOGIN_CREDENTIAL_PROBLEM, e);
} catch (LoginException e) {
    throw new EfritTechnicalException(EfritTechnicalExceptionEnum.LOGIN_CREDENTIAL_PROBLEM, e);
}

PasswordCredential cred = (PasswordCredential) subject.getPrivateCredentials().toArray()[0];

this.user = cred.getUserName();
this.password = String.valueOf(cred.getPassword());
<bean id="userConnexion" class="com.myapp.util.security.WebsphereCredentials">
    <constructor-arg ref="wasCallbackHandler"/>
</bean>

<bean id="wasCallbackHandler"
      factory-bean="wasCallbackFactory"
      factory-method="getCallbackHandler">
    <constructor-arg>
      <map>
        <entry
            value="${ldap.authJndiAlias}">
          <key>
            <util:constant static-field="com.ibm.wsspi.security.auth.callback.Constants.MAPPING_ALIAS"/>
          </key>
        </entry>
      </map>
    </constructor-arg>
    <constructor-arg>
      <null />
    </constructor-arg>
</bean>

<bean id="wasCallbackFactory"
    class="com.ibm.wsspi.security.auth.callback.WSMappingCallbackHandlerFactory"
    factory-method="getInstance" />