summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-03-04 00:49:17 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-03-04 00:49:17 -0400
commit78a43c5bc733fbb27f38b06d10e792283abcdb93 (patch)
tree2d4f92fac54c76413121654b5ce518c7e6dcd960
parent7422ca85177f11d8b74b28c58786aebf2ffe801b (diff)
move decorator to session
-rw-r--r--src/leap/bonafide/_decorators.py33
-rw-r--r--src/leap/bonafide/session.py22
2 files changed, 18 insertions, 37 deletions
diff --git a/src/leap/bonafide/_decorators.py b/src/leap/bonafide/_decorators.py
deleted file mode 100644
index 6b43715..0000000
--- a/src/leap/bonafide/_decorators.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# -*- coding: utf-8 -*-
-# _decorators.py
-# Copyright (C) 2015 LEAP
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-Decorators used in bonafide.
-"""
-
-
-def auth_required(func):
- """
- Decorate a method so that it will not be called if the instance
- attribute `is_authenticated` does not evaluate to True.
- """
- def decorated(*args, **kwargs):
- instance = args[0]
- allowed = getattr(instance, 'is_authenticated')
- if not allowed:
- raise RuntimeError('This method requires authentication')
- return func(*args, **kwargs)
- return decorated
diff --git a/src/leap/bonafide/session.py b/src/leap/bonafide/session.py
index 7c40d28..547f0dd 100644
--- a/src/leap/bonafide/session.py
+++ b/src/leap/bonafide/session.py
@@ -22,12 +22,25 @@ from twisted.python import log
from leap.bonafide import _srp
from leap.bonafide import provider
-from leap.bonafide._decorators import auth_required
from leap.bonafide._http import httpRequest, cookieAgentFactory
OK = 'ok'
+def _auth_required(func):
+ """
+ Decorate a method so that it will not be called if the instance
+ attribute `is_authenticated` does not evaluate to True.
+ """
+ def decorated(*args, **kwargs):
+ instance = args[0]
+ allowed = getattr(instance, 'is_authenticated')
+ if not allowed:
+ raise RuntimeError('This method requires authentication')
+ return func(*args, **kwargs)
+ return decorated
+
+
class Session(object):
def __init__(self, credentials, api, provider_cert):
@@ -101,7 +114,7 @@ class Session(object):
self._token = token
defer.returnValue(OK)
- @auth_required
+ @_auth_required
@defer.inlineCallbacks
def logout(self):
uri = self._api.get_logout_uri()
@@ -121,7 +134,7 @@ class Session(object):
met = self._api.get_vpn_cert_method()
return self._request(self._agent, uri, method=met)
- @auth_required
+ @_auth_required
def get_smtp_cert(self):
# TODO pass it to the provider object so that it can save it in the
# right path.
@@ -152,8 +165,9 @@ class Session(object):
self.password = password
defer.returnValue((OK, registered_user))
- @auth_required
+ @_auth_required
def update_user_record(self):
+ # FIXME to be implemented
pass
# Authentication-protected configuration