#!/usr/bin/env python

from dm.common.constants import dmRole
from dm.common.utility.loggingManager import LoggingManager

class AuthorizationPrincipalRetriever:

    def __init__(self, name=None):
        self.name = name
        self.logger = LoggingManager.getInstance().getLogger(self.__class__.__name__)

    def getName(self):
        return self.name

    def getAuthorizationPrincipal(self, username):
        return None

    def setAuthorizationPrincipalSessionRole(self, principal):
        if principal is None:
            return
        for userSystemRoleId in principal.get('userSystemRoleDict', {}).keys():
            if userSystemRoleId == dmRole.DM_ADMIN_SYSTEM_ROLE_ID:
                principal.setSessionRole(dmRole.DM_ADMIN_SESSION_ROLE)
                return
        principal.setSessionRole(dmRole.DM_USER_SESSION_ROLE)


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