Can Spring LDAP User with Entry Annotation access outside objects
14:33 02 Mar 2026

I have a Java 17 and SpringBoot 3 application that has some legacy code. I've never work with a Spring LDAP User before, so I am trying to come up to speed on this and learn about it. With the SpringBoot application.properties, we have the correct properties set. We can create a Spring LDAP user, and we get search/find them by uid. This all works.

When we get the LdapUser, we have a legacy method, and this is part of the LDAP User:

@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })
public final class LdapUser {
    @Attribute // here

As I said we can search and get back an Ldapuser with no issues, there is a 'dn' and a 'cn' just fine. We have this legacy method as follows:

public Name getFullPathDn() throws LdapException {
    String userBase = System.getProperty("myapp.ldap.base");
    String envBaseDn = System.getProperty("myapp.ldap.env.base");

    if (userBase == null || envBaseDn == null) {
    throw new LdapException("invalid myapp.ldap.base or myapp.ldap.env.base");
    }

In the old application, I don't know why they did this. It runs on WildFly, and we have a standalone.xml which has a variety of properties which System.getProperty works just fine. However, in the new app I am working on, this will NOT work. We do not want environment variables like this. In our new SpringBoot app, we have an application.properties file that has two properties that are what we want. However, how the heck do we get access to that. I have tried adding @Value for these fields, which does NOT work. Because @Value only works on Component, or Service, and not @Entry. So, we don't get the fields and these are null.

I create a Util file, that uses the @Value and that utils file can get access to the files just fine.

@Component
public class LdapUtils {

    @Value("${myapp.ldap.base}")
    private String userBase;
    
    @Value("${myapp.ldap.env.base}")
    private String envBaseDn;
    
    @Value("${myapp.ldap.cn.index}")
    private String cnIndex;

    public String getUserBase() {
        return userBase;
    }

    public String getEnvBaseDn() {
        return envBaseDn;
    }

    public String getCnIndex() {
        return cnIndex;
    }

}

I thought if I inject this into the LdapUser class, it would work, but it does not.

@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })
public final class LdapUser {

   @Autowired
   private com.myapp.ldap.LdapUtils ldapUtils;

   @Attribute // here

When I do this, I get a conversion error, it says that there needs to be a custom converter for ldapUtils because it thinks it is an @Attribute of which it is not. So, that's two ways I am trying to get values from application.properties, and neither are working.

So, I think the easiest thing to do is change my LdapRepository to add the @Values there. Then when I run the code to add/remove a group, I can pass in the values from there.

So, at the top of my LdapRepository, I have the values, and then I'll pass in the values to the other method:

@Value("${myapp.ldap.base}")
private String userBase;
    
@Value("${myapp.ldap.env.base}")
private String envBaseDn;

distinguishedName = ldapUser.getFullPathDn(userBase, envBaseDn);

I think this will work, but I'd still like to know how to get values into the LdapUser class.

spring-boot spring-ldap