Apache Directory Server Guide
Uwiki
1. Apache DS 설치
1.1 필요 조건
● Java 5.0: 썬 JDK를 사용할 것을 권고, JRockit 5.0, IBM Java 5.0에서도 잘 동작함
● JVM을 위해 최소 348MB RAM 필요
1.2 다운로드1.
● url: http://www.apache.org/dyn/closer.cgi/directory/ 에서 apacheds-1.5.4.zip 다운로드
1.3 설치방법
● zip 파일을 PC에서 압축을 풀고, ftp를 이용 업로드
2. Apache DS 실행
● 아래 명령어로 자바가 path에 존재하는지 확인
[user]# which java
● apacheds.sh의 로그 설정 부분을 보면,
-Dlog4j.configuration=file:conf/log4j.properties
위와 같이 설정되어 있고, 다시 conf/log4j.properties를 살펴 보면,
log4j.appender.R.File=${apacheds.log.dir}/apacheds-rolling.log
위와 같이 되어 있으므로, apacheds.log.dir가 설정되어 있지 않으면, 최초 실행시 로그 파일을 생성하지 못하는 에러가 뜸. 따라서, 로그파일을 쓰기 권한이 있는 파일로 재설정해주어야 함
[user]# ./apacheds.sh &
유닉스 머신 재부팅 시 따로 실행 명령을 하지 않으려면, 데몬에 설정해서 자동 실행되게끔 설정하여야 함
3. Spring LDAP 사용법
●“Spring LDAP - Reference Documentation 1.3.0.RELEASE” 문서 참조
● 개념
JDBC가 DB서버를 대상으로 한 API라고 한다면, Spring LDAP은 LDAP서버를 대상으로 하고 있음. 즉, 개념적으로 상응하는 요소가 있으므로, 그것을 이해하는 것이 전체적인 개념을 잡는데 도움이 됨 Using JDBC, we would create a connection and execute a query using a statement. We would then loop over the result set and retrieve the column we want, adding it to a list. In contrast, using Java LDAP, we would create a context and perform a search using a search filter. We would then loop over the resulting naming enumeration and retrieve the attribute we want, adding it to a list.
해석: JDBC 사용시, connection을 생성하고, statement를 사용하여 query를 실행한다. 그런 다음 result set을 루프 돌면서 원하는 column을 찾아내 리스트에 추가한다. LDAP의 경우는, context를 생성하고, search filter를 사룡하여 search를 수행한다. 그런 다음 결과로 받는 naming enumeration을 루프 돌면서 원하는 attribute를 찾아내 리스트에 추가한다.
● Context 생성
ApplicationContext factory =
new ClassPathXmlApplicationContext("com/nongshim/ldap/springldap.xml");
4. springldap.xml 내용
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> <!-- Default settings for the Apache Directory Server 1.5.1 --> <property name="url" value="ldap://172.25.1.191:10389" /> <!-- <property name="base" value="ou=people,o=nongshim" /> --> <property name="userDn" value="uid=admin,ou=system" /> <property name="password" value="secret" /> </bean> <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"> <constructor-arg ref="contextSource" /> </bean> <bean id="personDao" class="com.nongshim.ldap.dao.PersonDaoImpl"> <property name="ldapTemplate" ref="ldapTemplate" /> </bean> <bean id="orgDao" class="com.nongshim.ldap.dao.OrgDaoImpl"> <property name="ldapTemplate" ref="ldapTemplate" /> </bean> </beans>
5. LDAP 서버에 엔트리 추가하기
JAVA LDAP에서 데이터를 생성하는 것을 binding이라고 부름
PersonDaoImpl.java
/*
* @see PersonDao#create(Person)
*/
public void create(LdapGwPersonSelect person) {
Name dn = buildDn(person);
DirContextAdapter context = new DirContextAdapter(dn);
mapToContext(person, context);
ldapTemplate.bind(dn, context, null);
}
private DistinguishedName buildDn(LdapGwPersonSelect person) {
return buildDn(person.getUid());
}
private DistinguishedName buildDn(String uid) {
DistinguishedName dn = new DistinguishedName("ou=people.mj,o=nongshim");
dn.add("uid", uid);
return dn;
}
private void mapToContext(LdapGwPersonSelect person,
DirContextAdapter context) {
context.setAttributeValues("objectclass", new String[] { "top", "person", "organizationalPerson", "inetOrgPerson" });
context.setAttributeValue("cn", person.getCommonName());
context.setAttributeValue("sn", person.getCommonName());
context.setAttributeValue("mail", person.getEmail());
context.setAttributeValue("mobile", person.getMobile());
context.setAttributeValue("uid", person.getUid());
context.setAttributeValue("userpassword",
person.getPassword());
}

