private Attributes buildAttributes( String dn, String[] attributes, String[] values, String multValuedSeparator ) { Attributes attrs = new javax.naming.directory.BasicAttributes( true ); int nrAttributes = attributes.length; for ( int i = 0; i < nrAttributes; i++ ) { if ( !Utils.isEmpty( values[i] ) ) { // We have a value String value = values[i].trim(); if ( multValuedSeparator != null && value.indexOf( multValuedSeparator ) > 0 ) { Attribute attr = new javax.naming.directory.BasicAttribute( attributes[i] ); for ( String attribute : value.split( multValuedSeparator ) ) { attr.add( attribute ); } attrs.put( attr ); } else { attrs.put( attributes[i], value ); } } } return attrs; }
private static Attributes mockAttributes(NameValues... namedValues) throws NamingException { Attributes attributes = new BasicAttributes(); for (NameValues namedValue : namedValues) { Attribute attr = new BasicAttribute(namedValue.name); for (String value : namedValue.values) { attr.add(value); } attributes.put(attr); } return attributes; }
public static <T> Attribute attr(String attrID, T... vals) { Attribute attr = new BasicAttribute(attrID); for (T val : vals) attr.add(val.toString()); return attr; }
private static Attribute attr(String attrID, byte[]... vals) { Attribute attr = new BasicAttribute(attrID); for (byte[] val : vals) attr.add(val); return attr; }
public static Attribute attr(String attrID, int... vals) { Attribute attr = new BasicAttribute(attrID); for (int val : vals) attr.add(Integer.toString(val)); return attr; }
private static void addEmptyValue(String emptyValue, Attribute attr) { if (attr != null && attr.size() == 0 && emptyValue != null) { attr.add(emptyValue); } }
private static void addEmptyValue(String emptyValue, Attribute attr) { if (attr != null && attr.size() == 0 && emptyValue != null) { attr.add(emptyValue); } }
Attributes attributes=new BasicAttributes(); Attribute objectClass=new BasicAttribute("objectClass"); objectClass.add("inetOrgPerson"); attributes.put(objectClass); Attribute sn=new BasicAttribute("sn"); Attribute cn=new BasicAttribute("cn"); sn.add("sahul"); cn.add("vetcha"); attributes.put(sn); attributes.put(cn); attributes.put("title","software engg") ctx.createSubcontext("uid=sahul,ou=some organization7,o=some company7,ou=system",attributes);
private static Attribute connRefs(Collection<Connection> conns, String deviceDN) { Attribute attr = new BasicAttribute("dicomNetworkConnectionReference"); for (Connection conn : conns) attr.add(LdapUtils.dnOf(conn, deviceDN)); return attr; }
public void addChildGroup(LDAPGroup childGroup) { Attribute memberAttribute = getLDAPAttributes().get(MEMBER); if (memberAttribute == null) { memberAttribute = new BasicAttribute(MEMBER); getLDAPAttributes().put(memberAttribute); } memberAttribute.add(getDN(childGroup.getName())); }
public void addMember(LDAPEntry childEntry) { Attribute memberAttribute = getLDAPAttributes().get(MEMBER); if (memberAttribute != null) { if (memberAttribute.contains(SPACE_STRING)) { memberAttribute.remove(SPACE_STRING); } } else { memberAttribute = new BasicAttribute(MEMBER); } memberAttribute.add(childEntry.getDN()); getLDAPAttributes().put(memberAttribute); }
@Override protected void storeTo(Device device, Attributes attrs) { ProxyDeviceExtension proxyDev = device.getDeviceExtension(ProxyDeviceExtension.class); if (proxyDev == null) return; attrs.get("objectClass").add("dcmProxyDevice"); LdapUtils.storeNotNull(attrs, "dcmSchedulerInterval", proxyDev.getSchedulerInterval()); LdapUtils.storeNotNull(attrs, "dcmForwardThreads", proxyDev.getForwardThreads()); LdapUtils.storeNotDef(attrs, "dcmProxyConfigurationStaleTimeout", proxyDev.getConfigurationStaleTimeout(), 0); }
private Attribute createRangeAttribute(String attributeName, RangeOption range, int valueCnt) { Attribute attribute = new BasicAttribute(attributeName + ";" + range.toString()); for (int i = 0; i < valueCnt; i++) { attribute.add("value" + (range.getInitial() + i - 1)); } return attribute; } }
@Test public void testResetAttributeValuesNotReportedAsModifications() { BasicAttributes attrs = new BasicAttributes("myattr", "a"); attrs.get("myattr").add("b"); attrs.get("myattr").add("c"); UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName()); ctx.setAttributeValues("myattr", new String[] { "a", "b" }); ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" }); assertThat(ctx.getModificationItems().length).isEqualTo(0); }
@Test public void testResetAttributeValuesSameLengthNotReportedAsModifications() { BasicAttributes attrs = new BasicAttributes("myattr", "a"); attrs.get("myattr").add("b"); attrs.get("myattr").add("c"); UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName()); ctx.setAttributeValues("myattr", new String[] { "a", "b", "d" }); ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" }); assertThat(ctx.getModificationItems().length).isEqualTo(0); }
public void addMembers(String groupDN, Iterable<String> memberDNs) throws Exception { LdapContext ctxt = getWiredContext(); Attribute attr = new BasicAttribute("member"); for (String dn : memberDNs) { attr.add(dn); } BasicAttributes attrs = new BasicAttributes(); attrs.put(attr); ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs); }