Fetch keys from ldap.

        Args:
            username Username associated with keys to fetch (optional)

        Returns:
            Array of dictionaries in '{username: [public keys]}' format
188051
def get_keys_from_ldap(self, username=None):
        
        result_dict = {}
        filter = ['(sshPublicKey=*)']
        if username is not None:
            filter.append('(uid={})'.format(username))
        attributes = ['uid', 'sshPublicKey']
        results = self.client.search(filter, attributes)
        for result in results:
            result_dict[result.uid.value] = result.sshPublicKey.values
        return result_dict
522789
def get_or_create_user(self, username, ldap_user):
        
        model = self.get_user_model()
        username_field = getattr(model, 'USERNAME_FIELD', 'username')

        kwargs = {
            username_field + '__iexact': username,
            'defaults': {username_field: username.lower()}
        }

        return model.objects.get_or_create(**kwargs)
951817
def ldap_login(self, username, password):
        
        self.connect()

        if self.config.get('USER_SEARCH'):
            result = self.bind_search(username, password)
        else:
            result = self.direct_bind(username, password)
        return result
1086360
private RSAPublicKey getKeyForUser(String userName) throws KeyNotFoundException {
    RSAPublicKey key = null;
    for (final KeyProvider keyProvider : keyProviders) {
      try {
        key = keyProvider.getKey(userName);
        break;
      } catch (KeyNotFoundException e) {
        // that's fine, try the next provider
      }
    }

    if (key == null) {
      throw new KeyNotFoundException();
    }

    return key;
  }
192711
def _cache_key(self, attr_name):
        
        dn = self._ldap_user.dn.replace(' ', '%20')
        key = u'auth_ldap.%s.%s.%s' % (self.__class__.__name__, attr_name, dn)

        return key
142833
def get_random_user(self):
        
        from provider.models import User
        u = User.objects.order_by('?')[0]
        return {"username": u.username, "password": u.password, "fullname": u.fullname}
568832
def find_user_by_name(username):
    
    if db is not None:
        uid = db.hget('users', username)
        if uid:
            return get_user(uid)
    else:
        for uid, u in app.config['COIL_USERS'].items():
            if u['username'] == username:
                return get_user(uid)
596554
def passwd_keys(self, username):
        
        keys = []
        if username == 'mysql':
            log("Bad username '%s'" % (username), level=WARNING)

        if username:
            # IMPORTANT: *newer* format must be returned first
            keys.append('mysql-%s.passwd' % (username))
            keys.append('%s.passwd' % (username))
        else:
            keys.append('mysql.passwd')

        for key in keys:
            yield key
1361398
def all_ldap_groups(username)
      return [] if service.nil?
      results = service.search(base: group_tree,
                   filter: Net::LDAP::Filter.eq('objectcategory', 'group') &
                       Net::LDAP::Filter.ex('member:1.2.840.113556.1.4.1941',
                                            "CN=#{Net::LDAP::Filter.escape(username)},#{account_tree}"),
                   attributes: ['cn'])
      if results.nil?
        []
      else
        results.collect do |entry|
          entry[:cn].first
        end
      end
    end
583356
def get_authors(apikey, username, password):
    
    authenticate(username, password)
    return [author_structure(author)
            for author in Author.objects.filter(is_staff=True)]
630536
def get_ldap_user_membership(self, user_dn):
        """"""
        #Escape parenthesis in DN
        membership_filter = self.conf_LDAP_SYNC_GROUP_MEMBERSHIP_FILTER.replace('{distinguishedName}', user_dn.replace('(', "\(").replace(')', "\)"))
        try:
            uri, groups = self.ldap_search(membership_filter, self.conf_LDAP_SYNC_GROUP_ATTRIBUTES.keys(), False, membership_filter)
        except Exception as e:
            logger.error("Error reading membership: Filter %s, Keys %s" % (membership_filter, str(self.conf_LDAP_SYNC_GROUP_ATTRIBUTES.keys())))
            return None
        #logger.debug("AD Membership: Retrieved %d groups for user '%s'" % (len(groups), user_dn))
        return (uri, groups)
732232
def _key(self, username, frozen=False):
        """"""
        if frozen:
            return self.frozen + username
        return self.prefix + username
201213
def get_blocked_usernames():
    
    if config.DISABLE_USERNAME_LOCKOUT:
        # There are no blocked usernames since we disabled them.
        return []
    key = get_username_blocked_cache_key("*")
    key_list = [redis_key.decode('utf-8')
                for redis_key in REDIS_SERVER.keys(key)]
    return strip_keys(key_list)
152949
def get_by_username(cls, username):
        
        return cls.query.filter(
            UserProfile._username == username.lower()
        ).one()
843251
def get_user_api_key(self, username, create=True):
        
        retval = self._database.users.find_one({"username": username}, {"apikey": 1})
        if "apikey" not in retval and create:
            apikey = self.generate_api_key()
            self._database.users.update_one({"username": username}, {"$set": {"apikey": apikey}})
        elif "apikey" not in retval:
            apikey = None
        else:
            apikey = retval["apikey"]
        return apikey
231708
def load(username)
      options = {}
      options[:basic_auth] = @auth
      response = self.class.get("/user/#{username}", options)
      if response.success?
        self.response = response
        parse_response
        self
      else
        raise response.response
      end
    end
352685
def get(self, user_ids=None, usernames=None, status=None):
        
        return self.connection.get('user/array',
                                   user_ids=user_ids,
                                   usernames=usernames,
                                   status=status)