ConverterNotFoundException при попытке доступа к данным LDAP - PullRequest
0 голосов
/ 09 мая 2018

Я пытаюсь получить данные с сервера LDAP. До сих пор мне удалось подключиться к серверу и получить список всех записей. Но когда я пытаюсь получить одну запись, я получаю следующую ошибку

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [javax.naming.Name]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.data.repository.support.ReflectionRepositoryInvoker.convertId(ReflectionRepositoryInvoker.java:289) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.data.repository.support.CrudRepositoryInvoker.invokeFindById(CrudRepositoryInvoker.java:92) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory$UnwrappingRepositoryInvoker.lambda$invokeFindById$2(UnwrappingRepositoryInvokerFactory.java:95) ~[spring-data-rest-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na]
...

У меня настроена конфигурация LDAP как таковая

@Configuration
@EnableLdapRepositories(basePackages = "com.sayak.repository.ldap")
public class LdapConfig {
    @Value("${ldap.urls}")
    private String ldapUrls;

    @Value("${ldap.base.dn}")
    private String ldapBaseDn;

    @Value("${ldap.username}")
    private String ldapSecurityPrincipal;

    @Value("${ldap.password}")
    private String ldapPrincipalPassword;

    @Bean
    ContextSource contextSource() {
        LdapContextSource ldapContextSource = new LdapContextSource();
        ldapContextSource.setUrl(ldapUrls);
        ldapContextSource.setBase(ldapBaseDn);
        ldapContextSource.setUserDn(ldapSecurityPrincipal);
        ldapContextSource.setPassword(ldapPrincipalPassword);
        return ldapContextSource;
    }

    @Bean
    LdapTemplate ldapTemplate(ContextSource contextSource) {
        return new LdapTemplate(contextSource);
    }
}

Запись для данных LDAP:

@Entry(objectClasses = {"inetOrgPerson", "organizationalPerson", "person", "top"})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class LdapUser {
    @Id
    private Name distinguishedName;

    @Attribute(name = "cn")
    private String commonName;

    @Attribute(name = "sn")
    private String surname;

    @Attribute(name = "givenName")
    private String givenName;

    @Attribute(name = "ou")
    private String organisationalUnit;

    @Attribute(name = "uid")
    private String userId;

    @Attribute(name = "mail")
    private String email;

    public LdapUser(LdapUser other) {
        this.distinguishedName = other.distinguishedName;
        this.commonName = other.commonName;
        this.surname = other.surname;
        this.givenName = other.givenName;
        this.organisationalUnit = other.organisationalUnit;
        this.userId = other.userId;
        this.email = other.email;
    }
}

И мой репозиторий настроен как

@Repository
public interface LdapUserRepository extends LdapRepository<LdapUser> {
    LdapUser findByCommonName(String commonName);
    List<LdapUser> findByCommonNameContainingIgnoreCase(String commonName);
}

Когда я делаю GET-запрос на /ldapUsers, я получаю действительный ответ, такой как

{
    "_embedded": {
        "ldapUsers": [
            {
                "commonName": "Katherine Ito",
                "surname": "Ito",
                "givenName": "Katherine",
                "organisationalUnit": "Peons",
                "userId": "ItoK",
                "email": "ItoK@ns-mail3.com",
                "_links": {
                    "self": {
                        "href": "http://localhost:6332/api/v1/ldapUsers/cn=Katherine%20Ito,ou=Peons"
                    },
                    "ldapUser": {
                        "href": "http://localhost:6332/api/v1/ldapUsers/cn=Katherine%20Ito,ou=Peons"
                    }
                }
            },
            ...
        ]
    },
    "_links": {
        "self": {
            "href": "http://localhost:6332/api/v1/ldapUsers"
        },
        "profile": {
            "href": "http://localhost:6332/api/v1/profile/ldapUsers"
        },
        "search": {
            "href": "http://localhost:6332/api/v1/ldapUsers/search"
        }
    }
}

Но когда я делаю GET-запрос к /ldapUsers/cn=Katherine%20Ito,ou=Peons (как видно из self.href в первом ответе, он выдает ошибку.

Я знаю о существовании ConversionServiceConverterManager.StringToNameConverter, но по какой-то причине он, похоже, не срабатывает. Есть указатели?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...