LDAP中属性值是多个的添加方法
By:Roy.LiuLast updated:2011-06-22
最近用Tivoli TDS 来保存数据,有的属性值可以存多个值的方法。
public static void bindEntry(DirContext dirContext)
throws Exception{
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute("gps001", "001"));
matchAttrs.put(new BasicAttribute("gps002", "002"));
//====================多个属性值==========================================
BasicAttribute a=new BasicAttribute("gps002","coolbaby3");
a.add("3434");
a.add("ertert");
matchAttrs.put(a);
//====================多个属性值结束======================================
matchAttrs.put(new BasicAttribute("objectclass", "top"));
matchAttrs.put(new BasicAttribute("objectclass","gpstest"));
String name="cn=gpstest";
//==================================================================
DirContext schema = (DirContext)dirContext.getSchema("").lookup("ClassDefinition/gpsPerson");
System.out.println("schema mytest:"+schema.getAttributes(""));
DirContext schemaperson = (DirContext)dirContext.getSchema("").lookup("ClassDefinition/mytest");
System.out.println("schema: person"+schemaperson.getAttributes(""));
//==================================================================
InitialDirContext iniDirContext = (InitialDirContext)dirContext;
System.out.println("begin to bind.");
iniDirContext.rebind(name,dirContext,matchAttrs);
}
public static void bindEntry(DirContext dirContext)
throws Exception{
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute("gps001", "001"));
matchAttrs.put(new BasicAttribute("gps002", "002"));
//====================多个属性值==========================================
BasicAttribute a=new BasicAttribute("gps002","coolbaby3");
a.add("3434");
a.add("ertert");
matchAttrs.put(a);
//====================多个属性值结束======================================
matchAttrs.put(new BasicAttribute("objectclass", "top"));
matchAttrs.put(new BasicAttribute("objectclass","gpstest"));
String name="cn=gpstest";
//==================================================================
DirContext schema = (DirContext)dirContext.getSchema("").lookup("ClassDefinition/gpsPerson");
System.out.println("schema mytest:"+schema.getAttributes(""));
DirContext schemaperson = (DirContext)dirContext.getSchema("").lookup("ClassDefinition/mytest");
System.out.println("schema: person"+schemaperson.getAttributes(""));
//==================================================================
InitialDirContext iniDirContext = (InitialDirContext)dirContext;
System.out.println("begin to bind.");
iniDirContext.rebind(name,dirContext,matchAttrs);
}
From:一号门
Previous:LDAP 对object class 的操作。
COMMENTS