Beruflich Dokumente
Kultur Dokumente
environment in 5 minutes
June 13th, 2011 by Micha Kops
Eclipse IDE
You should at least install Apache Directory Studio Apache DS, Apache
Directory Studio LDAP Browser andApache Directory Studio LDIF
Editor here .. or just install everything .. it wont hurt ..
Open the server view by going: Menubar > Window > Show View > Other
> Apache DS > Servers
Rightclick in the server view and select New > New server
You should see your new created server in the server view
Start your LDAP server by rightclick and run .. after a short time the
servers status should have changed to started
If you take a look at the servers current configuration youll see that the
server is configured for the host name ldap.example.com
Just right-click on the server in the server view and select LDAP-Browser >
Create a connection and let the IDE switch to the LDAP Perspective
In the LDAP perspective theres the LDAP Browser, an outline for the
directory structure, the connection and server views and the directory
logs
Were going to import some data from an LDIF file .. just copy the
following content and save it to a file and open it in the perspectiv. It is
important that the last line in the LDIF file is an empty line/newline.
dn: dc=example,dc=com
objectClass: domain
objectClass: top
dc: example
dn: ou=Users,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
ou: Users
dn: ou=Groups,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
ou: Groups
dn: cn=Micha Kops,ou=Users,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: Micha Kops
sn: Kops
uid: mkops
userPassword:: abcdefg
dn: cn=Santa Claus,ou=Users,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: Santa Claus
sn: Claus
uid: sclaus
userPassword:: abcdefg
dn: cn=John Steinbeck,ou=Users,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: John Steinbeck
sn: Steinbeck
uid: jsteinbeck
userPassword:: abcdefg
Then click on Execute LDIF now weve got some more content in our
directory and you are able to see it in the Outline view
Now we want to query the directory for existing user using JNDI .. and our
program should output
Ive created a simple new Java project in Eclipse containing this one class
named LdapQuery
package com.hascode.tutorial.ldap;
import java.util.Hashtable;
import
import
import
import
import
import
import
import
javax.naming.Context;
javax.naming.NamingEnumeration;
javax.naming.NamingException;
javax.naming.directory.Attributes;
javax.naming.directory.DirContext;
javax.naming.directory.InitialDirContext;
javax.naming.directory.SearchControls;
javax.naming.directory.SearchResult;
}
}
}
Run the class and you should see the following output
2.
<ATG10dir>/DAS/LDAP/lib
3.
Error Message
InitialContextEnvironment
Property to Modify
providerURL
javax.naming.CommunicationException: <h
Error Message
InitialContextEnvironment
Property to Modify
ost:port>.
Root exception
is java.net.NoRouteToHostException:
Operation timed out: no further information
securityAuthentication
javax.naming.AuthenticationNotSupported
Exception:
SASL support not available:<value>
javax.naming.AuthenticationException:
[LDAP: error code 49 - Invalid Credentials]