Skip to content

Commit b553e28

Browse files
authored
Merge pull request #159 from zhenlineo/1.3-kerberos-auth
Adding kerberos token support
2 parents 64cbfa5 + 4999a80 commit b553e28

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

neo4j/bolt/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def __init__(self, sock, **config):
164164
self.auth_dict = vars(basic_auth(*auth))
165165
else:
166166
try:
167-
self.auth_dict = vars(config["auth"])
167+
self.auth_dict = vars(auth)
168168
except (KeyError, TypeError):
169169
raise TypeError("Cannot determine auth details from %r" % auth)
170170

neo4j/v1/security.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ def basic_auth(user, password, realm=None):
103103
return AuthToken("basic", user, password, realm)
104104

105105

106+
def kerberos_auth(base64_encoded_ticket):
107+
""" Generate a kerberos auth token with the base64 encoded ticket
108+
109+
:param base64_encoded_ticket: a base64 encoded service ticket
110+
:return: an authentication token that can be used to connect to Neo4j
111+
"""
112+
return AuthToken("kerberos", "", base64_encoded_ticket)
113+
114+
106115
def custom_auth(principal, credentials, realm, scheme, **parameters):
107116
""" Generate a basic auth token for a given user and password.
108117

test/unit/test_security.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2017 "Neo Technology,"
5+
# Network Engine for Objects in Lund AB [http://neotechnology.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
from unittest import TestCase
22+
from neo4j.v1.security import kerberos_auth, basic_auth, custom_auth
23+
24+
class AuthTokenTestCase(TestCase):
25+
26+
def test_should_generate_kerberos_auth_token_correctly(self):
27+
auth = kerberos_auth("I am a base64 service ticket")
28+
assert auth.scheme == "kerberos"
29+
assert auth.principal == ""
30+
assert auth.credentials == "I am a base64 service ticket"
31+
assert not auth.realm
32+
assert not hasattr(auth, "parameters")
33+
34+
def test_should_generate_basic_auth_without_realm_correctly(self):
35+
auth = basic_auth("molly", "meoooow")
36+
assert auth.scheme == "basic"
37+
assert auth.principal == "molly"
38+
assert auth.credentials == "meoooow"
39+
assert not auth.realm
40+
assert not hasattr(auth, "parameters")
41+
42+
def test_should_generate_base_auth_with_realm_correctly(self):
43+
auth = basic_auth("molly", "meoooow", "cat_caffe")
44+
assert auth.scheme == "basic"
45+
assert auth.principal == "molly"
46+
assert auth.credentials == "meoooow"
47+
assert auth.realm == "cat_caffe"
48+
assert not hasattr(auth, "parameters")
49+
50+
def test_should_generate_custom_auth_correctly(self):
51+
auth = custom_auth("molly", "meoooow", "cat_caffe", "cat", age="1", color="white")
52+
assert auth.scheme == "cat"
53+
assert auth.principal == "molly"
54+
assert auth.credentials == "meoooow"
55+
assert auth.realm == "cat_caffe"
56+
assert auth.parameters == {"age": "1", "color": "white"}

0 commit comments

Comments
 (0)