서버는 openldap으로 설치하고 클라이언트는 netscape의 java api를 이용해서 인증서를 삽입하려고 합니다.
string 타입의 attribute를 삽입하는 데는 성공했으나, 인증서와 같은 binary 타입의 attribute를 삽입하는 방법은 모르겠습니다.
objectclass에 strongUserAuthentication을 추가하고
attrs.add( new LDAPAttribute( "userCertificate;binary", *** ) );를 추가하면 될 거 같은데, 파일의 위치를 나타내는 ***을 어떻게 나타내야 할 지 모르겠습니다.
import netscape.ldap.*;
import java.util.*;
public class Add {
public static void main( String[] args )
{
/* Specify the DN we're adding */
String dn = "cn=Bill Jensen, o=mycom, c=KR";
/* Specify the attributes of the entry */
String objectclass_values[] = { "top",
"person" };
String cn_values[] = { "William B Jensen",
"Bill Jensen" };
String sn_values[] = { "Jensen" };
LDAPAttributeSet attrs = new LDAPAttributeSet();
LDAPAttribute attr = new LDAPAttribute( "objectClass" );
for( int i = 0; i < objectclass_values.length; i++ ) {
attr.addValue( objectclass_values );
}
attrs.add( attr );
attr = new LDAPAttribute( "cn" );
for( int i = 0; i < cn_values.length; i++ ) {
attr.addValue( cn_values );
}
attrs.add( attr );
attr = new LDAPAttribute( "sn" );
for( int i = 0; i < sn_values.length; i++ ) {
attr.addValue( sn_values );
}
attrs.add( attr );
/* Create an entry with this DN and these attributes */
LDAPEntry myEntry = new LDAPEntry( dn, attrs );
LDAPConnection ld = null;
int status = -1;
try {
ld = new LDAPConnection();
/* Connect to server */
String MY_HOST = "localhost";
int MY_PORT = 389;
ld.connect( MY_HOST, MY_PORT );
/* Authenticate to the server as directory manager */
String MGR_DN = "cn=Manager,o=mycom,c=KR";
String MGR_PW = "ldap";
ld.authenticate( MGR_DN, MGR_PW );
/* Now add the entry to the directory */
ld.add( myEntry );
System.out.println( "Entry added" );
}
catch( LDAPException e ) {
if ( e.getLDAPResultCode() == LDAPException.ENTRY_ALREADY_EXISTS )
System.out.println( "Error: Entry already present" );
else {
System.out.println( "Error: " + e.toString() );
}
}
/* Done, so disconnect */
if ( (ld != null) && ld.isConnected() ) {
try {
ld.disconnect();
} catch ( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
}
System.exit(status);
}
|