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 <esousa@whitestack.com>"
9 __date__
= "$27-jul-2018 23:59:59$"
11 from http
import HTTPStatus
14 class AuthException(Exception):
18 def __init__(self
, message
, http_code
=HTTPStatus
.UNAUTHORIZED
):
19 self
.http_code
= http_code
20 Exception.__init
__(self
, message
)
23 class AuthconnException(Exception):
25 Common and base class Exception for all authconn exceptions.
27 def __init__(self
, message
, http_code
=HTTPStatus
.UNAUTHORIZED
):
28 Exception.__init
__(message
)
29 self
.http_code
= http_code
32 class AuthconnConnectionException(AuthconnException
):
34 Connectivity error with Auth backend.
36 def __init__(self
, message
, http_code
=HTTPStatus
.BAD_GATEWAY
):
37 AuthconnException
.__init
__(self
, message
, http_code
)
40 class AuthconnNotSupportedException(AuthconnException
):
42 The request is not supported by the Auth backend.
44 def __init__(self
, message
, http_code
=HTTPStatus
.NOT_IMPLEMENTED
):
45 AuthconnException
.__init
__(self
, message
, http_code
)
48 class AuthconnNotImplementedException(AuthconnException
):
50 The method is not implemented by the Auth backend.
52 def __init__(self
, message
, http_code
=HTTPStatus
.NOT_IMPLEMENTED
):
53 AuthconnException
.__init
__(self
, message
, http_code
)
56 class AuthconnOperationException(AuthconnException
):
58 The operation executed failed.
60 def __init__(self
, message
, http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
):
61 AuthconnException
.__init
__(self
, message
, http_code
)
66 Abstract base class for all the Auth backend connector plugins.
67 Each Auth backend connector plugin must be a subclass of
70 def __init__(self
, config
):
72 Constructor of the Authconn class.
76 :param config: configuration dictionary containing all the
77 necessary configuration parameters.
81 def authenticate_with_user_password(self
, user
, password
):
83 Authenticate a user using username and password.
86 :param password: password
87 :return: an unscoped token that grants access to project list
89 raise AuthconnNotImplementedException("Should have implemented this")
91 def authenticate_with_token(self
, token
, project
=None):
93 Authenticate a user using a token. Can be used to revalidate the token
94 or to get a scoped token.
96 :param token: a valid token.
97 :param project: (optional) project for a scoped token.
98 :return: return a revalidated token, scoped if a project was passed or
99 the previous token was already scoped.
101 raise AuthconnNotImplementedException("Should have implemented this")
103 def validate_token(self
, token
):
105 Check if the token is valid.
107 :param token: token to validate
108 :return: dictionary with information associated with the token. If the
109 token is not valid, returns None.
111 raise AuthconnNotImplementedException("Should have implemented this")
113 def revoke_token(self
, token
):
117 :param token: token to be revoked
119 raise AuthconnNotImplementedException("Should have implemented this")
121 def get_project_list(self
, token
):
123 Get all the projects associated with a user.
125 :param token: valid token
126 :return: list of projects
128 raise AuthconnNotImplementedException("Should have implemented this")
130 def get_role_list(self
, token
):
132 Get role list for a scoped project.
134 :param token: scoped token.
135 :return: returns the list of roles for the user in that project. If
136 the token is unscoped it returns None.
138 raise AuthconnNotImplementedException("Should have implemented this")
140 def create_user(self
, user
, password
):
144 :param user: username.
145 :param password: password.
146 :raises AuthconnOperationException: if user creation failed.
148 raise AuthconnNotImplementedException("Should have implemented this")
150 def change_password(self
, user
, new_password
):
152 Change the user password.
154 :param user: username.
155 :param new_password: new password.
156 :raises AuthconnOperationException: if user password change failed.
158 raise AuthconnNotImplementedException("Should have implemented this")
160 def delete_user(self
, user
):
164 :param user: username.
165 :raises AuthconnOperationException: if user deletion failed.
167 raise AuthconnNotImplementedException("Should have implemented this")
169 def create_role(self
, role
):
173 :param role: role name.
174 :raises AuthconnOperationException: if role creation failed.
176 raise AuthconnNotImplementedException("Should have implemented this")
178 def delete_role(self
, role
):
182 :param role: role name.
183 :raises AuthconnOperationException: if user deletion failed.
185 raise AuthconnNotImplementedException("Should have implemented this")
187 def create_project(self
, project
):
191 :param project: project name.
192 :raises AuthconnOperationException: if project creation failed.
194 raise AuthconnNotImplementedException("Should have implemented this")
196 def delete_project(self
, project
):
200 :param project: project name.
201 :raises AuthconnOperationException: if project deletion failed.
203 raise AuthconnNotImplementedException("Should have implemented this")
205 def assign_role_to_user(self
, user
, project
, role
):
207 Assigning a role to a user in a project.
209 :param user: username.
210 :param project: project name.
211 :param role: role name.
212 :raises AuthconnOperationException: if role assignment failed.
214 raise AuthconnNotImplementedException("Should have implemented this")
216 def remove_role_from_user(self
, user
, project
, role
):
218 Remove a role from a user in a project.
220 :param user: username.
221 :param project: project name.
222 :param role: role name.
223 :raises AuthconnOperationException: if role assignment revocation failed.
225 raise AuthconnNotImplementedException("Should have implemented this")