database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
ㆍLDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
LDAP Q&A 723 게시물 읽기
No. 723
아..더 쉬운 방법이 있었군요 ^^;
작성자
하만복
작성일
2001-06-20 19:36
조회수
7,642

더 쉬운 방법을 찾아서 다시 글 올립니다..

썬에서 제공하는 ldap service provider 1.2.2 를 설치하시면,

~/doc/providers/jndi-ldap.html 에 관련글이 나옵니다

attribute value 를 위한 형식으로 String 과 byte[] 를 지원한다고..

다만 주의할 것은 binary syntax 를 사용할 attributeType 을

다음과 같이 명시적으로 알려주어야 합니다

(binary 를 add 할때는 문제가 없지만 retrieve 할때는 처리해주지 않으면

ClassCastException 이 나더군요)

 

...

env.put("java.naming.ldap.attributes.binary", "file")

...

 

"file" 은 제가 미리만들어 놓은 attributeType 입니다

(SYNTAX : binary)

 

제가 테스트한 소스를 첨부합니다..

(주석이 필요하시다면 허접한 주석이지만 달아서 자료실에 올려드리겠습니다 ^^)

=======================================================================

// 'file' attributeType 과 'fileContainer' object class 를 schema에 추가

import javax.naming.*;

import javax.naming.directory.*;

import java.util.*;

import com.javaholic.tools.PropertiesReader;

 

public class AddFileSchema

{

public static void main(String[] javaholic)

throws Exception

{

DirContext initCtx = new InitialDirContext(PropertiesReader.readFromFile("../widefool.properties"));

 

DirContext schema = initCtx.getSchema("");

DirContext attributeDef = (DirContext)schema.lookup("AttributeDefinition");

DirContext classDef = (DirContext)schema.lookup("ClassDefinition");

 

Attributes attrs = new BasicAttributes(true);

attrs.put("NUMERICOID", "file-oid");

attrs.put("NAME", "file");

attrs.put("DESC", "attribute for test");

attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.5");

attributeDef.createSubcontext("file", attrs);

 

attrs = new BasicAttributes(true);

attrs.put("NUMERICOID", "filecontainer-oid");

attrs.put("NAME", "fileContainer");

attrs.put("DESC", "object class for test");

attrs.put("SUP", "top");

attrs.put("STRUCTURAL", "true");

attrs.put("MUST", "cn");

attrs.put("MAY", "file");

classDef.createSubcontext("fileContainer", attrs);

}

}

 

 

==========================================================================

// source.gif 화일 저장

import javax.naming.*;

import javax.naming.directory.*;

import java.util.*;

import java.io.*;

import com.javaholic.tools.PropertiesReader;

 

public class AddFileTest

{

public static void main(String[] javaholic)

throws Exception

{

RandomAccessFile raf = new RandomAccessFile("./source.gif", "r");

byte[] b = new byte[(int)raf.length()];

raf.readFully(b);

 

Properties env = PropertiesReader.readFromFile("../widefool.properties");

//env.put("java.naming.ldap.attributes.binary", "file");

DirContext initCtx = new InitialDirContext(env);

 

Attributes attrs = new BasicAttributes(true);

attrs.put("objectClass", "fileContainer");

attrs.put("cn", "testfile");

attrs.put("file", b);

initCtx.createSubcontext("cn=testfile,o=widefool", attrs);

initCtx.close();

}

}

 

============================================================================

// cn=testfile,o=widefool 로 부터 화일을 받아옴

import javax.naming.*;

import javax.naming.directory.*;

import java.util.*;

import java.io.*;

import com.javaholic.tools.PropertiesReader;

 

public class GetFileTest

{

public static void main(String[] javaholic)

throws Exception

{

Properties env = PropertiesReader.readFromFile("../widefool.properties");

env.put("java.naming.ldap.attributes.binary", "file");

DirContext initCtx = new InitialDirContext(env);

 

Attribute attr = (initCtx.getAttributes("cn=testfile,o=widefool", new String[] {"file"})).get("file");

byte[] b = (byte[])attr.get();

initCtx.close();

 

FileOutputStream fo = new FileOutputStream("./copy.gif");

fo.write(b);

fo.close();

}

}

[Top]
No.
제목
작성자
작성일
조회
717jndi로 삭제할때 안되네요?
김병조
2001-06-19
6283
721┕>Re: jndi로 삭제할때 안되네요?
하만복
2001-06-20 10:59:11
6491
724 ┕>Re: Re: jndi로 삭제할때 안되네요?
이재신
2001-06-21 02:04:08
6720
716Berkeley DB 를 컴파일 하려는데여..
이수진
2001-06-19
5522
719┕>Re: Berkeley DB 를 컴파일 하려는데여..
정재익
2001-06-19 23:27:59
6245
714objectclass를 다중으로 설정하는데...
완전초보
2001-06-18
5522
752┕>Re: objectclass를 다중으로 설정하는데...
서호정
2001-07-02 21:16:15
6335
713JNDI로 바이너리 화일을 LDAP에 저장하는 방법??
허지환
2001-06-18
6727
722┕>Re: JNDI로 바이너리 화일을 LDAP에 저장하는 방법??
하만복
2001-06-20 11:14:19
7676
723┕>아..더 쉬운 방법이 있었군요 ^^;
하만복
2001-06-20 19:36:58
7642
726 ┕>성공했구여. 넘 고맙습니다.
허지환
2001-06-21 17:10:08
7566
712[제안] 한국인을 위한 objectClass 및 attributeType을 만드는건 어떨까요..
하만복
2001-06-18
6556
715┕>Re: 재미있겠군요. :-)
정재익
2001-06-18 19:56:00
7185
709LDAP 포럼 날짜 정해졌나요?
이윤원
2001-06-17
6981
697[초보질문]LDAP EntryADD 하는 소스인데 자꾸에러가.. 좀 봐주시면 감사하겠습니다.
신응섭
2001-06-15
7256
698┕>Re: [초보질문]LDAP EntryADD 하는 소스인데 자꾸에러가.. 좀 봐주시면 감사하겠습니다.
이윤원
2001-06-15 15:57:49
7537
700 ┕>Re: Re: 답변감사합니다.다시 해봐야죠..그리고 Pilot은 요..
신응섭
2001-06-15 16:41:08
7650
702┕>Re: [초보질문]LDAP EntryADD 하는 소스인데 자꾸에러가.. 좀 봐주시면 감사하겠습니다.
하만복
2001-06-15 17:29:05
7834
703┕>Re: [초보질문]LDAP EntryADD 하는 소스인데 자꾸에러가.. 좀 봐주시면 감사하겠습니다.
송상준
2001-06-15 21:57:48
7617
707┕>만드시려는 entry 가 person 이 확실하십니까?
하만복
2001-06-16 11:23:30
7894
710┕>Re: [초보질문]LDAP EntryADD 하는 소스인데 자꾸에러가.. 좀 봐주시면 감사하겠습니다.
권만희
2001-06-18 09:52:27
7716
711 ┕>inetOrgPerson 을 사용해도 되지만요..
하만복
2001-06-18 10:50:50
8058
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.020초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다