2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Netscape's 3.1 servers have some schema bugs: 0N/A * - It puts quotes around OIDs (such as those for SUP, SYNTAX). 0N/A * - When you try to write out the MUST/MAY list (such as "MUST cn"), 0N/A * it wants ("MUST (cn)") instead 0N/A private static final boolean debug =
false;
0N/A // names of attribute IDs in the LDAP schema entry 0N/A // information for creating internal nodes in JNDI schema tree 0N/A "objectclass",
"ClassDefinition"};
0N/A "AttributeDefinition";
0N/A "objectclass",
"AttributeDefinition" };
0N/A "objectclass",
"SyntaxDefinition" };
0N/A "objectclass",
"MatchingRule" };
0N/A // special tokens used in LDAP schema descriptions 0N/A private static final char WHSP =
' ';
0N/A // Object Class specific IDs 0N/A // Attribute Type specific IDs 0N/A // The string value we give to boolean variables 0N/A // To get around writing schemas that crash Netscape server 0N/A // create the class def subtree 0N/A // error occurred while parsing, ignore current entry 0N/A // create the AttributeDef subtree 0N/A // error occurred while parsing, ignore current entry 0N/A // create the SyntaxDef subtree 0N/A // error occurred while parsing, ignore current entry 0N/A // create the MatchRuleDef subtree 0N/A // error occurred while parsing, ignore current entry 0N/A //System.err.println(desc); 0N/A int[]
pos =
new int[]{
1};
// tolerate missing leading space 0N/A // Always begins with <whsp numericoid whsp> 0N/A // returns the index of the first whitespace char of a linear whitspace 0N/A // sequince ending at the given position. 0N/A for(
int i =
pos; i >
0; i--) {
0N/A // get the name and values of the attribute to return 0N/A // tolerate a schema that omits the trailing space 0N/A // make sure at least one value was returned 0N/A // create the attribute, using the first value 0N/A // add other values if there are any 0N/A // move parser past tag name 0N/A // otherwise it's a schema element with a quoted string value 0N/A // make sure the qdstring end symbol is there 0N/A * qdstring = whsp "'" dstring "'" whsp 0N/A * qdstringlist = [ qdstring *( qdstring ) ] 0N/A * qdstrings = qdstring / ( whsp "(" qdstringlist ")" whsp ) 0N/A * ; object descriptors used as schema element names 0N/A * qdescrs = qdescr / ( whsp "(" qdescrlist ")" whsp ) 0N/A * qdescrlist = [ qdescr *( qdescr ) ] 0N/A * qdescr = whsp "'" descr "'" whsp 0N/A * qdescrlist = [ qdescr *( qdescr ) ] 0N/A * qdescr = whsp "'" descr "'" whsp 0N/A // %%% workaround for Netscape schema bug 0N/A * oids = woid / ( "(" oidlist ")" ) 0N/A * oidlist = woid *( "$" woid ) 0N/A// ----------------- "unparser" methods 0N/A// Methods that are used for translating a node in the schema tree 0N/A// into RFC2252 format for storage back into the LDAP directory 0N/A static Attributes JNDI2LDAPSchema(DirContext schemaRoot) 0N/A throws NamingException { 0N/A Attribute objDescAttr = new BasicAttribute(OBJECTCLASSDESC_ATTR_ID); 0N/A Attribute attrDescAttr = new BasicAttribute(ATTRIBUTEDESC_ATTR_ID); 0N/A Attribute syntaxDescAttr = new BasicAttribute(SYNTAXDESC_ATTR_ID); 0N/A Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); 0N/A DirContext classDefs, attributeDefs, syntaxDefs; 0N/A Attributes classDefsAttrs, attributeDefsAttrs, syntaxDefsAttrs; 0N/A NamingEnumeration defs; 0N/A obj = schemaRoot.lookup(OBJECTCLASS_DEFINITION_NAME); 0N/A if(obj != null && obj instanceof DirContext) { 0N/A classDefs = (DirContext)obj; 0N/A defs = classDefs.listBindings(""); 0N/A while(defs.hasMoreElements()) { 0N/A DirContext classDef = (DirContext) 0N/A ((Binding)(defs.next())).getObject(); 0N/A classDefAttrs = classDef.getAttributes(""); 0N/A objDescAttr.add(classDef2ObjectDesc(classDefAttrs)); 0N/A System.err.println(i + " total object classes"); 0N/A attrs.put(objDescAttr); 0N/A throw new NamingException( 0N/A "Problem with Schema tree: the object named " + 0N/A OBJECTCLASS_DEFINITION_NAME + " is not a " + 0N/A } catch (NameNotFoundException e) {} // ignore 0N/A obj = schemaRoot.lookup(ATTRIBUTE_DEFINITION_NAME); 0N/A if(obj instanceof DirContext) { 0N/A attributeDefs = (DirContext)obj; 0N/A defs = attributeDefs.listBindings(""); 0N/A while(defs.hasMoreElements()) { 0N/A DirContext attrDef = (DirContext) 0N/A ((Binding)defs.next()).getObject(); 0N/A attrDefAttrs = attrDef.getAttributes(""); 0N/A attrDescAttr.add(attrDef2AttrDesc(attrDefAttrs)); 0N/A System.err.println(i + " attribute definitions"); 0N/A attrs.put(attrDescAttr); 0N/A throw new NamingException( 0N/A "Problem with schema tree: the object named " + 0N/A ATTRIBUTE_DEFINITION_NAME + " is not a " + 0N/A } catch (NameNotFoundException e) {} // ignore 0N/A obj = schemaRoot.lookup(SYNTAX_DEFINITION_NAME); 0N/A if(obj instanceof DirContext) { 0N/A syntaxDefs = (DirContext)obj; 0N/A defs =syntaxDefs.listBindings(""); 0N/A while(defs.hasMoreElements()) { 0N/A DirContext syntaxDef = (DirContext) 0N/A ((Binding)defs.next()).getObject(); 0N/A syntaxDefAttrs = syntaxDef.getAttributes(""); 0N/A syntaxDescAttr.add(syntaxDef2SyntaxDesc(syntaxDefAttrs)); 0N/A System.err.println(i + " total syntax definitions"); 0N/A attrs.put(syntaxDescAttr); 0N/A throw new NamingException( 0N/A "Problem with schema tree: the object named " + 0N/A SYNTAX_DEFINITION_NAME + " is not a " + 0N/A } catch (NameNotFoundException e) {} // ignore 0N/A * Translate attributes that describe an object class into the 0N/A * string description as defined in RFC 2252. 0N/A // extract attributes by ID to guarantee ordering 0N/A "have a numeric OID");
0N/A // process any remaining attributes 0N/A // use enumeration because attribute ID is not known 0N/A // skip those already processed 0N/A * Translate attributes that describe an attribute definition into the 0N/A * string description as defined in RFC 2252. 0N/A // extract attributes by ID to guarantee ordering 0N/A "have a numeric OID");
0N/A // process any remaining attributes 0N/A // use enumeration because attribute ID is not known 0N/A // skip those already processed 0N/A * Translate attributes that describe an attribute syntax definition into the 0N/A * string description as defined in RFC 2252. 0N/A // extract attributes by ID to guarantee ordering 0N/A "have a numeric OID");
0N/A // process any remaining attributes 0N/A // use enumeration because attribute ID is not known 0N/A // skip those already processed 0N/A * Translate attributes that describe an attribute matching rule 0N/A * definition into the string description as defined in RFC 2252. 0N/A // extract attributes by ID to guarantee ordering 0N/A "have a numeric OID");
0N/A "have a syntax OID");
0N/A // process any remaining attributes 0N/A // use enumeration because attribute ID is not known 0N/A // skip those already processed 0N/A "A class definition must have exactly one numeric OID");
0N/A /* qdescr = whsp "'" descr "'" whsp */ 0N/A * qdstring = whsp "'" dstring "'" whsp 0N/A * qdstringlist = [ qdstring *( qdstring ) ] 0N/A * qdstrings = qdstring / ( whsp "(" qdstringlist ")" whsp ) 0N/A * qdescrs = qdescr / ( whsp "(" qdescrlist ")" whsp ) 0N/A * qdescrlist = [ qdescr *( qdescr ) ] 0N/A * qdescr = whsp "'" descr "'" whsp 0N/A break;
// %%% write out as list to avoid crashing server 0N/A * Returns an attribute for updating the Object Class Definition schema 0N/A * Returns an attribute for updating the Attribute Definition schema attribute 0N/A * Returns an attribute for updating the Syntax schema attribute 0N/A * Returns an attribute for updating the Matching Rule schema attribute