import com.novell.ldap.*;
import java.util.*;
import java.io.UnsupportedEncodingException;
public class GetAttributeSchema {
public static void main( String[] args ) {
if (args.length != 4) {
System.err.println("Usage: java GetAttributeSchema <host name>" +
" <login dn> <password> <entry dn>");
System.err.println("Example: java GetAttributeSchema Acme.com"
+ " \"cn=admin,o=Acme\" secret \"cn=john,o=Acme\"");
System.exit(1);
}
int ldapPort = LDAPConnection.DEFAULT_PORT;
int ldapVersion = LDAPConnection.LDAP_V3;
int searchScope = LDAPConnection.SCOPE_BASE;
String ldapHost = args[0];
String loginDN = args[1];
String password = args[2];
String entryDN = args[3];
String searchFilter = "Objectclass=*";
LDAPConnection lc = new LDAPConnection();
LDAPSchema dirSchema=null;
try {
lc.connect( ldapHost, ldapPort );
lc.bind( ldapVersion, loginDN, password.getBytes("UTF8") );
try {
dirSchema=lc.fetchSchema(lc.getSchemaDN());
} catch( LDAPException e) {
e.printStackTrace();
}
LDAPSearchResults searchResults =
lc.search( entryDN,
searchScope,
searchFilter,
null,
false);
LDAPEntry Entry = null;
try {
Entry = searchResults.next();
}catch(LDAPException e) {
System.out.println("Error: " + e.toString());
}
LDAPAttributeSet attributeSet = Entry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
while(allAttributes.hasNext()) {
LDAPAttribute attribute =
(LDAPAttribute)allAttributes.next();
String attributeName = attribute.getName();
System.out.println(" "
+ attributeName
+ " "
+ dirSchema.getAttributeSchema(attributeName).toString());
System.out.println("\n");
}
}
catch( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
catch( UnsupportedEncodingException e ) {
System.out.println( "Error: " + e.toString() );
}
System.exit(0);
}
}