Automatic authentification for client implemented
This commit is contained in:
parent
f4a7f1e7a4
commit
a972e90c85
14
__init__.py
14
__init__.py
@ -180,8 +180,9 @@ class struct_json_protocol(object):
|
|||||||
AUTH_STATE_KEY_TRANSFERRED: 'Key has been sent',
|
AUTH_STATE_KEY_TRANSFERRED: 'Key has been sent',
|
||||||
AUTH_STATE_TRUSTED_CLIENT: 'Trusted Client'}
|
AUTH_STATE_TRUSTED_CLIENT: 'Trusted Client'}
|
||||||
|
|
||||||
def __init__(self, comm_instance, secret=None):
|
def __init__(self, comm_instance, secret=None, auto_auth=False):
|
||||||
self.__secret__ = secret
|
self.__secret__ = secret
|
||||||
|
self.__auto_auth__ = auto_auth
|
||||||
self.__clean_receive_buffer__()
|
self.__clean_receive_buffer__()
|
||||||
self.__callbacks__ = callback_storage()
|
self.__callbacks__ = callback_storage()
|
||||||
self.__callbacks__.add(self.SID_AUTH_SEED_REQUEST, 0, self.__authentificate_create_seed__)
|
self.__callbacks__.add(self.SID_AUTH_SEED_REQUEST, 0, self.__authentificate_create_seed__)
|
||||||
@ -192,7 +193,7 @@ class struct_json_protocol(object):
|
|||||||
self.__seed__ = None
|
self.__seed__ = None
|
||||||
self.__comm_inst__ = comm_instance
|
self.__comm_inst__ = comm_instance
|
||||||
self.__comm_inst__.register_callback(self.__data_available_callback__)
|
self.__comm_inst__.register_callback(self.__data_available_callback__)
|
||||||
self.__comm_inst__.register_connect_callback(self.__clean_receive_buffer__)
|
self.__comm_inst__.register_connect_callback(self.__connection_established__)
|
||||||
self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
|
self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
|
||||||
|
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
@ -201,6 +202,11 @@ class struct_json_protocol(object):
|
|||||||
def reconnect(self):
|
def reconnect(self):
|
||||||
return self.__comm_inst__.reconnect()
|
return self.__comm_inst__.reconnect()
|
||||||
|
|
||||||
|
def __connection_established__(self):
|
||||||
|
self.__clean_receive_buffer__()
|
||||||
|
if self.__auto_auth__ and self.__comm_inst__.IS_CLIENT and self.__secret__ is not None:
|
||||||
|
self.authentificate()
|
||||||
|
|
||||||
def __authentification_state_reset__(self):
|
def __authentification_state_reset__(self):
|
||||||
logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.LOG_PREFIX)
|
logger.info("%s Resetting authentification state to AUTH_STATE_UNKNOWN_CLIENT", self.LOG_PREFIX)
|
||||||
self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
|
self.__authentification_state__ = self.AUTH_STATE_UNKNOWN_CLIENT
|
||||||
@ -468,8 +474,8 @@ class pure_json_protocol(struct_json_protocol):
|
|||||||
|
|
||||||
.. literalinclude:: ../../socket_protocol/_examples_/socket_protocol__pure_json_protocol_client.log
|
.. literalinclude:: ../../socket_protocol/_examples_/socket_protocol__pure_json_protocol_client.log
|
||||||
"""
|
"""
|
||||||
def __init__(self, comm_instance, secret=None):
|
def __init__(self, *args, **kwargs):
|
||||||
struct_json_protocol.__init__(self, comm_instance, secret)
|
struct_json_protocol.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def __build_frame__(self, service_id, data_id, data, status=struct_json_protocol.STATUS_OKAY):
|
def __build_frame__(self, service_id, data_id, data, status=struct_json_protocol.STATUS_OKAY):
|
||||||
data_frame = json.dumps(self.__mk_msg__(status, service_id, data_id, data))
|
data_frame = json.dumps(self.__mk_msg__(status, service_id, data_id, data))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user