2013-02-13 6 views
3

Spring을 사용하여 ActiveDirectory 레코드를 LDIF 형식의 파일로 내보내려고합니다.LdapAttributes를 얻는 방법

에 대해 많은 정보를 찾고 있는데, LDIF 파일을 파싱하고 있지만 LDIF로 내보내는 것에 대해서는 상대적으로 적습니다. 봄에는 LdapAttributes 클래스의 toString() 메서드가 LDIF 형식의 문자열을 반환하지만 처음에는 LdapAttributes 인스턴스를 가져올 위치가 표시되지 않습니다. LdapTemplate에 아무것도 표시되지 않습니다.

이 프레임 워크는 LdapAttributes 개체를 직접 작성하지 않고이 작업을 수행하는 간단한 방법을 제공합니다.

답변

0

흠, 나는이 함께했다 :

import javax.naming.NamingEnumeration; 
import javax.naming.NamingException; 
import javax.naming.directory.Attribute; 
import javax.naming.directory.Attributes;  
import org.springframework.ldap.core.AttributesMapper; 
import org.springframework.ldap.core.DistinguishedName; 
import org.springframework.ldap.core.LdapAttributes; 

public class PersonMapper implements AttributesMapper { 

    @Override 
    public Object mapFromAttributes(Attributes attrs) throws NamingException { 
     String dnValue = (String) attrs.get("distinguishedName").get(); 
     DistinguishedName dn = new DistinguishedName(dnValue); 
     LdapAttributes ldapAttrs = new LdapAttributes(dn); 
     for (NamingEnumeration<? extends Attribute> ne = attrs.getAll(); ne.hasMore();) { 
      ldapAttrs.put(ne.next()); 
     } 
     return ldapAttrs; 
    } 
} 

내가 도울 수 없지만이 일을 좀 더 아웃 - 오브 - 박스 방법이 있어야한다고 생각 위의 작품 불구하고. unboundid LDAP의 SDK 같은

0
LdapAttributes ldapAttributes = basic2LdapAttributes(result.getNameInNamespace(), result.getAttributes()); 

public static LdapAttributes basic2LdapAttributes(String distinguishedName, Attributes attributes) throws NamingException{ 
     LdapAttributes ldapAttributes = new LdapAttributes(); 
     ldapAttributes.setName(LdapUtils.newLdapName(distinguishedName)); 
     for (NamingEnumeration<? extends Attribute> nameEnumeration = attributes.getAll(); nameEnumeration.hasMore();) { 
      ldapAttributes.put(nameEnumeration.next()); 
     } 
     return ldapAttributes; 
}