首頁>Program>source

我在測試中使用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"物件類儲存實體時,会發生錯誤,因為在cn = nis,ou = schema中未將" m-disabled"引數設置為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
最新回復
  • 7月前
    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();
    

    為了啟用posixAccount,將必需的屬性m禁用為FALSE,

  • c++:使用std :: less <>將unique_ptr与原始指標进行比较無法編譯,但可以使用包裝器吗?
  • Steam API 2020