Вход в OpenLdap с использованием SpringSecurity не работает - PullRequest
0 голосов
/ 28 февраля 2019

У меня работает сервер LDAP.Я пытаюсь подключиться к серверу, используя Java Classes / Spring Classes

С Java Classes

public static void main(String[] args) {

        Hashtable env = new Hashtable(11);
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:389");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "cn=admin,dc=ecodenetworks,dc=com");
        env.put(Context.SECURITY_CREDENTIALS, "123");

        try {
            // Create initial context
            DirContext ctx = new InitialDirContext(env);

            System.out.println("Login Success");

            ctx.close();
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }

Работает

СВесенние классы

@Configuration
@EnableWebSecurity(debug = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        System.out.println("============Setting URL===========");
        http.authorizeRequests().anyRequest().fullyAuthenticated().and()
                .formLogin();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.ldapAuthentication()
                .userDnPatterns("cn=admin,dc=ecodenetworks,dc=com")
                .contextSource().url("ldap://localhost:389").and()
                .passwordCompare().passwordAttribute("123");

    }

Там написано Неверные полномочия .Не уверен, что не так.

Мое дерево LDAP при просмотре в phpLDAP

+--> dc=ecodenetworks,dc=com (1)
  +--> cn=admin (1)
  | ---> cn=ashish
  | ---> Create new entry here
  ---> Create new entry here
...