Example #1
0
    def _mapRawResult(self, rawResult):
        """ Prepare LDAP query result. """

        mappedResult = list()
        for item in rawResult:
            uniqueName = self._configuration.domain + _DOMAIN_SEPARATOR + unicode(
                item[0][0], self._configuration.encoding)
            displayName = ""
            if not item[2][0] is None:
                displayName = unicode(item[2][0], self._configuration.encoding)
            if _LDAP_PROPERTY_OBJECT_CLASS_USER_VALUE in item[1]:
                principalType = constants.USER_PRINCIPAL_TYPE
            else:
                principalType = constants.GROUP_PRINCIPAL_TYPE
            memberOf = list()
            if not item[3] is None:
                for member in item[3]:
                    if not member is None:
                        uniqueMemberName = self._configuration.domain + _DOMAIN_SEPARATOR + unicode(
                            member, self._configuration.encoding)
                        member = principal.Principal(
                            uniqueMemberName,
                            type=constants.GROUP_PRINCIPAL_TYPE)
                        memberOf.append(member)
            principal_ = principal.Principal(uniqueName,
                                             type=principalType,
                                             displayName=displayName,
                                             roles=memberOf)
            mappedResult.append(principal_)
        return mappedResult
Example #2
0
    def _mapPersistencePrincipal(self, principal_):
        """ Maps the WebDAV representation of a principal to the interface-specific. """

        mappedPrincipal = principal.Principal(None)
        if not principal_.property is None and principal_.property in _webdavToGeneralPrincipalMap.keys(
        ):
            mappedPrincipal = principal.Principal(
                _webdavToGeneralPrincipalMap[principal_.property],
                type=principal_constants.GROUP_PRINCIPAL_TYPE)
        elif not principal_.principalURL is None:
            if self._userUrl in principal_.principalURL:
                principalType = principal_constants.USER_PRINCIPAL_TYPE
            else:
                principalType = principal_constants.GROUP_PRINCIPAL_TYPE
            mappedPrincipal = principal.Principal(os.path.basename(
                principal_.principalURL),
                                                  type=principalType)
        return mappedPrincipal
Example #3
0
 def testCreate(self):
     """ Tests the creation of an ACE. """
     
     persistenceAce = SimpleMock()
     persistenceAce.principal = principal.Principal(identifier="principal")
     persistenceAce.grantedPrivileges = [privilege.READ_PRIVILEGE.identifier]
     persistenceAce.deniedPrivileges = [privilege.WRITE_PRIVILEGE.identifier]
     mappedAce = self._ace.create(persistenceAce)
     
     self.assertEquals(mappedAce.principal.identifier, "principal")
     self.assertEquals(mappedAce.grantedPrivileges, set([privilege.READ_PRIVILEGE]))
     self.assertEquals(mappedAce.deniedPrivileges, set([privilege.WRITE_PRIVILEGE]))
Example #4
0
    def _mapRawResult(rawResult, mappedResult, isUser):
        """ Maps the WebDAV search result to the required format. """

        for key, value in rawResult.iteritems():
            uniqueName = os.path.basename(key)
            displayName = ""
            if (NS_DAV, PROP_DISPLAY_NAME) in value:
                displayName = unicode(value[(NS_DAV,
                                             PROP_DISPLAY_NAME)].textof())
            if isUser:
                principalType = constants.USER_PRINCIPAL_TYPE
            else:
                principalType = constants.GROUP_PRINCIPAL_TYPE
            principal_ = principal.Principal(uniqueName,
                                             type=principalType,
                                             displayName=displayName)
            mappedResult.append(principal_)
Example #5
0
from webdav.Connection import WebdavError
from webdav.Constants import NS_DAV, PROP_DISPLAY_NAME

from datafinder.persistence.principal_search import constants, principal
from datafinder.persistence.adapters.webdav_.principal_search.adapter import PrincipalSearchWebdavAdapter
from datafinder.persistence.error import PersistenceError
from datafinder_test.mocks import SimpleMock

__version__ = "$Revision-Id:$"

_VALID_WEBDAV_USER_RESULT = {
    "http://test.de/path/user1": {
        (NS_DAV, PROP_DISPLAY_NAME): SimpleMock("displayName")
    }
}
_VALID_USER_RESULT = [principal.Principal("user1", displayName="displayName")]

_VALID_WEBDAV_GROUP_RESULT = {
    "http://test.de/path/group1": {
        (NS_DAV, PROP_DISPLAY_NAME): SimpleMock("displayName")
    }
}
_VALID_GROUP_RESULT = [
    principal.Principal("group1",
                        type=constants.GROUP_PRINCIPAL_TYPE,
                        displayName="displayName")
]
_VALID_USER_GROUP_RESULT = [_VALID_USER_RESULT[0], _VALID_GROUP_RESULT[0]]


class _WebDAVSearchMethodMock(object):
Example #6
0
from datafinder.persistence.principal_search import constants, principal
from datafinder.persistence.adapters.ldap_.configuration import Configuration
from datafinder.persistence.adapters.ldap_.principal_search import adapter

__version__ = "$Revision-Id:$"

_TEST_DOMAIN = "dlr"
_SERVER_DOWN_URI = "uriDown"

_VALID_USER_QUERY = "validUser"
_VALID_GROUP_QUERY = "validGroup"
_VALID_USER_GROUP_QUERY = "validUserGroup"
_INVALID_QUERY = "invalidQuery"
_PROBLEM_ON_QUERY = "problemOnQuery"

_GROUP1_PRINCIPAL = principal.Principal(_TEST_DOMAIN + "\\group1",
                                        type=constants.GROUP_PRINCIPAL_TYPE)
_GROUP2_PRINCIPAL = principal.Principal(_TEST_DOMAIN + "\\group2",
                                        type=constants.GROUP_PRINCIPAL_TYPE)
_ROLES = [_GROUP1_PRINCIPAL, _GROUP2_PRINCIPAL]

_RAW_USER_RESULT = [{
    0: ["test"],
    1: ["user"],
    2: ["test"],
    3: ["group1", "group2"]
}]
_MAPPED_USER = principal.Principal(_TEST_DOMAIN + "\\test",
                                   displayName="test",
                                   roles=_ROLES)

_RAW_GROUP_RESULT = [{
Example #7
0
    def __init__(self, principalId):
        """ Constructor. """

        self.principal = principal.Principal(principalId)
        self.grantedPrivileges = list()
        self.deniedPrivileges = list()
Example #8
0
__version__ = "$Revision-Id:$"

import unittest

from webdav.Connection import WebdavError

from datafinder.persistence.principal_search import principal
from datafinder.persistence.privileges import constants
from datafinder.persistence.privileges.ace import AccessControlListEntry
from datafinder.persistence.adapters.webdav_.privileges import adapter
from datafinder.persistence.adapters.webdav_.privileges import privileges_mapping
from datafinder.persistence.error import PersistenceError
from datafinder_test.mocks import SimpleMock

_VALID_ACL = [AccessControlListEntry(principal.Principal("id"))]


class PrivilegeWebdavAdapterTestCase(unittest.TestCase):
    def setUp(self):
        self._privilegeMapper = SimpleMock()
        self._connectionHelper = SimpleMock(SimpleMock())
        self._adapter = adapter.PrivilegeWebdavAdapter("identifier",
                                                       SimpleMock(),
                                                       SimpleMock(),
                                                       self._privilegeMapper,
                                                       self._connectionHelper)

    def testRetrieveAcl(self):
        self._privilegeMapper.value = _VALID_ACL
        self.assertEquals(self._adapter.retrieveAcl(), _VALID_ACL)