繁体   English   中英

使用Weblogic LDAP身份验证器配置Spring Security

[英]Configure Spring Security with Weblogic LDAP authenticator

我试图使用在Oracle Weblogic Server 10.3中配置的LDAP身份验证器在我的应用程序中设置Spring Security。

我一直在互联网上进行搜索,但是我发现的只是如何将LDAP直接设置到spring-security.xml中,但是与以某种方式将服务器上的配置导入到其中无关,因此当我尝试登录时- ,它将使用服务器上的身份验证器检查用户和密码。

我想这样做是因为我无法访问LDAP的配置(它在生产环境中),因此我必须直接将数据发送给它。

有什么办法可以做到这一点?

您需要创建一个自定义AuthenticationHandler并在Spring Security配置中对其进行声明,或者您可以编写自己的UserDetailsS​​ervice来为您执行LDAP查询。

<authentication-manager>
    <authentication-provider user-service-ref="jbossLdapController" >
       <password-encoder hash="sha" base64="true" ref="passwordEncoder">
          <salt-source ref="saltSource"/>
       </password-encoder>
    </authentication-provider>
</authentication-manager>

这样,您可以创建一个实现UserDetailsService的类,以获取此功能的所有功能,而不必使用典型的自定义身份验证处理程序手动实现所有功能。

public class JBossLdapController implements UserDetailsService {
      ReflectionSaltSource saltSource;
      public void setSaltSource(ReflectionSaltSource saltSource) {
         this.saltSource = saltSource;
      }

      ShaPasswordEncoder passwordEncoder;
      public void setPasswordEncoder(ShaPasswordEncoder passwordEncoder) {
         this.passwordEncoder = passwordEncoder;
      }

      // LDAP stuff

      @Override
      public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
         // Build user details, call LDAP query.  User details functionality of Spring will automatically compare user supplied credentials with hash and salt source versus username and encrypted password in UserDetails object.
      }

请记住,这只是在不放弃Spring Security UserDetails功能优势的情况下如何完成此操作的示例。 当然,在不了解您的LDAP提供程序的情况下,密码可能无法使用SHA进行SHA加密。

暂无
暂无

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

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