как создать новую запись в файле ldif (Embeded LDAP) с помощью весенней загрузки - PullRequest
0 голосов
/ 22 октября 2019

Я пытаюсь вставить информацию о пользователе в мой файл LDIF, который идеально настроен с помощью весенней загрузки, потому что я могу получать данные, даже если я могу использовать метод LdapTemplate.bind ().

Я пыталсяразличные коды и, наконец, я могу использовать метод ldapTemplate.bind (), но он связывает мою запись только с деревом LDAP, что означает отсутствие записи в файле ldif, и при перезапуске сервера LDAP эта запись теряется.

Ошибка:

org.springframework.ldap.InvalidNameException: Invalid name: abcdtestuser@gmail.com; nested exception is javax.naming.InvalidNameException: Invalid name: abcdtestuser@gmail.com
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:136)
    at org.springframework.ldap.support.LdapUtils.newLdapName(LdapUtils.java:416)
    at org.springframework.ldap.support.LdapNameBuilder.add(LdapNameBuilder.java:121)
    at in.indg.cdac.ldap.service.LdapService.saveInLdap(LdapService.java:71)
    at in.indg.cdac.ldap.service.LdapService.create(LdapService.java:57)
    at in.indg.cdac.ldap.controller.LdapController.saveUserDetail(LdapController.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

Сущность:

@Entry(base="ou=vikaspedia", objectClasses = {"inetOrgPerson", "person", "top"})
public class User {

    @Id
    private Name id;
    private @Attribute(name = "mail") String uid;
    private @Attribute(name = "cn") String firstName;
    private @Attribute(name = "sn") String lastName;
    private @Attribute(name = "userPassword") String password;
    private @Attribute(name = "description") String userrole;

Метод создания:

    public String create(UserResponsePojo userResponsePojo) {
        try {
            Name dn = LdapNameBuilder
                      .newInstance()
                      .add("ou", "vikaspedia")
                      .add("mail", userResponsePojo.getUid())
//                    .add("cn", userResponsePojo.getUsername())
                      .build();
                    DirContextAdapter context = new DirContextAdapter(dn);

//                  Name id = LdapNameBuilder
//                          .newInstance()
//                          .add(userResponsePojo.getUid())
//                          .build();

                    context.setAttributeValues("objectclass", new String[]{"inetOrgPerson", "person", "top"});
                    context.setAttributeValue("cn", userResponsePojo.getUsername());
                    context.setAttributeValue("sn", userResponsePojo.getLastname());
                    context.setAttributeValue("description", userResponsePojo.getUserrole());
                    context.setAttributeValue("mail", userResponsePojo.getUid());
                    context.setAttributeValue("userPassword", digestSHA(userResponsePojo.getPassword()));

                    ldapTemplate.bind(context);
                    ldapTemplate.create(context);

Возможно, автоматическое увеличение идентификатора может решить проблему, но я не знаю, какмогу ли я достичь этого, как мы делаем с JPA @GeneratedValue (стратегии = GeneratedType.IDENTITY)

Любая помощь будет оценена. Заранее спасибо!

...