⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createjavaschema.java

📁 java tutorial.sun公司官方出品。java入门书籍。最新版
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	Attributes attrs5 = new BasicAttributes();	attrs5.put(new BasicAttribute("adminDescription", attrID));	attrs5.put(new BasicAttribute("attributeID",	    "1.3.6.1.4.1.42.2.27.4.1.11"));	attrs5.put(new BasicAttribute("attributeSyntax", "2.5.5.12"));	attrs5.put(new BasicAttribute("cn", attrID));	attrs5.put(new BasicAttribute("description",	    "Addresses associated with a JNDI Reference"));	attrs5.put(new BasicAttribute("distinguishedName", "CN=" + attrID +	    "," + dn));	attrs5.put(new BasicAttribute("isSingleValued", "FALSE"));	attrs5.put(new BasicAttribute("lDAPDisplayName", attrID));	attrs5.put(new BasicAttribute("name", attrID));	attrs5.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," +	    dn));	attrs5.put(new BasicAttribute("objectClass", "attributeSchema"));	attrs5.put(new BasicAttribute("oMSyntax", "64"));	attrs5.put(new BasicAttribute("searchFlags", "0"));	attrs5.put(new BasicAttribute("systemOnly", "FALSE"));	schemaCtx.createSubcontext("cn=" + attrID, attrs5);System.out.println("    [" + attrID + "]");	attrID = new String("javaDoc");	Attributes attrs6 = new BasicAttributes();	attrs6.put(new BasicAttribute("adminDescription", attrID));	attrs6.put(new BasicAttribute("attributeID",	    "1.3.6.1.4.1.42.2.27.4.1.12"));	attrs6.put(new BasicAttribute("attributeSyntax", "2.5.5.5"));	attrs6.put(new BasicAttribute("cn", attrID));	attrs6.put(new BasicAttribute("description",	    "The Java documentation for the class"));	attrs6.put(new BasicAttribute("distinguishedName", "CN=" + attrID +	    "," + dn));	attrs6.put(new BasicAttribute("isSingleValued", "FALSE"));	attrs6.put(new BasicAttribute("lDAPDisplayName", attrID));	attrs6.put(new BasicAttribute("name", attrID));	attrs6.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," +	    dn));	attrs6.put(new BasicAttribute("objectClass", "attributeSchema"));	attrs6.put(new BasicAttribute("oMSyntax", "22"));	attrs6.put(new BasicAttribute("searchFlags", "0"));	attrs6.put(new BasicAttribute("systemOnly", "FALSE"));	schemaCtx.createSubcontext("cn=" + attrID, attrs6);System.out.println("    [" + attrID + "]");	attrID = new String("javaClassNames");	Attributes attrs7 = new BasicAttributes();	attrs7.put(new BasicAttribute("adminDescription", attrID));	attrs7.put(new BasicAttribute("attributeID",	    "1.3.6.1.4.1.42.2.27.4.1.13"));	attrs7.put(new BasicAttribute("attributeSyntax", "2.5.5.12"));	attrs7.put(new BasicAttribute("cn", attrID));	attrs7.put(new BasicAttribute("description",	    "Fully qualified Java class or interface name"));	attrs7.put(new BasicAttribute("distinguishedName", "CN=" + attrID +	    "," + dn));	attrs7.put(new BasicAttribute("isSingleValued", "FALSE"));	attrs7.put(new BasicAttribute("lDAPDisplayName", attrID));	attrs7.put(new BasicAttribute("name", attrID));	attrs7.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," +	    dn));	attrs7.put(new BasicAttribute("objectClass", "attributeSchema"));	attrs7.put(new BasicAttribute("oMSyntax", "64"));	attrs7.put(new BasicAttribute("searchFlags", "0"));	attrs7.put(new BasicAttribute("systemOnly", "FALSE"));	schemaCtx.createSubcontext("cn=" + attrID, attrs7);System.out.println("    [" + attrID + "]");	flushADSchemaMods(rootCtx); // finally    }    /**     * Inserts object class definitions from RFC 2713 into the schema.     *     * This method maps the LDAP schema definitions in RFC 2713 onto the     * proprietary attributes required by the Active Directory schema.     *     * The resulting object class definitions differ from those of RFC 2713     * in the following ways:     *     *     - Abstract and auxiliary classes are now defined as structural.     *     - The javaObject class now inherits from javaContainer.     *     - The javaNamingReference, javaSerializedObject and     *       javaMarshalledObject now inherit from javaObject.     *     * The effect of these differences is that Java objects cannot be     * mixed-in with other directory entries, they may only be stored as     * stand-alone entries.     *     * The reason for these differences is due to the way auxiliary classes     * are supported the Active Directory. Only the names of structural     * classes (not auxiliary) may appear in the object class attribute of     * an entry. Therefore, the abstract and auxiliary classes in the Java     * schema definition are re-defined as structural.     */    protected void insertADObjectClasses(DirContext rootCtx,	DirContext schemaCtx) throws NamingException {System.out.println("  [inserting new object class definitions ...]");	String dn = schemaCtx.getNameInNamespace();	String attrID;	attrID = new String("javaContainer");	Attributes attrs1 = new BasicAttributes();	attrs1.put(new BasicAttribute("objectClass", "classSchema"));	attrs1.put(new BasicAttribute("defaultHidingValue", "FALSE"));	attrs1.put(new BasicAttribute("governsID",	    "1.3.6.1.4.1.42.2.27.4.2.1"));	attrs1.put(new BasicAttribute("lDAPDisplayName", attrID));	attrs1.put(new BasicAttribute("mustContain", "cn"));	attrs1.put(new BasicAttribute("objectClassCategory", "1"));	attrs1.put(new BasicAttribute("systemOnly", "FALSE"));	attrs1.put(new BasicAttribute("subclassOf", "top"));	attrs1.put(new BasicAttribute("possSuperiors", "top")); //any superior	attrs1.put(new BasicAttribute("description",	    "Container for a Java object"));	schemaCtx.createSubcontext("CN=" + attrID, attrs1);System.out.println("    [" + attrID + "]");	flushADSchemaMods(rootCtx); // because javaObject relys on javaContainer	attrID = new String("javaObject");	Attributes attrs2 = new BasicAttributes();	attrs2.put(new BasicAttribute("objectClass", "classSchema"));	attrs2.put(new BasicAttribute("defaultHidingValue", "FALSE"));	attrs2.put(new BasicAttribute("governsID",	    "1.3.6.1.4.1.42.2.27.4.2.4"));	attrs2.put(new BasicAttribute("lDAPDisplayName", attrID));	attrs2.put(new BasicAttribute("mustContain", "javaClassName"));	Attribute joMay = new BasicAttribute("mayContain");	joMay.add("javaClassNames");	joMay.add("javaCodeBase");	joMay.add("javaDoc");	joMay.add("description");	attrs2.put(joMay);	attrs2.put(new BasicAttribute("objectClassCategory", "1"));	attrs2.put(new BasicAttribute("systemOnly", "FALSE"));	attrs2.put(new BasicAttribute("subclassOf", "javaContainer"));	attrs2.put(new BasicAttribute("description",	    "Java object representation"));	schemaCtx.createSubcontext("CN=" + attrID, attrs2);System.out.println("    [" + attrID + "]");	flushADSchemaMods(rootCtx); // because next 3 rely on javaObject	attrID = new String("javaSerializedObject");	Attributes attrs3 = new BasicAttributes();	attrs3.put(new BasicAttribute("objectClass", "classSchema"));	attrs3.put(new BasicAttribute("defaultHidingValue", "FALSE"));	attrs3.put(new BasicAttribute("governsID",	    "1.3.6.1.4.1.42.2.27.4.2.5"));	attrs3.put(new BasicAttribute("lDAPDisplayName", attrID));	attrs3.put(new BasicAttribute("mustContain", "javaSerializedData"));	attrs3.put(new BasicAttribute("objectClassCategory", "1"));	attrs3.put(new BasicAttribute("systemOnly", "FALSE"));	attrs3.put(new BasicAttribute("subclassOf", "javaObject"));	attrs3.put(new BasicAttribute("description", "Java serialized object"));	schemaCtx.createSubcontext("CN=" + attrID, attrs3);System.out.println("    [" + attrID + "]");	attrID = new String("javaNamingReference");	Attributes attrs4 = new BasicAttributes();	attrs4.put(new BasicAttribute("objectClass", "classSchema"));	attrs4.put(new BasicAttribute("defaultHidingValue", "FALSE"));	attrs4.put(new BasicAttribute("governsID",	    "1.3.6.1.4.1.42.2.27.4.2.7"));	attrs4.put(new BasicAttribute("lDAPDisplayName", attrID));	Attribute jnrMay = new BasicAttribute("mayContain");	jnrMay.add("javaReferenceAddress");	jnrMay.add("javaFactory");	attrs4.put(jnrMay);	attrs4.put(new BasicAttribute("objectClassCategory", "1"));	attrs4.put(new BasicAttribute("systemOnly", "FALSE"));	attrs4.put(new BasicAttribute("subclassOf", "javaObject"));	attrs4.put(new BasicAttribute("description", "JNDI reference"));	schemaCtx.createSubcontext("CN=" + attrID, attrs4);System.out.println("    [" + attrID + "]");	attrID = new String("javaMarshalledObject");	Attributes attrs5 = new BasicAttributes();	attrs5.put(new BasicAttribute("objectClass", "classSchema"));	attrs5.put(new BasicAttribute("defaultHidingValue", "FALSE"));	attrs5.put(new BasicAttribute("governsID",	    "1.3.6.1.4.1.42.2.27.4.2.8"));	attrs5.put(new BasicAttribute("lDAPDisplayName", attrID));	attrs5.put(new BasicAttribute("mustContain", "javaSerializedData"));	attrs5.put(new BasicAttribute("objectClassCategory", "1"));	attrs5.put(new BasicAttribute("systemOnly", "FALSE"));	attrs5.put(new BasicAttribute("subclassOf", "javaObject"));	attrs5.put(new BasicAttribute("description", "Java marshalled object"));	schemaCtx.createSubcontext("CN=" + attrID, attrs5);System.out.println("    [" + attrID + "]");	flushADSchemaMods(rootCtx); // finally    }    /**     * Writes schema modifications to the Active Directory schema immediately.     */    protected void flushADSchemaMods(DirContext rootCtx)	throws NamingException {	rootCtx.modifyAttributes("", new ModificationItem[] {	    new ModificationItem(DirContext.ADD_ATTRIBUTE,		new BasicAttribute("schemaUpdateNow", "1")) });    }    private int processCommandLine(String[] args) {	String option;	boolean schema = false;	boolean list = false;	for (int i = 0; i < args.length; i++) {	    option = args[i];	    if (option.startsWith("-h")) {		printUsage(null);	    }	    if (option.startsWith("-s")) {		schema = true;		netscapebug = option.equals("-sn");		netscape41bug = option.equals("-sn41");		activeDirectorySchemaBug = option.equals("-sad");	    } else if (option.startsWith("-l")) {		list = true;	    } else if (option.startsWith("-a")) {		auth = option.substring(2);	    } else if (option.startsWith("-n")) {		dn = option.substring(2);	    } else if (option.startsWith("-p")) {		passwd = option.substring(2);	    } else if (option.startsWith("-trace")) {		traceLdap = true;	    } else {		// invalid option		printUsage("Invalid option");	    }	}	if (!schema) {	    return LIST;	} else {	    return UPDATE;	}    }    protected void printUsage(String msg) {	printUsageAux(msg, "Java");    }    protected void printUsageAux(String msg, String key) {	if (msg != null) {	    System.out.println(msg);	}System.out.print("Usage: ");System.out.println("java [-Djava.naming.provider.url=<ldap_server_url>] \\");System.out.println("  Create" + key + "Schema [-h|-l|-s[n|n41|ad]] [-n<dn>] [-p<passwd>] [-a<auth>]");System.out.println();System.out.println("  -h\t\tPrint the usage message");System.out.println("  -l\t\tList the " + key + " schema in the directory");System.out.println("  -s[n|n41|ad]\tUpdate schema:");System.out.println(    "\t\t -sn   use workaround for Netscape Directory pre-4.1 schema bug");System.out.println(    "\t\t -sn41 use workaround for Netscape Directory 4.1 schema bug");System.out.println(    "\t\t -sad  use workaround for Active Directory schema bug");System.out.println("  -n<dn>\tUse <dn> as the distinguished name for authentication");System.out.println("  -p<passwd>\tUse <passwd> as the password for authentication");System.out.println("  -a<auth>\tUse <auth> as the authentication mechanism");System.out.println("\t\t Default is 'simple' if dn specified; otherwise 'none'");	System.exit(-1);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -