User LDAP attributes.
198759
def __ldap_attr(self, fname, lname, type, group,
                    group_api):  # pragma: no cover
        """"""
        return {
            'uid':
            str(self.username).encode(),
            'cn':
            ' '.join([fname, lname]).encode(),
            'sn':
            str(lname).encode(),
            'givenname':
            str(fname).encode(),
            'homedirectory':
            os.path.join(os.path.sep, 'home', self.username).encode(),
            'loginshell':
            os.path.join(os.path.sep, 'bin', 'bash').encode(),
            'mail':
            '@'.join([self.username, self.client.mail_domain]).encode(),
            'uidnumber':
            self.__uidnumber(type),
            'gidnumber':
            API.__gidnumber(group, group_api),
            'userpassword':
            str('{SSHA}' + API.__create_password().decode()).encode(),
        }
1115358
def dn_ous
            unless @dn_ous
                @dn_ous = []
                @ldap_object.dn.split(/,/).each do |entry|
                    @dn_ous.push entry.gsub(/OU=/, '').gsub(/CN=/,'') if entry =~ /OU=/ or entry == "CN=Users"
                end
            end
            @dn_ous
        end
708947
def _get_users(self, user_base):
        """""""
        results = self._search(
            getattr(self, '_%s_user_base' % user_base),
            '(objectClass=*)',
            ['*'],
            scope=ldap.SCOPE_ONELEVEL
        )
        for dn, attrs in results:
            uid = attrs.get('uid')[0].decode('utf-8', 'ignore')
            getattr(self, '_%s_users' % user_base)[uid] = FreeIPAUser(dn, attrs)
            # print(attrs)
        log.debug('%s users: %s' % (user_base.capitalize(), len(getattr(self, '_%s_users' % user_base))))
446922
def assign_provider_attrs(user, auth_hash)
      attrs = auth_hash['info'].slice(*user.attribute_names)
      user.assign_attributes(attrs)
    end
1267512
public function userPuidFromLdapEntry($ldap_entry) {

    if ($this->unique_persistent_attr
        && isset($ldap_entry[$this->unique_persistent_attr][0])
        && is_scalar($ldap_entry[$this->unique_persistent_attr][0])
        ) {
      $puid = $ldap_entry[$this->unique_persistent_attr][0];
      return ($this->unique_persistent_attr_binary) ? ldap_servers_binary($puid) : $puid;
    }
    else {
      return FALSE;
    }
  }
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
574605
def _config(name, key=None, **kwargs):
    '''
    
    '''
    if key is None:
        key = name
    if name in kwargs:
        value = kwargs[name]
    else:
        value = __salt__['config.option']('ldap.{0}'.format(key))
    return salt.utils.data.decode(value, to_str=True)
733610
def credentials(self):
        """"""
        if self.filename:
            db_filename = os.path.join(os.getcwd(), self.filename)
        else:
            db_filename = None

        return {
            "username": self.username,
            "password": self.password,
            "hostname": self.hostname,
            "port": self.port,
            "filename": db_filename,
            "dbname": self.dbname,
            "dbtype": self.dbtype,
            "schemas": self.schemas,
            "limit": self.limit,
            "keys_per_column": self.keys_per_column,
        }
200537
def auth(username, password):
    '''
    
    '''
    if not HAS_LDAP:
        log.error('LDAP authentication requires python-ldap module')
        return False

    bind = None

    # If bind credentials are configured, verify that we receive a valid bind
    if _config('binddn', mandatory=False) and _config('bindpw', mandatory=False):
        search_bind = _bind_for_search(anonymous=_config('anonymous', mandatory=False))

        # If username & password are not None, attempt to verify they are valid
        if search_bind and username and password:
            bind = _bind(username, password,
                         anonymous=_config('auth_by_group_membership_only', mandatory=False)
                         and _config('anonymous', mandatory=False))
    else:
        bind = _bind(username, password,
                     anonymous=_config('auth_by_group_membership_only', mandatory=False)
                     and _config('anonymous', mandatory=False))

    if bind:
        log.debug('LDAP authentication successful')
        return bind

    log.error('LDAP _bind authentication FAILED')
    return False
