public Map<String, Object> get() { if (handleEndOfResults()) return null; try { Map<String, Object> entry = new LinkedHashMap<>(attributes.size() + 1); LDAPEntry en = null; en = lsr.next(); entry.put("dn", en.getDN()); if (attributes != null && attributes.size() > 0) { for (int col = 0; col < attributes.size(); col++) { Object val = readValue(en.getAttributeSet().getAttribute(attributes.get(col))); if (val != null) entry.put(attributes.get(col),val ); } } else { // make it dynamic Iterator<LDAPAttribute> iter = en.getAttributeSet().iterator(); while (iter.hasNext()) { LDAPAttribute attr = iter.next(); Object val = readValue(attr); if (val != null) entry.put(attr.getName(), readValue(attr)); } } //System.out.println("entry " + entry); return entry; } catch (LDAPException e) { e.printStackTrace(); throw new RuntimeException("Error getting next ldap entry " + e.getLDAPErrorMessage()); } }
/** * Returns the name of the attribute. * * @see <a href="../../../../api/com/novell/ldap/LDAPAttribute.html#getName()"> com.novell.ldap.LDAPAttribute.getName()</a> */ public String getName() { return attr.getName(); }
/** * Returns <code>true</code> if this set contains an attribute of the same name * as the specified attribute. * * @param attr Object of type <code>LDAPAttribute</code> * * @return true if this set contains the specified attribute * * @throws ClassCastException occurs the specified Object * is not of type LDAPAttribute. */ public boolean contains(Object attr) { LDAPAttribute attribute = (LDAPAttribute) attr; return this.map.containsKey( attribute.getName().toUpperCase() ); }
/** * Adds the specified attribute to this set if it is not already present. * <p>If an attribute with the same name already exists in the set then the * specified attribute will not be added.</p> * * @param attr Object of type <code>LDAPAttribute</code> * * @return true if the attribute was added. * * @throws ClassCastException occurs the specified Object * is not of type <code>LDAPAttribute</code>. */ public boolean add(Object attr) { //We must enforce that attr is an LDAPAttribute LDAPAttribute attribute = (LDAPAttribute) attr; String name = attribute.getName().toUpperCase(); if( this.map.containsKey(name)) return false; else{ this.map.put(name, attribute); return true; } }
/** * Removes the specified object from this set if it is present. * * <p>If the specified object is of type <code>LDAPAttribute</code>, the * specified attribute will be removed. If the specified object is of type * <code>String</code>, the attribute with a name that matches the string will * be removed.</p> * * @param object LDAPAttribute to be removed or <code>String</code> naming * the attribute to be removed. * * @return true if the object was removed. * * @throws ClassCastException occurs the specified Object * is not of type <code>LDAPAttribute</code> or of type <code>String</code>. */ public boolean remove(Object object) { String attributeName; //the name is the key to object in the HashMap if (object instanceof String){ attributeName = (String)object; } else { attributeName = ((LDAPAttribute) object).getName(); } if (attributeName == null){ return false; } return (this.map.remove( attributeName.toUpperCase() ) != null ); }
/** * Fill provided <code>searchAttributeList</code> with provided LDAP attributes. * * @param searchAttributeList the XWiki attributes. * @param attributeSet the LDAP attributes. */ protected void ldapToXWikiAttribute(List<XWikiLDAPSearchAttribute> searchAttributeList, LDAPAttributeSet attributeSet) { for (Object attributeItem : attributeSet) { LDAPAttribute attribute = (LDAPAttribute) attributeItem; String attributeName = attribute.getName(); if (LOG.isDebugEnabled()) { LOG.debug(" - values for attribute \"" + attributeName + "\""); } Enumeration<String> allValues = attribute.getStringValues(); if (allValues != null) { while (allValues.hasMoreElements()) { String value = allValues.nextElement(); if (LOG.isDebugEnabled()) { LOG.debug(" |- [" + value + "]"); } searchAttributeList.add(new XWikiLDAPSearchAttribute(attributeName, value)); } } } }
LDAPEntry entry1 = searchResults.next(); System.out.println("\n" + entry1.getDN()); System.out.println(" Attributes: "); LDAPAttributeSet attributeSet1 = entry1.getAttributeSet(); Iterator allAttributes1 = attributeSet1.iterator(); while(allAttributes1.hasNext()) { LDAPAttribute attribute = (LDAPAttribute)allAttributes1.next(); String attrName = attribute.getName(); System.out.println(" " + attrName); Enumeration allValues1 = attribute.getStringValues(); while(allValues1.hasMoreElements()) { oid = (String) allValues1.nextElement(); if ( (attrName.equalsIgnoreCase("supportedExtension")) || (attrName.equalsIgnoreCase("supportedControl"))) { System.out.println(" " + oid); } } }
private void writeAttribute(Element attribute, LDAPAttribute attr) { attribute.setAttribute("name", attr.getName()); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ Element value = doc.createElement("value"); if (Base64.isValidUTF8(bytevalues[i], false)){ value.appendChild(doc.createTextNode(values[i])); } else { value.setAttribute("xsi:type", "base64Binary"); value.appendChild(doc.createTextNode( Base64.encode(bytevalues[i]))); } attribute.appendChild(value); } }
/** * This method does DSML serialization of the instance. * * @param oout Outputstream where the serialzed data has to be written * * @throws IOException if write fails on OutputStream */ public void writeDSML(java.io.OutputStream oout) throws java.io.IOException { java.io.Writer out=new java.io.OutputStreamWriter(oout,"UTF-8"); out.write("<LDAPAttribute>"); newLine(1,out); out.write("<attr name=\""); out.write(getName()); out.write("\">"); //sub classes override this.. writeValue(out); newLine(1,out); out.write("</attr>"); newLine(0,out); out.write("</LDAPAttribute>"); out.close(); }
private void writeAttribute(LDAPAttribute attr, StringBuffer buff) throws java.io.IOException { buff.append(ValueXMLhandler.newLine(1)); buff.append("<attr name=\""); buff.append(attr.getName()); buff.append("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ buff.append(ValueXMLhandler.newLine(2)); if (Base64.isValidUTF8(bytevalues[i], false)){ buff.append("<value>"); buff.append(values[i]); buff.append("</value>"); } else { buff.append("<value xsi:type=\"xsd:base64Binary\">"); buff.append(Base64.encode(bytevalues[i])); buff.append("</value>"); } } buff.append(ValueXMLhandler.newLine(1)); buff.append("</attr>"); }
private void writeAttribute(LDAPAttribute attr, StringBuffer buff) throws java.io.IOException { buff.append(ValueXMLhandler.newLine(2)); buff.append("<attr name=\""); buff.append(attr.getName()); buff.append("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ buff.append(ValueXMLhandler.newLine(3)); if (Base64.isValidUTF8(bytevalues[i], false)){ buff.append("<value><![CDATA["); buff.append(values[i]); buff.append("]]></value>"); } else { buff.append("<value xsi:type=\"xsd:base64Binary\"><![CDATA["); buff.append(Base64.encode(bytevalues[i])); buff.append("]]></value>"); } } buff.append(ValueXMLhandler.newLine(2)); buff.append("</attr>"); }
private void writeAttribute(LDAPAttribute attr, StringBuffer buff) throws java.io.IOException { buff.append(ValueXMLhandler.newLine(1)); buff.append("<attr name=\""); buff.append(attr.getName()); buff.append("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ buff.append(ValueXMLhandler.newLine(2)); if (Base64.isValidUTF8(bytevalues[i], false)){ buff.append("<value>"); buff.append(values[i]); buff.append("</value>"); } else { buff.append("<value xsi:type=\"xsd:base64Binary\">"); buff.append(Base64.encode(bytevalues[i])); buff.append("</value>"); } } buff.append(ValueXMLhandler.newLine(1)); buff.append("</attr>"); }
String attributeName = attribute.getName();
private void writeAttribute(LDAPAttribute attr,java.io.Writer out) throws java.io.IOException { newLine(2,out); out.write("<attr name=\""); out.write(attr.getName()); out.write("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ newLine(3,out); if (Base64.isValidUTF8(bytevalues[i], false)){ out.write("<value>"); out.write(values[i]); out.write("</value>"); } else { out.write("<value xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(bytevalues[i])); out.write("</value>"); } } newLine(2,out); out.write("</attr>"); }
private void writeAttribute(LDAPAttribute attr,java.io.Writer out) throws java.io.IOException { newLine(1,out); out.write("<attr name=\""); out.write(attr.getName()); out.write("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ newLine(2,out); if (Base64.isValidUTF8(bytevalues[i], false)){ out.write("<value>"); out.write(values[i]); out.write("</value>"); } else { out.write("<value xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(bytevalues[i])); out.write("</value>"); } } newLine(1,out); out.write("</attr>"); }
/** * Used to write an attribute and its values. * @param attr Attribute to be written. */ private void writeAttribute(LDAPAttribute attr) throws IOException { newLine(3); out.write("<attr name=\""); out.write(attr.getName()); out.write("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ newLine(4); if (Base64.isValidUTF8(bytevalues[i],true) && this.isXMLSafe(bytevalues[i])){ out.write("<value>"); String xmlvalue = makeAttributeSafe(values[i]); out.write(xmlvalue); out.write("</value>"); } else { out.write("<value xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(bytevalues[i])); out.write("</value>"); } } newLine(3); out.write("</attr>"); return; }
/** * Build the attribuite list from an LDAPEntry. * * @param entry The LDAPEntry associated with this add request. */ private static final RfcAttributeList makeRfcAttrList( LDAPEntry entry) { // convert Java-API LDAPEntry to RFC2251 AttributeList LDAPAttributeSet attrSet = entry.getAttributeSet(); RfcAttributeList attrList = new RfcAttributeList(attrSet.size()); Iterator itr = attrSet.iterator(); while (itr.hasNext()) { LDAPAttribute attr = (LDAPAttribute)itr.next(); ASN1SetOf vals = new ASN1SetOf(attr.size()); Enumeration attrEnum = attr.getByteValues(); while(attrEnum.hasMoreElements()) { vals.add(new RfcAttributeValue((byte[])attrEnum.nextElement())); } attrList.add(new RfcAttributeTypeAndValues( new RfcAttributeDescription(attr.getName()), vals)); } return attrList; }
while (allAttrs.hasNext()) { LDAPAttribute attr = allAttrs.next(); String attrName = attr.getName(); System.out.println(attrName); if (attrName.equalsIgnoreCase("suid")) { // we got the CN
/** * Creates a ASN Encoded Sequence for the specified entry. * @param entry The LDAPEntry to be encoded. * @return ASN Encoded representation of the entry. */ private static ASN1Sequence getEntrySequence(LDAPEntry entry) { if (entry == null) { throw new IllegalArgumentException("Argument \"entry\" cannot be null"); } Iterator entryiterator = entry.getAttributeSet().iterator(); ASN1Sequence attributelistsequence = new ASN1Sequence(); while (entryiterator.hasNext()) { ASN1Sequence attributesequence = new ASN1Sequence(); LDAPAttribute attribute = (LDAPAttribute) entryiterator.next(); attributesequence.add(new ASN1OctetString(attribute.getName())); ASN1Set valueset = new ASN1Set(); String[] valueArray = attribute.getStringValueArray(); if (valueArray != null) for (int i = 0; i < valueArray.length; i++) { valueset.add(new ASN1OctetString(valueArray[i])); } attributesequence.add(valueset); attributelistsequence.add(attributesequence); } return attributelistsequence; } /**
rfcMod.add(new ASN1Enumerated(mods[i].getOp())); rfcMod.add(new RfcAttributeTypeAndValues( new RfcAttributeDescription(attr.getName()), vals));