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()); } }
private Object readValue(LDAPAttribute att) { if (att == null) return null; if (att.size() == 1) { // single value // for now everything is string return att.getStringValue(); } else { return att.getStringValueArray(); } } }
/** * Returns an enumerator for the string values of an attribute. * * @see <a href="../../../../api/com/novell/ldap/LDAPAttribute.html#getStringValues()"> com.novell.ldap.LDAPAttribute.getStringValues()</a> */ public Enumeration getStringValues() { return attr.getStringValues(); }
protected void endElement() { Iterator valueiterator = valuelist.iterator(); LDAPAttribute attr = new LDAPAttribute(attrName); while (valueiterator.hasNext()) { attr.addValue((byte[])valueiterator.next()); } setObject(attr); valuelist.clear(); }
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); } }
/** * 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)); } } } }
String attrValue = attribute.getStringValue(); MessageFormat format = valueMappings.get(logicalAttrName); if (format != null && attrValue != null) { "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.eid: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.firstName: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.firstNamePreferred: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.lastName: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.email: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() +
Enumeration<String> values = classAttribute.getStringValues(); Collection<String> groupClasses = getGroupClasses(); while (values.hasMoreElements()) { String uid = uidAttribute.getStringValue();
/** * 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; }
String attributeName = attribute.getName(); Enumeration<String> allValues = attribute.getStringValues(); LOGGER.debug(" - attribute [{}] is binary", attributeName); Enumeration<byte[]> allValues = attribute.getByteValues();
tokens.put(TokenName.fromAttribute(attr.getName()), attr.getStringValue());
/** * Constructs an attribute that has a single string value. * * @see <a href="../../../../api/com/novell/ldap/LDAPAttribute.html#LDAPAttribute(java.lang.String, java.lang.String)"> com.novell.ldap.LDAPAttribute.LDAPAttribute(String, String)</a> */ public LDAPAttribute(String attrName, String attrString) { this.attr = new com.novell.ldap.LDAPAttribute(attrName, attrString); return; }
@Test public void testLoadLDAP() throws Exception { Map<String, Object> connParms = new HashMap<>(); connParms.put("ldapHost", "ldap.forumsys.com"); connParms.put("ldapPort", 389l); connParms.put("loginDN", "cn=read-only-admin,dc=example,dc=com"); connParms.put("loginPW", "password"); LoadLdap.LDAPManager mgr = new LoadLdap.LDAPManager(LoadLdap.getConnectionMap(connParms)); Map<String, Object> searchParms = new HashMap<>(); searchParms.put("searchBase", "dc=example,dc=com"); searchParms.put("searchScope", "SCOPE_ONE"); searchParms.put("searchFilter", "(&(objectClass=*)(uid=training))"); ArrayList<String> ats = new ArrayList<>(); ats.add("uid"); searchParms.put("attributes", ats); LDAPSearchResults results = mgr.doSearch(searchParms); LDAPEntry le = results.next(); assertEquals("uid=training,dc=example,dc=com", le.getDN()); assertEquals("training", le.getAttribute("uid").getStringValue()); }
String attrName = attr.getName(); byte[][] values = attr.getByteValueArray();
if( attr.size() != 1) { throw new IllegalArgumentException("compare: Exactly one value " + "must be present in the LDAPAttribute"); attr.getName(), attr.getByteValue(), cons.getControls());
/** * 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; } /**
/** * 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(); }
attrSet.add(new LDAPAttribute(attrName)); attrSet.getAttribute(attrName).addBase64Value(currentField. substring(index+2)); attrSet.getAttribute(attrName).addBase64Value(currentField. substring(index+2)); attrSet.getAttribute(attrName).addValue(vals); attrSet.getAttribute(attrName).addValue(vals);
buff.append(ValueXMLhandler.newLine(1)); buff.append("<attr name=\""); buff.append(getName()); buff.append("\">"); writeValue(buff);
/** * Returns the values of the attribute as an array of strings. * * @see <a href="../../../../api/com/novell/ldap/LDAPAttribute.html#getStringValueArray()"> com.novell.ldap.LDAPAttribute.getStringValueArray()</a> */ public String[] getStringValueArray() { return attr.getStringValueArray(); }