vt-middleware / ldaptive

A simple, extensible Java API for interacting with LDAP servers
56 stars 26 forks source link

Referrals DefaultLdapEntryManager add not working when error=10 #269

Closed sysmat closed 2 months ago

sysmat commented 2 months ago
this.manager().add(user);
dfish3r commented 2 months ago

What version are you using?

sysmat commented 2 months ago

1.2.4 I'm still on java 8(customer cannot move to higher java)

dfish3r commented 2 months ago

Can you post a code snippet so I can see the usage? (If you're using DefaultLdapEntryManager, I'm pretty sure that component doesn't support referrals.)

sysmat commented 2 months ago
....
public void build(ConfigIntf configApi) {
        final Map<String, Object> props = new HashMap<>();
        props.put(INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        props.put(PROVIDER_URL, configApi.getLdapUrl());
        props.put(SECURITY_AUTHENTICATION, "simple");
        props.put(SECURITY_PRINCIPAL, configApi.getLdapUser());
        props.put(SECURITY_CREDENTIALS, configApi.getLdapPass());
        // ldap cluster has readonly & write nodes so we need this for write operations to work
        props.put(REFERRAL, "follow");
        props.put("java.naming.ldap.referral.limit", "3");

        // https://www.ldaptive.org/v1/
        ConnectionConfig connConfig = new ConnectionConfig(configApi.getLdapUrl());

        // connConfig.setUseStartTLS(true); if we whant to start TLS but we use ldaps already
        this.ldapFactory = new DefaultConnectionFactory(connConfig);
        this.ldapFactory.getProvider().getProviderConfig().setProperties(props);
        this.ldapConn = ldapFactory.getConnection();
    }

public DefaultLdapEntryManager<UserLdap> getManager() {
        DefaultLdapEntryMapper<UserLdap> mapper = new DefaultLdapEntryMapper<>();
        return new DefaultLdapEntryManager<>(mapper, this.ldapFactory);
}

....

...
try {
            this.connBuildr.getManager()
                           .add(user);
        } catch (LdapException e ){ }
dfish3r commented 2 months ago

I haven't been able to reproduce this yet. Based on your configuration, JNDI should handle the referral transparently. To be clear, are you seeing a success result code or referral result code at the client but no entry added in the server?

sysmat commented 2 months ago

@dfish3r thx