Skip to content

Adding kerberos token support #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion neo4j/bolt/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(self, sock, **config):
self.auth_dict = vars(basic_auth(*auth))
else:
try:
self.auth_dict = vars(config["auth"])
self.auth_dict = vars(auth)
except (KeyError, TypeError):
raise TypeError("Cannot determine auth details from %r" % auth)

Expand Down
9 changes: 9 additions & 0 deletions neo4j/v1/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def basic_auth(user, password, realm=None):
return AuthToken("basic", user, password, realm)


def kerberos_auth(base64_encoded_ticket):
""" Generate a kerberos auth token with the base64 encoded ticket

:param base64_encoded_ticket: a base64 encoded service ticket
:return: an authentication token that can be used to connect to Neo4j
"""
return AuthToken("kerberos", "", base64_encoded_ticket)


def custom_auth(principal, credentials, realm, scheme, **parameters):
""" Generate a basic auth token for a given user and password.

Expand Down
56 changes: 56 additions & 0 deletions test/unit/test_security.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

# Copyright (c) 2002-2017 "Neo Technology,"
# Network Engine for Objects in Lund AB [http://neotechnology.com]
#
# This file is part of Neo4j.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import TestCase
from neo4j.v1.security import kerberos_auth, basic_auth, custom_auth

class AuthTokenTestCase(TestCase):

def test_should_generate_kerberos_auth_token_correctly(self):
auth = kerberos_auth("I am a base64 service ticket")
assert auth.scheme == "kerberos"
assert auth.principal == ""
assert auth.credentials == "I am a base64 service ticket"
assert not auth.realm
assert not hasattr(auth, "parameters")

def test_should_generate_basic_auth_without_realm_correctly(self):
auth = basic_auth("molly", "meoooow")
assert auth.scheme == "basic"
assert auth.principal == "molly"
assert auth.credentials == "meoooow"
assert not auth.realm
assert not hasattr(auth, "parameters")

def test_should_generate_base_auth_with_realm_correctly(self):
auth = basic_auth("molly", "meoooow", "cat_caffe")
assert auth.scheme == "basic"
assert auth.principal == "molly"
assert auth.credentials == "meoooow"
assert auth.realm == "cat_caffe"
assert not hasattr(auth, "parameters")

def test_should_generate_custom_auth_correctly(self):
auth = custom_auth("molly", "meoooow", "cat_caffe", "cat", age="1", color="white")
assert auth.scheme == "cat"
assert auth.principal == "molly"
assert auth.credentials == "meoooow"
assert auth.realm == "cat_caffe"
assert auth.parameters == {"age": "1", "color": "white"}