简体   繁体   English

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

[英]Configure Spring Security with Weblogic LDAP authenticator

I'm trying to set up Spring Security in my application using a LDAP authenticator configured in an Oracle Weblogic Server 10.3. 我试图使用在Oracle Weblogic Server 10.3中配置的LDAP身份验证器在我的应用程序中设置Spring Security。

I've been searching on the internet, but all I find is how to set the LDAP right into the spring-security.xml, but nothing about somehow importing the configuration I have on the server into it, so when I try to log-in, it checks the user and password with the authenticator on the server. 我一直在互联网上进行搜索,但是我发现的只是如何将LDAP直接设置到spring-security.xml中,但是与以某种方式将服务器上的配置导入到其中无关,因此当我尝试登录时- ,它将使用服务器上的身份验证器检查用户和密码。

I want to do so because I don't have access to the configuration of the LDAP (it's on a production environment), so I have to send the data directly to it. 我想这样做是因为我无法访问LDAP的配置(它在生产环境中),因此我必须直接将数据发送给它。

Is there any way to accomplish this? 有什么办法可以做到这一点?

You need to create a custom AuthenticationHandler and declare it in your Spring Security configuration or you can write your own UserDetailsService that performs the LDAP query for you. 您需要创建一个自定义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>

With this you can create a class that implements UserDetailsService to get all the functionality of this without having to implement it all by hand using a typical custom authentication handler. 这样,您可以创建一个实现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.
      }

Keep in mind that this is just an example of how this can be done without giving up the benefits of the Spring Security UserDetails functionality. 请记住,这只是在不放弃Spring Security UserDetails功能优势的情况下如何完成此操作的示例。 Of course, without knowing more about your LDAP provider, the passwords may not be SHA encrypted with a salt. 当然,在不了解您的LDAP提供程序的情况下,密码可能无法使用SHA进行SHA加密。

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

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