【问题标题】:Spring Tests. I cannot use posixAccount objectClass in ldap as its use is disabled in the schema春季测试。我不能在 ldap 中使用 posixAccount objectClass,因为它的使用在架构中被禁用
【发布时间】:2020-11-01 01:02:58
【问题描述】:

我在测试中使用 spring-ldap-test(2.3.3)。配置:

@TestConfiguration
@TestPropertySource("classpath:application.yml")
@EnableAutoConfiguration(exclude = {ConsulAutoConfiguration.class,
        AutoServiceRegistrationAutoConfiguration.class,
        ConsulServiceRegistryAutoConfiguration.class,
        ConsulCatalogWatchAutoConfiguration.class,
        ConsulAutoServiceRegistrationAutoConfiguration.class,
})
public class TestConfigurations {

@Autowired
private Environment env;
@Autowired
private ResourceLoader resourceLoader;



@Primary
@Bean
public TestContextSourceFactoryBean testContextSource() {
    TestContextSourceFactoryBean contextSource = new TestContextSourceFactoryBean();
    contextSource.setDefaultPartitionName(env.getRequiredProperty("ldap.partition"));
    contextSource.setDefaultPartitionSuffix(env.getRequiredProperty("ldap.partitionSuffix"));
    contextSource.setPrincipal(env.getRequiredProperty("ldap.principal"));
    contextSource.setPassword(env.getRequiredProperty("ldap.password"));
    contextSource.setLdifFile(resourceLoader.getResource(env.getRequiredProperty("ldap.ldiffile")));
    contextSource.setPort(Integer.parseInt(env.getRequiredProperty("ldap.port")));
    return contextSource;
}


@Bean
public LdapTemplate ldapTemplate() throws Exception {
    return new LdapTemplate((ContextSource) testContextSource().getObject());
}




}

这是 appication.yml 文件:

ldap:
  partitionSuffix: dc=example,dc=com
  partition: example
  principal: uid=admin,ou=system
  password: secret
  ldiffile: classpath:/test.ldif
  port: 18888
  url: ldap://localhost:18888

因此,当我尝试使用“posixAccount”对象类保存实体时,会发生错误,因为“m-disabled”参数在 cn = nis, ou = schema 中设置为 TRUE,这不是为我定义的,并且我无法通过 Spring 更改此设置。

如何动态改变它?(((

实体:

@Entry(objectClasses = {"inetOrgPerson","top","posixAccount"})
public final class Person {
...................................
}

错误,顺便说一句:

 objectClass posixaccount w/ OID 1.3.6.1.1.1.2.0 not registered!
Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 54 - LOOP_DETECT

【问题讨论】:

    标签: java spring testing ldap schema


    【解决方案1】:

    我只是重写类 TestContextSourceFactoryBean 并将这行写到 createInstance() 方法的末尾:

    Hashtable env = new Hashtable(2);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:" + port);
    DirContext ctx = new InitialDirContext(env);
    ctx.modifyAttributes("cn=nis,ou=schema", new ModificationItem[]{new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("m-disabled", "FALSE"))});
    ctx.close();
    

    将必要的属性 m-disabled 设置为 FALSE 以启用 posixAccount,

    【讨论】:

      猜你喜欢
      • 2016-04-28
      • 1970-01-01
      • 2021-08-22
      • 2023-03-28
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 1970-01-01
      相关资源
      最近更新 更多