Skip to content
Snippets Groups Projects
noOpPrincipalRetriever.py 1022 B
Newer Older
#!/usr/bin/env python

from dm.common.constants import dmRole
from dm.common.objects.authorizationPrincipal import AuthorizationPrincipal
from dm.common.utility.cryptUtility import CryptUtility
from authorizationPrincipalRetriever import AuthorizationPrincipalRetriever 

class NoOpPrincipalRetriever(AuthorizationPrincipalRetriever):

    def __init__(self):
        AuthorizationPrincipalRetriever.__init__(self, self.__class__.__name__)

    def getAuthorizationPrincipal(self, username):
        # Set password to be the same as username
        noOpPassword = CryptUtility.cryptPasswordWithPbkdf2(username)
        principal = AuthorizationPrincipal(name=username, token=noOpPassword)
        principal.setUserSystemRoleDict({dmRole.DM_ADMIN_SYSTEM_ROLE_ID:[]})
        principal.setUserExperimentRoleDict({})
        self.setAuthorizationPrincipalSessionRole(principal)
        return principal

#######################################################################
# Testing.
if __name__ == '__main__':
    pass