Esempio n. 1
0
    def __init__(self, principal, plugin):
        """Instanciate LDAPUserPropertySheet.

        @param principal: user id or group id
        @param plugin: LDAPPlugin instance
        """
        # do not set any non-pickable attribute here, i.e. acquisition wrapped
        self._plugin = aq_base(plugin)
        self._properties = dict()
        self._attrmap = dict()
        self._ldapprincipal_id = principal.getId()
        if self._ldapprincipal_id in plugin.users:
            pcfg = ILDAPUsersConfig(plugin)
            self._ldapprincipal_type = 'users'
        else:
            pcfg = ILDAPGroupsConfig(plugin)
            self._ldapprincipal_type = 'groups'
        for k, v in pcfg.attrmap.items():
            if k in ['rdn', 'id']:
                # XXX: maybe 'login' should be editable if existent ??
                continue
            self._attrmap[k] = v
        ldapprincipal = self._get_ldap_principal()
        request = getRequest()
        # XXX: tmp - load props each time they are accessed.
        if not request or not request.get('_ldap_props_reloaded'):
            ldapprincipal.attrs.context.load()
            if request:
                request['_ldap_props_reloaded'] = 1
        for key in self._attrmap:
            self._properties[key] = ldapprincipal.attrs.get(key, '')
        UserPropertySheet.__init__(self, principal.getId(), schema=None,
                                   **self._properties)
Esempio n. 2
0
    def __init__(self, principal, plugin):
        """Instanciate LDAPUserPropertySheet.

        @param principal: user id or group id
        @param plugin: LDAPPlugin instance
        """
        self._plugin = plugin
        self._properties = dict()
        if principal.getId() in plugin.users:
            self._pcfg = ILDAPUsersConfig(plugin)
            self._lprincipal = plugin.users[principal.getId()]
        else:
            self._pcfg = ILDAPGroupsConfig(plugin)
            self._lprincipal = plugin.groups[principal.getId()]
        
        self._attrmap = dict()
        for k, v in self._pcfg.attrmap.items():
            if k in ['rdn', 'id']:
                # XXX: maybe 'login' should be editable if existent ??
                continue
            self._attrmap[k] = v

        # XXX: tmp - load props each time they are accessed.
        if not self._plugin.REQUEST.get('_ldap_props_reloaded'):
            self._lprincipal.attrs.context.load()
            self._plugin.REQUEST['_ldap_props_reloaded'] = 1

        for key in self._attrmap:
            self._properties[key] = self._lprincipal.attrs.get(key, '')
        UserPropertySheet.__init__(self, principal, schema=None, 
                                   **self._properties)
Esempio n. 3
0
    def __init__(self, principal, plugin):
        """Instanciate LDAPUserPropertySheet.

        @param principal: user id or group id
        @param plugin: LDAPPlugin instance
        """
        # do not set any non-pickable attribute here, i.e. acquisition wrapped
        self._plugin = aq_base(plugin)
        self._properties = dict()
        self._attrmap = dict()
        self._ldapprincipal_id = principal.getId()
        if self._ldapprincipal_id in plugin.users:
            pcfg = ILDAPUsersConfig(plugin)
            self._ldapprincipal_type = 'users'
        else:
            pcfg = ILDAPGroupsConfig(plugin)
            self._ldapprincipal_type = 'groups'
        for k, v in pcfg.attrmap.items():
            if k in ['rdn', 'id']:
                # XXX: maybe 'login' should be editable if existent ??
                continue
            self._attrmap[k] = v
        ldapprincipal = self._get_ldap_principal()
        request = getRequest()
        # XXX: tmp - load props each time they are accessed.
        if not request or not request.get('_ldap_props_reloaded'):
            ldapprincipal.attrs.context.load()
            if request:
                request['_ldap_props_reloaded'] = 1
        for key in self._attrmap:
            self._properties[key] = ldapprincipal.attrs.get(key, '')
        UserPropertySheet.__init__(self,
                                   principal.getId(),
                                   schema=None,
                                   **self._properties)
Esempio n. 4
0
 def propertysheet(self):
     if self._sheet is not None:
         return self._sheet
     # build sheet from identities
     pdata = dict(id=self.userid)
     cfgs_providers = authomatic_cfg()
     for provider_name in cfgs_providers:
         identity = self.identity(provider_name)
         if identity is None:
             continue
         logger.debug(identity)
         cfg = cfgs_providers[provider_name]
         for akey, pkey in cfg.get('propertymap', {}).items():
             # Always search first on the user attributes, then on the raw
             # data this guaratees we do not break existing configurations
             ainfo = identity.get(akey, identity['data'].get(akey, None))
             if ainfo is None:
                 continue
             if isinstance(pkey, dict):
                 for k, v in pkey.items():
                     pdata[k] = ainfo.get(v)
             else:
                 pdata[pkey] = ainfo
     self._sheet = UserPropertySheet(**pdata)
     return self._sheet
Esempio n. 5
0
    def getPropertiesForUser(self, user, request=None):
        """

        o User will implement IPropertiedUser.

        o Plugin should return a dictionary or an object providing
          IPropertySheet.

        o Plugin may scribble on the user, if needed (but must still
          return a mapping, even if empty).

        o May assign properties based on values in the REQUEST object, if
          present
        """
        if request is None:
            if hasattr(self, 'REQUEST'):  # noqa
                request = self.REQUEST
            else:
                return {}
        userId = user.getId()
        if userId == request.environ.get(USERNAME_HEADER):
            return UserPropertySheet(user.id,
                                     **self._getShibProperties(userId))
        else:
            return {}
