2017-07-25 16 views
1

で失敗私は、読ん更新およびLDAPでユーザーデータを作成するために、春データとLdapRepository APIを使用しようとしています。私は読むことと、正常に更新することができましたが、私は新しいレコードを挿入しようとするたびに私はこのエラーを取得する:春データLdapRepositoryで新しいユーザーを作成するLDAPエラーコード32

2017-07-25 17:31:01.966 ERROR 14404 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; 
nested exception is org.springframework.ldap.NameNotFoundException: 
[LDAP: error code 32 - The search base entry '[email protected],ou=people,ou=myou,dc=bar,dc=foo' does not exist]; 
nested exception is javax.naming.NameNotFoundException: 
[LDAP: error code 32 - The search base entry '[email protected],ou=people,ou=myou,dc=bar,dc=foo' does not exist]; remaining name '[email protected]'] 
with root cause 
javax.naming.NameNotFoundException: [LDAP: error code 32 - The search base entry '[email protected],ou=people,ou=myou,dc=bar,dc=foo' does not exist] 

私application.propertiesは次のとおりです。

user-api.ldap.contextSource.url=ldap://server.address.com:1389 
user-api.ldap.contextSource.userDn=cn=manager role 
user-api.ldap.contextSource.password=apasswordwashere 
user-api.ldap.contextSource.base=ou=people,ou=myou,dc=bar,dc=foo 

私のレポインタフェース、LdapUserRepository .javaファイル:

public interface LdapUserRepository extends LdapRepository<LdapUser>{ 

    LdapUser findByCn(String cn); 

    LdapUser findBySn(String sn); 

    LdapUser save(LdapUser ldapUser); 
} 

私は明示的に保存方法を公開するか否か同じ応答を取得します。

私の設定がLdapConfiguration.javaで行われます。

@Configuration 
@EnableLdapRepositories(basePackages = "foo.bar.userapi.dao.ldap", ldapTemplateRef="userLdapTemplate") 
public class LdapConfiguration { 

    @Autowired 
    Environment env; 

    @Bean 
    public LdapContextSource contextSource() { 
     LdapContextSource contextSource= new LdapContextSource(); 
     contextSource.setUrl(env.getRequiredProperty("user-api.ldap.contextSource.url")); 
     contextSource.setBase(env.getRequiredProperty("user-api.ldap.contextSource.base")); 
     contextSource.setUserDn(env.getRequiredProperty("user-api.ldap.contextSource.userDn")); 
     contextSource.setPassword(env.getRequiredProperty("user-api.ldap.contextSource.password")); 
     return contextSource; 
    } 

    @Bean(name="userLdapTemplate") 
    public LdapTemplate ldapTemplate() { 
     return new LdapTemplate(contextSource());  
    } 

} 

そして、私のテストルーチン:

public void test() { 
    LdapUser ldapUser = new LdapUser(); 

    ldapUser.setCn("198777777"); 
    ldapUser.setCountry("United States"); 
    ldapUser.setGivenName("Hepsibah"); 
    ldapUser.setIsActive("true"); 
    ldapUser.setSn("Testerson91"); 
    ldapUser.setStatus("active"); 
    ldapUser.setUid(LdapUtils.newLdapName("[email protected]")); 
    ldapUser.setUserModifyTimestamp("20160222145439Z"); 
    ldapUser.setUserPassword("Password-12345"); 
    ldapUser = ldapUserRepository.save(ldapUser); 
} 

ストレスに私はこのような何かを行うとするので、コンフィギュレーションは、挿入以外のすべてのために働きます、それは動作します:

public void test2() { 
      LdapUser ldapUser = ldapUserRepository.findBySn("Testerson"); 
      if (ldapUser != null) { 
       System.out.println(ldapUser.getUid().toString()); 
       System.out.println("result: " + ldapUser.toString()); 

       ldapUser.setSn("Testerson2"); 
       ldapUser.setUserPassword("Password-12345!"); 
       ldapUser = ldapUserRepository.save(ldapUser); 

       ldapUser = ldapUserRepository.findBySn("Testerson2"); 
       if (ldapUser != null) { 
         System.out.println("result: " + ldapUser.toString()); 
       } 
      } 
    } 

私は答えがLdap error code 32 while adding user to ldapしかし、私は明示的に保存操作中にdnを追加していません。更新操作はうまく動作します。

レコードを取得するときに、uid値を変更して保存すると、同じエラーが発生します。レコードを取得してuidを検査すると、 "uid = [email protected]"の部分だけが表示され、 "ou = people、ou = myou、dc = bar、dc = foo"の部分は表示されません。 SimpleLdapRepositoryが、それは「保存」または「更新すべきかどうかを判断しようとすると、問題が発生している - デフォルトの実装が使用されている(リポジトリインタフェースを自身で実装していない場合は、これを取得しますSimpleLdapRepository)を想定すると

+0

完璧だったアウトhttps://stackoverflow.com/questions/33288011/ldaprepository-update-spring-ldap P. – Philip

答えて

0

あなたの存在。 hereからSimpleLdapRepositoryでそのコードは次のようになります。

@Override 
public <S extends T> S More ...save(S entity) { 
    Assert.notNull(entity, "Entity must not be null"); 
    Name declaredId = odm.getId(entity); 

    if (isNew(entity, declaredId)) { 
     ldapOperations.create(entity); 
    } else { 
     ldapOperations.update(entity); 
    } 

    return entity; 
} 

は、あなたがそれを見ているエラーはおそらくあなたのエンティティは、このアップデートは実体があるときに失敗した実行され、新規であることが決定されていないです取得するには存在しないことが判明し、更新することができません。

isNew()方法は次のようになります。あなたの例では

 private <S extends T> boolean More ...isNew(S entity, Name id) { 
    if (entity instanceof Persistable) { 
     Persistable<?> persistable = (Persistable<?>) entity; 
     return persistable.isNew(); 
    } else { 
     return id == null; 
    } 
} 

あなたがIDを設定する必要があるように見えます。つまり、エンティティが新しいかどうかを返すためにPersistableインターフェイスとisNew()メソッドを実装することです。エンティティが新規であると判断された場合(保存する前にldapUser.setNew(true);などと電話できます)、更新されるのではなく保存されます。

+0

、ありがとう!保存するオブジェクトを変更しました: 'public final class LdapUser implements Persistable {...それは、LDAPテーブル:: '@Transient プライベートブールisNewのフィールドにそれと一致するようにしようとしなかったように、' は、それから私は、一時アノテーションで、ldapuserのクラス、isNewメンバーに、追加しました; '標準のセッターとあなたが提案された方法と一緒に : '@Override \t公共ブールisNew(){ \t \tリターンthis.isNew。 \t} ' それは、私がそのフィールドを真実に設定して保存したときに、そのトリックでした! – Endie

関連する問題