3

I want to test LDAP with Spring using a LDIF file.

I don't use xml.

I achieve to read from LDIF file all the basic attributes.

How I can add some custom attributes?

So far I used this syntax

dn: cn=name,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
cn: name
sn: name
uid: name
mail: name@gmail.com
givenName: name
userPassword: namespassword
changetype: modify
add: telephonenumber
telephonenumber: 555-2468

...but It can not read the file, because it doesn't recognize the "changeType" attribute.

EDIT QUESTION

I have this file:

dn: dc=springframework,dc=org
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: springframework

dn: ou=groups,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: groups

dn: ou=subgroups,ou=groups,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: subgroups

dn: ou=people,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: people

dn: ou=space cadets,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: space cadets

dn: ou=\"quoted people\",dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: "quoted people"

dn: ou=otherpeople,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: otherpeople

dn: uid=ben,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Ben Alex
sn: Alex
uid: ben
userPassword: {SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=

dn: uid=bob,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Bob Hamilton
sn: Hamilton
uid: bob
userPassword: bobspassword

dn: uid=joe,ou=otherpeople,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Joe Smeth
sn: Smeth
uid: joe
userPassword: joespassword

dn: cn=mouse\, jerry,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Mouse, Jerry
sn: Mouse
uid: jerry
userPassword: jerryspassword

dn: cn=slash/guy,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: slash/guy
sn: Slash
uid: slashguy
mail: slash@gmail.com
givenName: Slash Snakepit
userPassword: slashguyspassword
msExchUserAccountControl: 0

dn: cn=quote\"guy,ou=\"quoted people\",dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: quote\"guy
sn: Quote
uid: quoteguy
userPassword: quoteguyspassword

dn: uid=space cadet,ou=space cadets,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Space Cadet
sn: Cadet
uid: space cadet
userPassword: spacecadetspassword

dn: cn=developers,ou=groups,dc=springframework,dc=org
objectclass: top
objectclass: groupOfUniqueNames
cn: developers
ou: developer
uniqueMember: uid=ben,ou=people,dc=springframework,dc=org
uniqueMember: uid=bob,ou=people,dc=springframework,dc=org

dn: cn=managers,ou=groups,dc=springframework,dc=org
objectclass: top
objectclass: groupOfUniqueNames
cn: managers
ou: manager
uniqueMember: uid=ben,ou=people,dc=springframework,dc=org
uniqueMember: cn=mouse\, jerry,ou=people,dc=springframework,dc=org

dn: cn=submanagers,ou=subgroups,ou=groups,dc=springframework,dc=org
objectclass: top
objectclass: groupOfUniqueNames
cn: submanagers
ou: submanager
uniqueMember: uid=ben,ou=people,dc=springframework,dc=org

And I have this exception:

Caused by: com.unboundid.ldap.sdk.LDAPException: Unable to add entry 'cn=slash/guy,ou=people,dc=springframework,dc=org' because it violates the provided schema: The entry contains attribute msExchUserAccountControl which is not defined in the schema.

How can I add that attribute?

pacio14
  • 351
  • 1
  • 8
  • 18
  • Are you trying to use LDIF to modify an existing LDAP entry, or do you actually have an attribute called "changetype" you're trying to set when creating a new LDAP entry via LDIF? – ChadSikorra Apr 03 '17 at 20:29
  • I'm trying to create the same LDAP structure that I have, but this LDIF file is a new file that I use only for the JUNIT tests. I have the need to add other attributes, which are custom attributes. – pacio14 Apr 04 '17 at 07:21
  • I aim to add some custom attributes to an LDAP entry, and I thought "changetype" was the way... If there is another way to add them, tell me, please. – pacio14 Apr 04 '17 at 08:16
  • 1
    "changetype" is a special LDIF directive when used in an entry. If you leave it out then the action is assumed to be an "add". If you're looking to do a LDIF modify of an existing LDAP entry then the "changetype" of modify is correct, but the format is completely different from what you're using. Also, typically the "changetype" statement comes at the top right below the "dn:" (Though I'm not sure this matters, would depend on the parser). See: https://www.centos.org/docs/5/html/CDS/ag/8.0/Creating_Directory_Entries-LDIF_Update_Statements.html – ChadSikorra Apr 04 '17 at 13:59
  • I updated the question to be more clear (hopefully). Thanks a lot – pacio14 Apr 04 '17 at 15:54
  • The attribute it is throwing an error on is part of the Microsoft Exchange schema (gets added to AD when installing Microsoft Exchange server). Are you running this against AD or OpenLDAP? You may be able to just omit that attribute from that entry depending on your testing needs. – ChadSikorra Apr 04 '17 at 17:24
  • I'm using this LDIF file for testing LDAP behavior in Junit tests in a Java Application with Spring (without xml configuration). I would like to simulate the real microsoft LDAP with the same structure and, a part the rest, only this attribute is not possible to duplicate in test, but for my application it is necessary, so i have to add it and check it. – pacio14 Apr 05 '17 at 07:00

1 Answers1

6

try to add this property to your application.properties

spring.ldap.embedded.validation.enabled=false

you can alternativly define your schema with "spring.ldap.embedded.validation.schema" property as describe here

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-ldap-embedded

Al1
  • 76
  • 1
  • 4