如何解决春季测试我无法在ldap中使用posixAccount objectClass,因为在架构中已禁用它的使用
我在测试中使用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
解决方法
我只是重写类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,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。