001package com.nimbusds.common.ldap; 002 003 004import com.unboundid.ldap.sdk.LDAPConnection; 005import com.unboundid.ldap.sdk.LDAPException; 006import com.unboundid.ldap.sdk.schema.ObjectClassDefinition; 007import com.unboundid.ldap.sdk.schema.Schema; 008 009 010/** 011 * LDAP schema utilities. 012 */ 013public class SchemaUtils { 014 015 016 /** 017 * Returns the schema definition for the specified object class, in the 018 * format described in RFC 4512 section 4.1.1. 019 * 020 * @param ldapCon The LDAP connection. Must not be {@code null}. 021 * @param objectClass The object class. Must not be {@code null}. 022 * 023 * @return The object class definition, or an error message if an 024 * exception is encountered. 025 */ 026 public static String dumpObjectClassDefinition(final LDAPConnection ldapCon, 027 final String objectClass) { 028 029 Schema schema; 030 031 try { 032 schema = ldapCon.getSchema(); 033 034 } catch (LDAPException e) { 035 036 return e.getMessage(); 037 } 038 039 if (schema == null) { 040 return "LDAP schema not available (check permissions)"; 041 } 042 043 ObjectClassDefinition objClassDef = schema.getObjectClass(objectClass); 044 045 if (objClassDef == null) { 046 return "No such objectClass: " + objectClass; 047 } 048 049 return objClassDef.toString(); 050 } 051 052 053 /** 054 * Prevents public instantiation. 055 */ 056 private SchemaUtils() { 057 058 } 059}