/** * Search users in contacts folder * * @param condition search filter * @param returningAttributes requested attributes * @param maxCount maximum item count * @return List of users * @throws IOException on error */ public Set<LdapContact> contactFind( Condition condition, Set<String> returningAttributes, int maxCount) throws IOException { Set<LdapContact> results = new HashSet<LdapContact>(); List<LdapContact> contacts = user.searchContacts(condition, maxCount); LogUtils.trace(log, "contactFind: contacts size:", contacts.size()); for (LdapContact contact : contacts) { results.add(contact); } return results; }
private void sendPersons( int currentMessageId, String baseContext, Set<LdapContact> persons, Set<String> returningAttributes) throws IOException, NotAuthorizedException, BadRequestException { LogUtils.debug(log, "sendPersons", baseContext, "size:", persons.size()); boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.isEmpty(); boolean returnAllAttributes = returningAttributes.isEmpty(); if (persons.isEmpty()) { log.warn("No contacts to send! -------------------"); } for (LdapContact person : persons) { if (abandon) { log.warn("Abandon flag is set, so exiting send!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); break; } Map<String, Object> response = new HashMap<String, Object>(); Set<LdapMappedProp> props = propertyMapper.mapProperties(returnAllAttributes, returningAttributes, person); response.put("uid", person.getName()); for (LdapMappedProp prop : props) { ValueAndType vt; try { vt = propertyMapper.getProperty(prop.mappedName, person); } catch (NotAuthorizedException ex) { vt = null; } if (vt == null) { LogUtils.trace( log, "sendPersons: property not found: ldap property: ", prop.ldapName, " - dav prop: ", prop.mappedName, "resource: ", person.getClass()); } else { if (vt.getValue() != null) { response.put(prop.ldapName, vt.getValue()); } } } // Process all attributes which have static mappings for (Map.Entry<String, String> entry : Ldap.STATIC_ATTRIBUTE_MAP.entrySet()) { String ldapAttribute = entry.getKey(); String value = entry.getValue(); if (value != null && (returnAllAttributes || returningAttributes.contains(ldapAttribute))) { response.put(ldapAttribute, value); } } if (needObjectClasses) { response.put("objectClass", Ldap.PERSON_OBJECT_CLASSES); } // iCal: copy email to apple-generateduid, encode @ if (returnAllAttributes || returningAttributes.contains("apple-generateduid")) { String mail = (String) response.get("mail"); if (mail != null) { response.put("apple-generateduid", mail.replaceAll("@", "__AT__")); } else { // failover, should not happen // failover, should not happen response.put("apple-generateduid", response.get("uid")); } } // iCal: replace current user alias with login name if (user.getName().equals(response.get("uid"))) { if (returningAttributes.contains("uidnumber")) { response.put("uidnumber", user.getName()); } } LogUtils.debug( log, "LOG_LDAP_REQ_SEARCH_SEND_PERSON", currentMessageId, response.get("uid"), baseContext, response); responseHandler.sendEntry( currentMessageId, "uid=" + response.get("uid") + baseContext, response); } }
/** {@inheritDoc} */ public boolean login() throws LoginException { try { final NameCallback nameCb = new NameCallback("Enter user: "******"Enter user password: "******"Authentication failed", authEx); } throw new LoginException(authEx != null ? authEx.getMessage() : "Authentication failed"); } else { if (this.setLdapPrincipal) { final LdapPrincipal lp = new LdapPrincipal(nameCb.getName()); if (attrs != null) { lp.getLdapAttributes().addAttributes(attrs); } this.principals.add(lp); } final String loginDn = this.auth.getDn(nameCb.getName()); if (loginDn != null && this.setLdapDnPrincipal) { final LdapDnPrincipal lp = new LdapDnPrincipal(loginDn); if (attrs != null) { lp.getLdapAttributes().addAttributes(attrs); } this.principals.add(lp); } if (this.setLdapCredential) { this.credentials.add(new LdapCredential(passCb.getPassword())); } this.storeCredentials(nameCb, passCb, loginDn); } } catch (NamingException e) { if (this.logger.isDebugEnabled()) { this.logger.debug("Error occured attempting authentication", e); } this.loginSuccess = false; throw new LoginException(e != null ? e.getMessage() : "Authentication Error"); } finally { this.auth.close(); } return true; }