📄 labbasetest.java
字号:
/*
* 创建日期 2007-5-16
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
package servlet;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls ;
import javax.naming.NamingEnumeration;
import javax.naming.directory.SearchResult;
import javax.naming.directory.Attributes ;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.ModificationItem;
import java.lang.reflect.Method;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.naming.*;
/**
* @author qzj
*
* 更改所生成类型注释的模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
public class LabBaseTest {
public static String MY_SEARCHBASE="ou=MetaEntities, o=MetaSubTree";
DirContext ctx = null;
public void init(){
String account="orcladmin";//操作LDAP的帐户。默认就是Admin。
String password="welcome";//帐户Admin的密码。
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");//必须这样写,无论用什么LDAP服务器。
env.put(Context.PROVIDER_URL, "ldap://210.25.133.32:4032/");//LDAP服务器的地址:端口。对WLS端口就是7001
env.put(Context.SECURITY_AUTHENTICATION, "simple");//授权界别,可以有三种授权级别,但是如果设为另外两种都无法登录,我也不知道为啥,但是只能设成这个值"none"。
env.put(Context.SECURITY_PRINCIPAL, "cn=" + account );//载入登陆帐户和登录密码
env.put(Context.SECURITY_CREDENTIALS, password);
try{
ctx = new InitialDirContext(env);//初始化上下文
System.out.println("认证成功");//这里可以改成异常抛出。
}catch(javax.naming.AuthenticationException e){
System.out.println("认证失败");
}catch(Exception e){
System.out.println("认证出错:"+e);
}
}
public void close(){
if(ctx != null)
{
try
{
ctx.close();
System.out.println("成功关闭");
}
catch (NamingException e)
{
System.out.println("NamingException in close():"+e);
}
}
}
public void add(String p1,String p2,String p3,String p4,String p5,String p6,String p7,String type){
try{
//String dn="ou=01,ou=DeviceContainer,ou=MetaEntities, o=MetaSubTree";//制定新条目的 DN
//String newUserName="qinzhijing";
BasicAttributes attrs =new BasicAttributes();
BasicAttribute objclassSet=new BasicAttribute("objectclass");
//BasicAttribute objclassSet=new BasicAttribute("generalLocalIdentifier");
//objclassSet.add("person");
objclassSet.add("top");
//objclassSet.add("gtype");
//objclassSet.add("inetOrgPerson");//这是个母类,添加子类时一定要先加母类
objclassSet.add("scientificDataObject");
objclassSet.add("laboratoryObject");
objclassSet.add("test1");
attrs.put(objclassSet);
//attrs.put("sn",newUserName);
//attrs.put("uid",newUserName);
//attrs.put("cn",newUserName);
attrs.put("GTitle",p1);
attrs.put("generalLocalIdentifier","");
attrs.put("orgprincipal",p4);
attrs.put("orgsuperior",p3);
attrs.put("orgsupport",p2);
attrs.put("GDescription",p7);
attrs.put("gaddressidentifier",p5);
attrs.put("orgresearch",p6);
attrs.put("gtype","005");
attrs.put("GTaxonomy",type);
attrs.put("GAggregation","");
attrs.put("OrgAddressIdentifier",p5);
attrs.put("MetaCreator","国家科技基础条件平台资源调查");
attrs.put("MetaConformsTo","国家科技基础条件平台资源元数据接口标准规范");
attrs.put("MetaVersion","5.大型仪器资源.学科分类与代码表.0.2004-10-29.自然科技资源.国家自然科技资源平台");
attrs.put("flag","0");
attrs.put("OrgName","");
attrs.put("OrgAddressIdentifier","");
ctx.createSubcontext("GTitle="+p1+", ou="+type+",ou=LaboratoryContainer,ou=MetaEntities, o=MetaSubTree", attrs);
}
catch (Exception e){
System.out.println("Exception in add():"+e);
}
}
public static void main(String[]args)
{
LabBaseTest tt=new LabBaseTest();
tt.init();
tt.add("1","2","3","4","5","6","7","110");//可用
tt.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -