Commit a70404e6 authored by Antoine Millet's avatar Antoine Millet
Browse files

[bug#3921] Roles checking.

parent f1965ab3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -24,3 +24,6 @@ class NotConnectedAccountError(Exception):

class ReservedTagError(Exception):
    pass

class BadRoleError(Exception):
    pass
+9 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import logging
from sjrpc.utils import RpcHandler, pure
from conf import CCConf
from exceptions import (AlreadyRegistered, AuthenticationError, RightError,
                        ReservedTagError, BadObjectError,
                        ReservedTagError, BadObjectError, BadRoleError,
                        NotConnectedAccountError)

def listed(func):
@@ -196,7 +196,10 @@ class CliHandler(OnlineCCHandler):
        '''
        Create a new account with specified login.
        '''
        if role in WelcomeHandler.ROLES:
            self._server.conf.create_account(login, role, password)
        else:
            raise BadRoleError('%r is not a legal role.' % role)

    @listed
    def addtag(self, conn, query, tag_name, tag_value):
@@ -452,6 +455,7 @@ class WelcomeHandler(CCHandler):
    ROLES = {
        'cli': CliHandler,
        'hv': HypervisorHandler,
        'host': None,
    }

    @listed
@@ -469,6 +473,9 @@ class WelcomeHandler(CCHandler):
                if 'close' in self._server.conf.show(login)['tags']:
                    raise AuthenticationError('Account is closed')

        if role not in WelcomeHandler.ROLES:
            raise BadRoleError('%r is not a legal role' % role)

        if role is None:
            logging.info('New authentication from %s: failure',
                         login.encode('ascii', 'ignore'))