Skip to content

Commit fe64fe1

Browse files
authored
Token providers can use the member address for token creation (#455)
Token providers can use the member address for token creation
1 parent 5603400 commit fe64fe1

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

docs/securing_client_connection.rst

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -330,28 +330,6 @@ The package provides the necessary token provider that handles the
330330
authentication against the KDC (key distribution center) with the given
331331
credentials, receives and caches the ticket, and finally retrieves the token.
332332

333-
You can install the package from PyPI.
334-
335-
.. code:: bash
336-
337-
pip install hazelcast-kerberos
338-
339-
A sample code that makes use of the package is below.
340-
341-
.. code:: python
342-
343-
import hazelcast
344-
import hzkerberos
345-
346-
token_provider = hzkerberos.TokenProvider(
347-
principal="hz/172.17.0.2@EXAMPLE.COM",
348-
keytab="/etc/krb5.keytab",
349-
)
350-
351-
client = hazelcast.HazelcastClient(
352-
token_provider=token_provider
353-
)
354-
355333
For more information and possible client and server configurations, refer to
356-
the `documentation <https://pypi.org/project/hazelcast-kerberos/>`__ of the
334+
the `documentation <https://github.com/hazelcast/hazelcast-python-client-kerberos>`__ of the
357335
``hazelcast-kerberos`` package.

hazelcast/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,10 @@ def _authenticate(self, connection):
491491
cluster_name = self._config.cluster_name
492492
client_name = client.name
493493
if self._config.token_provider:
494+
token = self._config.token_provider.token(connection.connected_address)
494495
request = client_authentication_custom_codec.encode_request(
495496
cluster_name,
496-
self._config.token_provider.token(),
497+
token,
497498
self.client_uuid,
498499
CLIENT_TYPE,
499500
SERIALIZATION_VERSION,

hazelcast/security.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
from hazelcast.six import string_types
2+
from hazelcast.core import Address
23

34

45
class TokenProvider(object):
56
"""TokenProvider is a base class for token providers."""
67

7-
def token(self):
8-
# type: (TokenProvider) -> bytes
8+
def token(self, address=None):
9+
# type: (TokenProvider, Address) -> bytes
910
"""Returns a token to be used for token-based authentication.
1011
12+
Args:
13+
address (hazelcast.core.Address): Connected address for the member.
14+
1115
Returns:
1216
bytes: token as a bytes object.
1317
"""
@@ -25,11 +29,5 @@ def __init__(self, token=""):
2529
else:
2630
raise TypeError("token must be either a str or bytes object")
2731

28-
def token(self):
29-
# type: (BasicTokenProvider) -> bytes
30-
"""Returns a token to be used for token-based authentication.
31-
32-
Returns:
33-
bytes: token as a bytes object.
34-
"""
32+
def token(self, address=None):
3533
return self._token

0 commit comments

Comments
 (0)