289415
def load_ldap_config(self):  # pragma: no cover
        """"""
        try:
            with open('{}/ldap_info.yaml'.format(self.config_dir),
                      'r') as FILE:
                config = yaml.load(FILE)
                self.host = config['server']
                self.user_dn = config['user_dn']
                self.port = config['port']
                self.basedn = config['basedn']
                self.mail_domain = config['mail_domain']
                self.service_ou = config['service_ou']
        except OSError as err:
            print('{}: Config file ({}/ldap_info.yaml) not found'.format(
                type(err), self.config_dir))
688304
def user_name_attributes(user, service):
    """"""
    attributes = {}
    attributes['username'] = user.get_username()
    attributes['full_name'] = user.get_full_name()
    attributes['short_name'] = user.get_short_name()
    return attributes
1009216
def _cache_key(self, attr_name):
        
        dn = self._ldap_user.dn
        return valid_cache_key(
            "auth_ldap.{}.{}.{}".format(self.__class__.__name__, attr_name, dn)
        )
1308038
def is_member(self, ldap_user, group_dn):
        
        try:
            user_uid = ldap_user.attrs["uid"][0]

            try:
                is_member = ldap_user.connection.compare_s(
                    group_dn, "memberUid", user_uid.encode()
                )
            except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
                is_member = False

            if not is_member:
                try:
                    user_gid = ldap_user.attrs["gidNumber"][0]
                    is_member = ldap_user.connection.compare_s(
                        group_dn, "gidNumber", user_gid.encode()
                    )
                except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
                    is_member = False
        except (KeyError, IndexError):
            is_member = False

        return is_member
1163669
def _search(self, base, fltr, attrs=None, scope=ldap.SCOPE_SUBTREE):
        """"""
        try:
            results = self._conn.search_s(base, scope, fltr, attrs)
        except Exception as e:
            log.exception(self._get_ldap_msg(e))
            results = False
        return results
485302
def basic_info(user, keys):
    """"""

    table = formatting.KeyValueTable(['Title', 'Basic Information'])
    table.align['Title'] = 'r'
    table.align['Basic Information'] = 'l'

    table.add_row(['Id', user.get('id', '-')])
    table.add_row(['Username', user.get('username', '-')])
    if keys:
        for key in user.get('apiAuthenticationKeys'):
            table.add_row(['APIKEY', key.get('authenticationKey')])
    table.add_row(['Name', "%s %s" % (user.get('firstName', '-'), user.get('lastName', '-'))])
    table.add_row(['Email', user.get('email')])
    table.add_row(['OpenID', user.get('openIdConnectUserName')])
    address = "%s %s %s %s %s %s" % (
        user.get('address1'), user.get('address2'), user.get('city'), user.get('state'),
        user.get('country'), user.get('postalCode'))
    table.add_row(['Address', address])
    table.add_row(['Company', user.get('companyName')])
    table.add_row(['Created', user.get('createDate')])
    table.add_row(['Phone Number', user.get('officePhone')])
    if user.get('parentId', False):
        table.add_row(['Parent User', utils.lookup(user, 'parent', 'username')])
    table.add_row(['Status', utils.lookup(user, 'userStatus', 'name')])
    table.add_row(['PPTP VPN', user.get('pptpVpnAllowedFlag', 'No')])
    table.add_row(['SSL VPN', user.get('sslVpnAllowedFlag', 'No')])
    for login in user.get('unsuccessfulLogins', {}):
        login_string = "%s From: %s" % (login.get('createDate'), login.get('ipAddress'))
        table.add_row(['Last Failed Login', login_string])
        break
    for login in user.get('successfulLogins', {}):
        login_string = "%s From: %s" % (login.get('createDate'), login.get('ipAddress'))
        table.add_row(['Last Login', login_string])
        break

    return table
399454
public List<String> getAttributes() throws GuacamoleException {
        return environment.getProperty(
            LDAPGuacamoleProperties.LDAP_USER_ATTRIBUTES,
            Collections.<String>emptyList()
        );
    }
593676
def write_user(user):
    

    udata = {}

    for f in USER_FIELDS:
        udata[f] = getattr(user, f)

    for p in PERMISSIONS:
        udata[p] = '1' if getattr(user, p) else '0'
    db.hmset('user:{0}'.format(user.uid), udata)