와우 리눅스 7.1 에 openldap을 설치하고 데이타를 저장했습니다.
./libexec/slapd ldap://203.238.197.250:389 etc/openldep/slapd.conf
데몬을 실행했습니다.
그리고 , 데이터는 아래와 같이 저정했으면, search 검색이 가능합니다.
-x 로 검색했습니다. 자바로 search 프로그램을 짜서 프로그램세계10월 참조...
이런 에러가 발생합니다.
어디가 잘못된 것인지를 잘 모르겠습니다...
javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials
]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.connect(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at javax.naming.directory.InitialDirContext.<init>(Unknown Source)
at JNDISearch.main(JNDISearch.java:25)
-------------------------------------------------------
dn:dc=posdata,dc=com
dc:posdata
objectclass:dcobject
dn:o=organization,dc=posdata,dc=com
o :organization
objectclass:organization
dn:cn=park,o=organization,dc=posdata,dc=com
cn:park
sn:woong
userPassword:mypass
telephoneNumber:967-2221
description:i studing openLDAP
objectclass:person
dn:cn=Hong,o=organization,dc=posdata,dc=com
cn:Hong
sn:Haeng suk
userPassword:mypass1
telephoneNumber:967-1354
description:What do you do
objectclass:person
-------------------------------------------------------------------source 코드
import java.util.Enumeration;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
class JNDISearch
{
public static void main(String[] args)
{
String returnedAttributes[] = {"cn" , "sn", "userPasswd", "telephoneNumber"};
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"ldap://203.238.197.250:389/cn=park,o=organization,dc=posdata,dc=com");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=manager");
env.put(Context.SECURITY_CREDENTIALS,"asdf");
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
constraints.setReturningAttributes(returnedAttributes);
try{
DirContext context = new InitialDirContext(env);
NamingEnumeration searchResults = context.search( args[0],"(cn = park)",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());
}//end while
}//end if
else if(attribute.size() > 0)
{
System.out.println(attributeID + " : " + attribute.get());
}//end else if
else
{
System.out.println("애트리뷰트에 값이 없습니다");
}//end else
}//end while
}//end else
System.out.println();
}//end while
}//end try
catch(NamingException e)
{
System.out.println("애브리뷰트 테스트가 실패했습니다");
e.printStackTrace();
}//end catch
catch(Error e){
System.err.println("에러 다.................");
e.printStackTrace();
}
finally{
System.exit(0);
}
}//end main
}//end JNDISearch
|