openLDAP에 JNDI를 이용해 책에 있는 소스를 구현해 봤습니다.
Search만 하면 되는데 자꾸 에러나 나네요 고수님들 부탁 드립니다.
내용은 아래와 같습니다.
[root@mail servlet]# java JNDISearch ou=Manager,o=mail.cubetech.co.kr
애트리뷰트가 실패하였습니다.
javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; rema
ining name 'ou=Manager,o=mail.cubetech.co.kr'
자바소스
//package webmail;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.directory.*;
class JNDISearch {
public static void main(String[] args) {
String returnedAttributes[]=;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://211.222.124.20:389");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=Manager,dc=mail,dc=cubetech,dc=co,dc=kr");
env.put(Context.SECURITY_CREDENTIALS,"testpass");
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
constraints.setReturningAttributes(returnedAttributes);
try {
DirContext context = new InitialDirContext(env);
NamingEnumeration searchResults = context.search( args[0], "(uid=admin)", constraints);
while(searchResults.hasMore()) {
SearchResult nextResult = (SearchResult) searchResults.next();
System.out.println("이름: " +nextResult.getName());
Attributes attributeSet = nextResult.getAttributes();
System.out.println("이 애트리뷰트의 크기: "+attributeSet.size());
if (attributeSet.size() == 0) {
System.out.println("애트리뷰트 값이 없습니다.");
} else {
NamingEnumeration allAttributes = attributeSet.getAll();
while(allAttributes.hasMoreElements()) {
Attribute attribute = (Attribute)allAttributes.next();
String attributeID = attribute.getID();
if(attribute.size() > 1) {
Enumeration allValues = attribute.getAll();
while(allValues.hasMoreElements()) {
System.out.println(attributeID+":"+allValues.nextElement());
}
} else if (attribute.size() > 0)
System.out.println(attributeID+":"+attribute.get());
else
System.out.println("애트리뷰트 값이 없습니다.");
}
}
System.out.println();
}
}
catch(NamingException e)
{
System.err.println("애트리뷰트가 실패하였습니다.");
e.printStackTrace();
}
catch(Error e)
{
System.err.println("이 애트리뷰트는 JDK1.1을 지원하지 않습니다.");
e.printStackTrace();
}
finally
{
System.exit(0);
}
}
}
slapd.conf파일내용
# $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.8.8.7 2001/09/27 20:00:31 kur
t Exp $
#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include /usr/local/etc/openldap/schema/core.schema
# Define global ACLs to disable default read access.
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral ldap://root.openldap.org
pidfile /usr/local/var/slapd.pid
argsfile /usr/local/var/slapd.args
# Load dynamic backend modules:
# modulepath /usr/local/libexec/openldap
# moduleload back_ldap.la
# moduleload back_ldbm.la
# moduleload back_passwd.la
# moduleload back_shell.la
#
# Sample Access Control
# Allow read access of root DSE
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
#
#access to dn="" by * read
#access to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default is:
# Allow read by all
#
# rootdn can always write!
#######################################################################
# ldbm database definitions
#######################################################################
database ldbm
suffix "dc=mail,dc=cubetech,dc=co,dc=kr"
#suffix "o=My Organization Name,c=US"
rootdn "cn=Manager,dc=mail,dc=cubetech,dc=co,dc=kr"
#rootdn "cn=Manager,o=My Organization Name,c=US"
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw testpass
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd/tools. Mode 700 recommended.
#directory /usr/local/var/openldap-ldbm
directory /usr/local/db2
# Indices to maintain
index objectClass eq
최상위 엔트리 입력
[root@mail libexec]# ldapadd -x -D "cn=Manager,dc=mail,dc=cubetech,dc=co,dc=kr"
-W -h mail.cubetech.co.kr << EOF
> dn: dc=mail,dc=cubetech,dc=co,dc=kr
> dc: mail
> objectclass: dcobject
> EOF
Enter LDAP Password:
adding new entry "dc=mail,dc=cubetech,dc=co,dc=kr"
==> 입력은 성공했어요
그런데 자바로 파일을 찾아도 그렇고 .....명령을 쳐도 그렇게 왜안나오는지..
고수님들 제발 답변좀 .....부탁드립니다.
|