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()); } }
@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()); }
/** * Returns the distinguished name of the entry. * * @see <a href="../../../../api/com/novell/ldap/LDAPEntry.html#getDN()"> com.novell.ldap.LDAPEntry.getDN()</a> */ public String getDN() { return entry.getDN(); }
/** * Always returns the value set by {@link #setUserType(String)}. * Default is <code>null</code> * * @return the value cached by {@link #setUserType(String)}. */ public String mapLdapEntryToSakaiUserType(LDAPEntry ldapEntry, LdapAttributeMapper mapper) { if ( log.isDebugEnabled() ) { log.debug("mapLdapEntryToSakaiUserType(): returning user type [" + userType + "] for [entry DN = " + ldapEntry.getDN() + "]"); } return userType; }
protected void setUserDataDn(LDAPEntry entry, LdapUserData targetUserData) { targetUserData.setProperty( AttributeMappingConstants.USER_DN_PROPERTY, entry.getDN()); }
ldapEntry.getDN() + "]"); log.debug("getUserTypeAttribute(): failed to find attribute mapping [logical attr name = " + logicalAttributeName + "][entry DN = " + ldapEntry.getDN() + "]"); if ( log.isDebugEnabled() ) { log.debug("getUserTypeAttribute(): entry had no Sakai user type attr [physical attr name = " + attrName + "][entry DN = " + ldapEntry.getDN() + "]");
/** * Maps attributes from the specified <code>LDAPEntry</code> onto * a newly instantiated {@link LdapUserData}. Implemented to * delegate to the currently assigned {@link LdapAttributeMapper}. * * @see LdapAttributeMapper#mapLdapEntryOntoUserData(LDAPEntry, LdapUserData) * @param ldapEntry a non-null directory entry to map * @return a new {@link LdapUserData}, populated with directory * attributes */ protected LdapUserData mapLdapEntryOntoUserData(LDAPEntry ldapEntry) { if ( log.isDebugEnabled() ) { log.debug("mapLdapEntryOntoUserData() [dn = " + ldapEntry.getDN() + "]"); } LdapUserData userData = newLdapUserData(); ldapAttributeMapper.mapLdapEntryOntoUserData(ldapEntry, userData); return userData; }
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 Element myWriteEntry( LDAPEntry entry, LDAPControl[] controls ) { Element e = doc.createElement("searchResultEntry"); e.setAttribute("dn", entry.getDN()); LDAPAttributeSet set = entry.getAttributeSet(); Iterator iterator = set.iterator(); while (iterator.hasNext()){ LDAPAttribute attr = (LDAPAttribute)iterator.next(); Element attribute = doc.createElement("attr"); writeAttribute(attribute, attr); e.appendChild(attribute); } if (controls != null) { writeControls(e, controls); } searchNode.appendChild( e); return e; }
/** * 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("<LDAPEntry dn=\""); out.write(getDN()); out.write("\">"); Iterator i = getAttributeSet().iterator(); while (i.hasNext()){ writeAttribute( (LDAPAttribute) i.next(),out); } newLine(0,out); out.write("</LDAPEntry>"); out.close(); } /**
(LDAPEntry)LDAPEntry.readDSML(istream); this.dn = readObject.getDN(); this.attrs = readObject.getAttributeSet();
results.forEach(entry -> userDNs.add(entry.getDN()));
" cannot be null"); if( entry.getDN() == null) { throw new IllegalArgumentException("The DN value must be present" + " in the LDAPEntry object");
protected void setDeserializedValues(LDAPMessage readObject, RfcControls asn1Ctrls) throws IOException, ClassNotFoundException { // Check if it is the correct message type if(!(readObject instanceof LDAPAddRequest)) throw new ClassNotFoundException("Error occured while deserializing " + "LDAPAddRequest object"); LDAPAddRequest tmp = (LDAPAddRequest)readObject; LDAPEntry entry = tmp.getEntry(); tmp = null; //remove reference after getting properties RfcRequest operation = new RfcAddRequest( new RfcLDAPDN(entry.getDN()), LDAPAddRequest.makeRfcAttrList( entry)); message = new RfcLDAPMessage(operation, asn1Ctrls); // Garbage collect the readObject from readDSML().. readObject = null; } }
/** * Constructs a request to add an entry to the directory. * * @param entry The LDAPEntry to add to the directory. * * @param cont Any controls that apply to the add request, * or null if none. */ public LDAPAddRequest( LDAPEntry entry, LDAPControl[] cont) throws LDAPException { super( LDAPMessage.ADD_REQUEST, new RfcAddRequest( new RfcLDAPDN(entry.getDN()), makeRfcAttrList( entry)), cont); return; }
protected void setDeserializedValues(LDAPMessage readObject, RfcControls asn1Ctrls) throws IOException, ClassNotFoundException { // Check if it is the correct message type if(!(readObject instanceof LDAPSearchResult)) throw new ClassNotFoundException("Error occured while deserializing " + "LDAPSearchResult object"); LDAPSearchResult tmp = (LDAPSearchResult)readObject; LDAPEntry entry = tmp.getEntry(); tmp = null; //remove reference after getting properties message = new RfcLDAPMessage( new RfcSearchResultEntry( new ASN1OctetString(entry.getDN()), LDAPSearchResult.getEntrySequence(entry)), asn1Ctrls); // Garbage collect the readObject from readDSML().. readObject = null; }
if (username == null) { logger.warn("User \"{}\" is missing a username attribute " + "and will be ignored.", entry.getDN()); return null;
/** * Constructs an LDAPSearchResult object from an LDAPEntry. * * @param entry the LDAPEntry represented by this search result. * <br><br> * @param cont controls associated with the search result */ public LDAPSearchResult(LDAPEntry entry, LDAPControl[] cont) { super( new RfcLDAPMessage( new RfcSearchResultEntry( new ASN1OctetString(entry.getDN()), getEntrySequence(entry)), RfcControlFactory(cont))); this.entry = entry; return; } /** Converts a LDAPControl array to an RfcControl Structure.