2016-10-31 3 views
0

私はこのLDAP設定を持っている:LDAP設定をSpring Securityの実現に変更するにはどうしたらいいですか?

Hashtable env = new Hashtable(); 

      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
      env.put(Context.PROVIDER_URL, "ldap://....."); 
      env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
      env.put(Context.SECURITY_PRINCIPAL, "login); 
      env.put(Context.SECURITY_CREDENTIALS, password); 

      // Create the initial context 
      DirContext ctx = new InitialDirContext(env); 
      boolean result = ctx != null; 

どのように私は春のセキュリティを実現するためのこの設定を変更できますか?

auth.ldapAuthentication()..... 

答えて

0

このサンプルコードはテンプレートとして使用できます。私の場合、LDAPプロバイダのURLはldap://localhost:1389/dc=example,dc=comであり、ユーザエントリのDNパターンはuid={0},ou=people,dc=example,dc=comです。つまり、uid属性がユーザー名として使用されます。

LdapContextSource ctxSrc = new LdapContextSource(); 
ctxSrc.setUrl("ldap://localhost:1389"); 
ctxSrc.setBase("dc=example,dc=com"); 
ctxSrc.setUserDn("login"); 
ctxSrc.setPassword("password"); 
ctxSrc.afterPropertiesSet(); 

auth 
    .ldapAuthentication() 
    .contextSource(ctxSrc) 
    .userSearchBase("ou=people") 
    .userSearchFilter("(uid={0})"); 
関連する問題