You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "St Clair S. Clarke" <st...@flowja.com> on 2010/05/27 16:27:53 UTC
Adding a baseDN with GroovyLdap
Hello,
I am attempting to add a baseDN using ApacheDS and Eclipse, but have
been failing miserable.
Below is the attempt. I would love it if you could help.
package snippets.security.ldap.groovyldap.add
import org.apache.directory.groovyldap.LDAP
class AddEntryDemo
{
static main( args)
{
def ldap = LDAP.newInstance('ldap://localhost:10389', 'uid=admin, ou=system' ,'secret')
// add the baseDN as a valid name entry
def baseDNAttrs = [ objectclass: ['top', 'ou'], sn: 'dc=epims dc=biz', cn: 'epims' ]
ldap.add( 'ou: epims dc=epims dc=biz', baseDNAttrs)
assert ! ldap.exists('cn=Heather Nova, dc=epims, dc=biz') // checks for previous entry with this dn
// define the attributes as a map
def attrs = [ objectclass: ['top', 'person'], sn: 'Nova', cn: 'Heather Nova' ]
ldap.add( 'cn=Heather Nova, dc=epims, dc=biz', attrs)
assert ldap.exists('cn=Heather Nova, dc=epims, dc=com')
}
}
---------------------------------------------------------
Dr. St Clair S. Clarke (M.B.B.S; D.M. (General Surgery) )
Head, General Surgery Department
Spanish Town General Hospital
Burk Road,
Spanish Town
St Catherine
Jamaica
Phone:(876) 984-3030/5
Phone:(876) 984-4670/2
Phone:(876) 749-2213 (Direct)
Fax:(876) 749-2213
Mobile: (876) 303-6177
Email: st_clair@flowja.com
Skype: st.clair.clarke
Re: Adding a baseDN with GroovyLdap
Posted by Stefan Zoerner <st...@labeo.de>.
St Clair S. Clarke wrote:
> I am attempting to add a baseDN using ApacheDS and Eclipse, but have
> been failing miserable.
I assume that you have an ApacheDS up and running, and are able to
connect from Groovy LDAP, i.e.
def ldap = LDAP.newInstance('ldap://localhost:10389', 'uid=admin,
ou=system' ,'secret')
works without an error.
As far as I understand your requirement, you plan to add a suffix,
"dc=epims, dc=com", and an entry below that.
Apache Directory Server comes with a default suffix "dc=example,dc=com"
for demonstration purposes, which maps to a partition (a data store)
within the configuration.
You therefore have to add a partition for your "dc=epims, dc=com". It is
not quite common to accomplish this administration task programmatically
(exception: an emedded server).
See details here
http://directory.apache.org/apacheds/1.5/143-adding-your-own-partition-resp-suffix.html
Please note that this line
def baseDNAttrs = [ objectclass: ['top', 'ou'], sn: 'dc=epims dc=biz',
cn: 'epims' ]
does not make sense, because sn is an attribute type reprsesenting the
surname of a person.
Hope this helps,
StefanZ
> Below is the attempt. I would love it if you could help.
>
>
> package snippets.security.ldap.groovyldap.add
>
> import org.apache.directory.groovyldap.LDAP
>
> class AddEntryDemo
> {
>
> static main( args)
> {
> def ldap = LDAP.newInstance('ldap://localhost:10389', 'uid=admin, ou=system' ,'secret')
>
> // add the baseDN as a valid name entry
> def baseDNAttrs = [ objectclass: ['top', 'ou'], sn: 'dc=epims dc=biz', cn: 'epims' ]
> ldap.add( 'ou: epims dc=epims dc=biz', baseDNAttrs)
>
> assert ! ldap.exists('cn=Heather Nova, dc=epims, dc=biz') // checks for previous entry with this dn
>
>
>
>
> // define the attributes as a map
> def attrs = [ objectclass: ['top', 'person'], sn: 'Nova', cn: 'Heather Nova' ]
>
> ldap.add( 'cn=Heather Nova, dc=epims, dc=biz', attrs)
>
> assert ldap.exists('cn=Heather Nova, dc=epims, dc=com')
>
> }
>
>
> }
>
>
>
>
>
>
>
>
> ---------------------------------------------------------
> Dr. St Clair S. Clarke (M.B.B.S; D.M. (General Surgery) )
> Head, General Surgery Department
> Spanish Town General Hospital
> Burk Road,
> Spanish Town
> St Catherine
> Jamaica
>
> Phone:(876) 984-3030/5
> Phone:(876) 984-4670/2
> Phone:(876) 749-2213 (Direct)
> Fax:(876) 749-2213
>
> Mobile: (876) 303-6177
> Email: st_clair@flowja.com
> Skype: st.clair.clarke
>
>
>