initial work
This commit is contained in:
parent
8c885b2b24
commit
81e55a2134
13 changed files with 335 additions and 0 deletions
22
hub/broker/authentication.py
Normal file
22
hub/broker/authentication.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from rest_framework.authentication import BasicAuthentication
|
||||
from rest_framework.exceptions import AuthenticationFailed
|
||||
from django.contrib.auth.models import User
|
||||
from .models import ServiceBrokerUser
|
||||
|
||||
|
||||
class ServiceBrokerAuthentication(BasicAuthentication):
|
||||
def authenticate_credentials(self, userid, password, request=None):
|
||||
try:
|
||||
user = User.objects.get(username=userid)
|
||||
if not user.check_password(password):
|
||||
raise AuthenticationFailed("Invalid password")
|
||||
|
||||
# Ensure user has broker permissions
|
||||
try:
|
||||
broker_user = ServiceBrokerUser.objects.get(user=user)
|
||||
except ServiceBrokerUser.DoesNotExist:
|
||||
raise AuthenticationFailed("User is not authorized for broker access")
|
||||
|
||||
return (user, None)
|
||||
except User.DoesNotExist:
|
||||
raise AuthenticationFailed("Invalid username")
|
Loading…
Add table
Add a link
Reference in a new issue