前言:本周次要对gitlabWebhook转github的我的项目扫了开头,并没有遇到什么问题,所以就上周LDAP中的疑难进行了进一步的理解。
承接上文中的问题:@Id和@DnAttributeID之间是什么关系。为什么在ldapAdmin中没有找到@ID对应的字段。
@Data@Entry(base = "", objectClasses="inetOrgPerson")public class Person { /** * 此字段不能少 */ @Id private Name id; @DnAttribute(value = "uid", index = 3) private String uid; @DnAttribute(value = "title", index = 4) private String title; @Attribute(name = "cn") private String commonName; @Attribute(name = "sn") private String myUerName; private String userPassword;}
就拿下面这个实体来说,咱们能够用如下办法查问它外部的属性:
List<Person> list = ldapTemplate.search("", filter, new AttributesMapper() { @SneakyThrows @Override public Object mapFromAttributes(Attributes attributes) throws NamingException { NamingEnumeration<? extends Attribute> att = attributes.getAll(); while (att.hasMore()) { Attribute a = att.next(); System.out.println(a.getID() + "=" + a.get()); }}
然而构造中并没有打印出id这一项,然而如果没有这一项在发明实体时会报如下谬误。
报的很间接,就是短少ID,那么咱们就要去ldapTemplate.creat函数外面去打点,看看报错是怎么来的。
测试后发现报错呈现在这里:
那么咱们再把ID属性增加完再来看这里。
因为咱们生成ID时没有给ID赋值,他会主动生成ID,而他主动生成的ID就是由咱们在试题中申明的 @DnAttribute 注解来的,依据所给的优先级进行排序生成。
就相似于@ID是由@DnAttribute对立形成的联结主键,只不过因为LDAP是树形存储,主键之间须要有优先程序之分,来区别那一项是哪一项的下级节点。
那么他的存储模式是什么呢?
拿上面的实体来举例:
@Test public void addPerson() { Person person = new Person(); person.setUid("uid:17"); person.setTitle("13131000001"); person.setMyUerName("liMing"); person.setCommonName("liming"); person.setUserPassword("123456"); ldapTemplate.create(person); }
他在库中的存储模式如下,因为UID的优先级要比title高,所以在父实体中。
那么咱们如果不给@DnAttribute属性赋初值呢?
就会报如下谬误:
总结来说的话就是@Id是为了结构该实体的DN而存在的,LDAP中Dn的结构是源于咱们一开始对根底dn的配置以及存储实体的@Id字段。
也就是说这一部分是依据@ID字段生成的
那么天经地义@DnAttribute注解字段也就不能随便更改了,如果依照之前的一般属性批改办法:
@Test public void update(){ String oldPersonDn = "uid=uid:17"; Person newPerson = new Person(); newPerson.setUid("uid=uid:29"); ldapTemplate.modifyAttributes(oldPersonDn, new ModificationItem[] { new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("uid", newPerson.getUid().trim())), }); }
会报如下谬误:
[LDAP: error code 64 - value of naming attribute 'uid' is not present in entry]
也就是说@DnAttribute注解后,LDAP并没有把它当做一般属性。
如果咱们要批改DN的话(当然个别状况下不应批改dn)能够应用如下办法批改:
ldapTemplate.rename(oldPersonDn, newPersonDn);
遇到的其余小问题:
在初始化前台时呈现了这样的报错:
Error creating bean with name 'entityManagerFactory' defined in class path resource [...]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service. . . . . .Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service
去网上查阅之后根本都是说是配置文件没有配置齐全。
上面是我的配置文件(application.properties):
server.port=8088dingTalkUrlPre=https://oapi.dingtalk.com/robot/sendspring.datasource.driver-class-name= com.mysql.cj.jdbc.Driverspring.datasource.url="jdbc:mysql://localhost:3310/setting?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai"spring.datasource.username=rootspring.datasource.password=rootspring.jpa.generate-ddl=truespring.jpa.show-sql=truespring.jpa.properties.hibernate.dialect="org.hibernate.dialect.MySQL57Dialect"spring.jpa.hibernate.ddl-auto=updatespring.jpa.database=mysql
并没有发现有哪些项没有配置齐全,之后才发现是因为spring.jpa.properties.hibernate.dialect
和另一个配置项前面的参数用引号括起来了,在application.yml中是否增加引号并不影响辨认,然而在application.properties
中却不行,之前并没有关注过这些,导致了这个谬误。