1 # -*- coding: utf-8 -*-
4 Authconn implements an Abstract class for the Auth backend connector
5 plugins with the definition of the methods to be implemented.
8 __author__
= "Eduardo Sousa <eduardosousa@av.it.pt>"
9 __date__
= "$27-jul-2018 23:59:59$"
11 from http
import HTTPStatus
14 class AuthconnException(Exception):
16 Common and base class Exception for all authconn exceptions.
18 def __init__(self
, message
, http_code
=HTTPStatus
.UNAUTHORIZED
):
19 Exception.__init
__(message
)
20 self
.http_code
= http_code
23 class AuthconnConnectionException(AuthconnException
):
25 Connectivity error with Auth backend.
27 def __init__(self
, message
, http_code
=HTTPStatus
.UNAUTHORIZED
):
28 AuthconnException
.__init
__(self
, message
, http_code
)
31 class AuthconnNotSupportedException(AuthconnException
):
33 The request is not supported by the Auth backend.
35 def __init__(self
, message
, http_code
=HTTPStatus
.UNAUTHORIZED
):
36 AuthconnException
.__init
__(self
, message
, http_code
)
39 class AuthconnNotImplementedException(AuthconnException
):
41 The method is not implemented by the Auth backend.
43 def __init__(self
, message
, http_code
=HTTPStatus
.UNAUTHORIZED
):
44 AuthconnException
.__init
__(self
, message
, http_code
)
49 Abstract base class for all the Auth backend connector plugins.
50 Each Auth backend connector plugin must be a subclass of
53 def __init__(self
, config
):
55 Constructor of the Authconn class.
59 :param config: configuration dictionary containing all the
60 necessary configuration parameters.
64 def authenticate_with_user_password(self
, user
, password
):
66 Authenticate a user using username and password.
69 :param password: password
70 :return: an unscoped token that grants access to project list
72 raise AuthconnNotImplementedException("Should have implemented this")
74 def authenticate_with_token(self
, token
, project
=None):
76 Authenticate a user using a token. Can be used to revalidate the token
77 or to get a scoped token.
79 :param token: a valid token.
80 :param project: (optional) project for a scoped token.
81 :return: return a revalidated token, scoped if a project was passed or
82 the previous token was already scoped.
84 raise AuthconnNotImplementedException("Should have implemented this")
86 def validate_token(self
, token
):
88 Check if the token is valid.
90 :param token: token to validate
91 :return: dictionary with information associated with the token. If the
92 token is not valid, returns None.
94 raise AuthconnNotImplementedException("Should have implemented this")
96 def revoke_token(self
, token
):
100 :param token: token to be revoked
102 raise AuthconnNotImplementedException("Should have implemented this")
104 def get_project_list(self
, token
):
106 Get all the projects associated with a user.
108 :param token: valid token
109 :return: list of projects
111 raise AuthconnNotImplementedException("Should have implemented this")
113 def get_role_list(self
, token
):
115 Get role list for a scoped project.
117 :param token: scoped token.
118 :return: returns the list of roles for the user in that project. If
119 the token is unscoped it returns None.
121 raise AuthconnNotImplementedException("Should have implemented this")
123 def create_user(self
, user
, password
):
127 :param user: username.
128 :param password: password.
129 :return: boolean to indicate if operation was successful.
131 raise AuthconnNotImplementedException("Should have implemented this")
133 def change_password(self
, user
, old_password
, new_password
):
135 Change the user password.
137 :param user: username.
138 :param old_password: old password.
139 :param new_password: new password.
140 :return: boolean to indicate if operation was successful.
142 raise AuthconnNotImplementedException("Should have implemented this")
144 def delete_user(self
, user
):
148 :param user: username.
149 :return: boolean to indicate if operation was successful.
151 raise AuthconnNotImplementedException("Should have implemented this")
153 def create_role(self
, role
):
157 :param role: role name.
158 :return: boolean to indicate if operation was successful.
160 raise AuthconnNotImplementedException("Should have implemented this")
162 def delete_role(self
, role
):
166 :param role: role name.
167 :return: boolean to indicate if operation was successful.
169 raise AuthconnNotImplementedException("Should have implemented this")
171 def create_project(self
, project
):
175 :param project: project name.
176 :return: boolean to indicate if operation was successful.
178 raise AuthconnNotImplementedException("Should have implemented this")
180 def delete_project(self
, project
):
184 :param project: project name.
185 :return: boolean to indicate if operation was successful.
187 raise AuthconnNotImplementedException("Should have implemented this")
189 def assign_role_to_user(self
, user
, project
, role
):
191 Assigning a role to a user in a project.
193 :param user: username.
194 :param project: project name.
195 :param role: role name.
196 :return: boolean to indicate if operation was successful.
198 raise AuthconnNotImplementedException("Should have implemented this")