protected LDAPObject queryByEmail(RealmModel realm, String email) {
    LDAPQuery ldapQuery = LDAPUtils.createQueryForUserSearch(this, realm);
    LDAPQueryConditionsBuilder conditionsBuilder = new LDAPQueryConditionsBuilder();

    // Mapper should replace "email" in parameter name with correct LDAP mapped attribute
    Condition emailCondition = conditionsBuilder.equal(new QueryParameter(UserModel.EMAIL), email);
    ldapQuery.where(emailCondition);

    return ldapQuery.getFirstResult();
  }
Esempio n. 2
0
  public LDAPObject loadLDAPUserByUsername(RealmModel realm, String username) {
    LDAPQuery ldapQuery = LDAPUtils.createQueryForUserSearch(this, realm);
    LDAPQueryConditionsBuilder conditionsBuilder = new LDAPQueryConditionsBuilder();

    String usernameMappedAttribute = this.ldapIdentityStore.getConfig().getUsernameLdapAttribute();
    Condition usernameCondition = conditionsBuilder.equal(usernameMappedAttribute, username);
    ldapQuery.addWhereCondition(usernameCondition);

    LDAPObject ldapUser = ldapQuery.getFirstResult();
    if (ldapUser == null) {
      return null;
    }

    return ldapUser;
  }