Esempio n. 6
0
 def _get_propertysheet_of_info(self, info):
     if info is None:
         return None
     sheet = UserPropertySheet(self.getId(),
                               title=info['title'],
                               description=info['description'],
                               email=info['email'])
     return sheet
Esempio n. 7
0
    def __init__(self, id, user):
        self.id = id

        acl = self._getLDAPUserFolder(user)
        self._ldapschema = [
            (x["ldap_name"], x["public_name"], x["multivalued"] and "lines" or "string")
            for x in acl.getSchemaConfig().values()
            if x["public_name"]
        ]

        properties = self._getCache(user)
        if properties is None:
            properties = self.fetchLdapProperties(user)
            if properties:
                self._setCache(user, properties)

        UserPropertySheet.__init__(self, id, schema=[(x[1], x[2]) for x in self._ldapschema], **properties)
Esempio n. 8
0
    def __init__(self, id, user):
        self.id=id

        acl = self._getLDAPUserFolder(user)
        self._ldapschema=[(x['ldap_name'], x['public_name'],
                        x['multivalued'] and 'lines' or 'string') \
                    for x in acl.getSchemaConfig().values() \
                    if x['public_name']]

        properties=self._getCache(user)
        if properties is None:
            properties=self.fetchLdapProperties(user)
            if properties:
                self._setCache(user, properties)

        UserPropertySheet.__init__(self, id,
                schema=[(x[1],x[2]) for x in self._ldapschema], **properties)
Esempio n. 9
0
 def _propertysheet(self, userid, identity):
     pdata = {
         'fullname': (
                 identity['Person.FirstName'][0] +
                 ' ' +
                 identity['Person.LastName'][0]
         ),
         'email': identity['Person.Email'][0]
     }
     return UserPropertySheet(userid, **pdata)
Esempio n. 10
0
    def __init__(self, id, user):
        self.id = id

        acl = self._getLDAPUserFolder(user)
        self._ldapschema=[(x['ldap_name'], x['public_name'],
                        x['multivalued'] and 'lines' or 'string') \
                    for x in acl.getSchemaConfig().values() \
                    if x['public_name']]

        properties = self._getCache(user)
        if properties is None:
            properties = self.fetchLdapProperties(user)
            if properties:
                self._setCache(user, properties)

        UserPropertySheet.__init__(self,
                                   id,
                                   schema=[(x[1], x[2])
                                           for x in self._ldapschema],
                                   **properties)
Esempio n. 11
0
    def addPropertysheet(self, id, data):
        """ -> add a prop sheet, given data which is either
        a property sheet or a raw mapping.
        """
        if IPropertySheet.providedBy(data):
            sheet = data
        else:
            sheet = UserPropertySheet(id, **data)

        if self._propertysheets.get(id) is not None:
            raise KeyError('Duplicate property sheet: %s' % id)

        self._propertysheets[id] = sheet
def __patched_init__(self, id, user):
    self.id = id

    acl = self._getLDAPUserFolder(user)
    self._ldapschema = [(x['ldap_name'], x['public_name'],
                         'lines' if x['multivalued'] else 'string')
                        for x in acl.getSchemaConfig().values()
                        if x['public_name']]

    properties = self._getCache(user)
    if not isinstance(properties, dict):
        properties = self.fetchLdapProperties(user)
        if properties and isinstance(properties, dict):
            self._setCache(user, properties)

    if not isinstance(properties, dict):
        logger.warning(properties)
        properties = {}

    id = properties.pop('id', id)
    UserPropertySheet.__init__(self, id,
            schema=[(x[1], x[2]) for x in self._ldapschema], **properties)
Esempio n. 13
0
def __patched_init__(self, id, user):
    self.id = id

    acl = self._getLDAPUserFolder(user)
    self._ldapschema = [(x['ldap_name'], x['public_name'],
                         'lines' if x['multivalued'] else 'string')
                        for x in acl.getSchemaConfig().values()
                        if x['public_name']]

    properties = self._getCache(user)
    if not isinstance(properties, dict):
        properties = self.fetchLdapProperties(user)
        if properties and isinstance(properties, dict):
            self._setCache(user, properties)

    if not isinstance(properties, dict):
        logger.warning(properties)
        properties = {}

    id = properties.pop('id', id)
    UserPropertySheet.__init__(self,
                               id,
                               schema=[(x[1], x[2]) for x in self._ldapschema],
                               **properties)
Esempio n. 14
0
    def getPropertiesForUser(self, user, request=None):
        default = {}

        user_id = user.getId()

        ob = self._useridentities_by_userid.get(user_id)
        if ob is not None:
            properties = dict(username=ob.get('preferred_username'),
                              email=ob.get('email'),
                              fullname=ob.get('name'))

            psheet = UserPropertySheet(
                self.getId(),
                schema=None,
                **properties,
            )
            return psheet

        return default
Esempio n. 15
0
 def __init__(self, plugin, **kwargs):
     UserPropertySheet.__init__(self, plugin.id, **kwargs)
     self._plugin = plugin
Esempio n. 16
0
 def __init__(self, plugin, **kwargs):
     UserPropertySheet.__init__(self, plugin.id, **kwargs)
     self._plugin = plugin