def authenticate(self):
<EOL>if self._authenticated is not None:<EOL><INDENT>return self._authenticated<EOL><DEDENT>try:<EOL><INDENT>self._ldap_conn.simple_bind_s(self._ldap_binddn_fmt.format(ldap.dn.escape_dn_chars(self.username)), self.password)<EOL><DEDENT>except ldap.SERVER_DOWN as exc:<EOL><INDENT>raise AuthError('<STR_LIT>')<EOL><DEDENT>except (ldap.INVALID_CREDENTIALS, ldap.INVALID_DN_SYNTAX,<EOL>ldap.UNWILLING_TO_PERFORM) as exc:<EOL><INDENT>self._logger.debug('<STR_LIT>' % self.username)<EOL>self._authenticated = False<EOL>return self._authenticated<EOL><DEDENT>self.authenticated_as = self.username<EOL>self.trusted = False<EOL>self.readonly = False<EOL>try:<EOL><INDENT>if self._ldap_search_conn is not None:<EOL><INDENT>self._ldap_search_conn.simple_bind(self._ldap_search_binddn, self._ldap_search_password)<EOL>search_conn = self._ldap_search_conn<EOL><DEDENT>else:<EOL><INDENT>search_conn = self._ldap_conn<EOL><DEDENT>res = search_conn.search_s(self._ldap_basedn, ldap.SCOPE_SUBTREE, self._ldap_search.format(ldap.dn.escape_dn_chars(self.username)), ['<STR_LIT>','<STR_LIT>'])<EOL>if res[<NUM_LIT:0>][<NUM_LIT:1>]['<STR_LIT>'][<NUM_LIT:0>] is not None:<EOL><INDENT>self.full_name = res[<NUM_LIT:0>][<NUM_LIT:1>]['<STR_LIT>'][<NUM_LIT:0>].decode('<STR_LIT:utf-8>')<EOL><DEDENT>if self._ldap_ro_group:<EOL><INDENT>if self._ldap_ro_group in res[<NUM_LIT:0>][<NUM_LIT:1>].get('<STR_LIT>', []):<EOL><INDENT>self.readonly = True<EOL><DEDENT><DEDENT>if self._ldap_rw_group:<EOL><INDENT>if self._ldap_rw_group in res[<NUM_LIT:0>][<NUM_LIT:1>].get('<STR_LIT>', []):<EOL><INDENT>self.readonly = False<EOL><DEDENT>else:<EOL><INDENT>if self._ldap_ro_group:<EOL><INDENT>if self._ldap_ro_group not in res[<NUM_LIT:0>][<NUM_LIT:1>].get('<STR_LIT>', []):<EOL><INDENT>self._authenticated = False<EOL>return self._authenticated<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.readonly = True<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except ldap.LDAPError as exc:<EOL><INDENT>raise AuthError(exc)<EOL><DEDENT>except KeyError:<EOL><INDENT>raise AuthError('<STR_LIT>')<EOL><DEDENT>except IndexError:<EOL><INDENT>self.full_name = '<STR_LIT>'<EOL>if self._ldap_rw_group or self._ldap_ro_group:<EOL><INDENT>self._authenticated = False<EOL>return self._authenticated<EOL><DEDENT><DEDENT>self._authenticated = True<EOL>self._logger.debug('<STR_LIT>' % (self.authenticated_as, self.username, self.full_name, str(self.readonly)))<EOL>return self._authenticated<EOL>
Verify authentication.

            Returns True/False dependant on whether the authentication
            succeeded or not.