示例#1
0
    def assignRolesToPrincipal(self, roles, principal_id, setting=True):
        if self._uid(principal_id) is None and self._gid(principal_id) is None:
            return

        if setting is True:
            # delete global mappings
            
            http_obj=httplib2.Http()
            query = '/++rest++brs/roles'
            data = {'principal_id': principal_id}
            params = urllib.urlencode(data)
            resp,content = http_obj.request(connection_url()+ query, params, "DELETE")               
            
            # update existing

            http_obj=httplib2.Http()
            query = '/++rest++brs/roles'
            data = {'principal_id': principal_id}
            params = urllib.urlencode(data)
            resp,content = http_obj.request(connection_url()+ query, params, "PUT")
            
        # insert new global mappings

            http_obj=httplib2.Http()
            query = '/++rest++brs/roles'
            data = {'roles': roles,
                    'principal_id': principal_id,
                    'setting': setting}            
            params = urllib.urlencode(data)
            resp,content = http_obj.request(connection_url()+ query, params, "POST")
            
        return True
示例#2
0
    def getPropertiesForUser(self, user, request=None):
        """Get property values for a user or group.
        Returns a dictionary of values or a PropertySheet.
        """
        view_name = createViewName('getPropertiesForUser', user)
        cached_info = self.ZCacheable_get(view_name=view_name)
        if cached_info is not None:
            return MutablePropertySheet(self.id, **cached_info)
        data = None
        if user.isGroup():
            http_obj = httplib2.Http()
            query = '/++rest++brs/groups?'
            params = urllib.urlencode({'user_name': user.getUserName()})
            resp, content = http_obj.request(connection_url() + query + params,
                                             "GET")
            data = simplejson.loads(content)

        else:
            http_obj = httplib2.Http()
            query = '/++rest++brs/users?'
            params = urllib.urlencode({'user_name': user.getUserName()})
            resp, content = http_obj.request(connection_url() + query + params,
                                             "GET")
            data = simplejson.loads(content)

        if data:
            self.ZCacheable_set(data, view_name=view_name)
            sheet = MutablePropertySheet(self.id, **data)
            return sheet
示例#3
0
    def enumerateUsers(self
                      , id=None
                      , login=None
                      , exact_match=False
                      , sort_by=None
                      , max_results=None
                      , **kw
                      ):
        """See IUserEnumerationPlugin.
        """
        if id is None:
            id = login

        http_obj=httplib2.Http()
        query = '/++rest++brs/enumerateusers?'
        params = urllib.urlencode({'user_manager_id': self.id,
                                   'id': id,
                                   'login': login,
                                   'exact_match': exact_match,
                                   'sort_by': sort_by,
                                   'max_results': max_results,
                                   'kw': kw})

        resp,content = http_obj.request(connection_url() + query + params, "GET")
        return simplejson.loads(content)          
示例#4
0
 def listUserInfo(self):
     http_obj=httplib2.Http()
     query = '/++rest++brs/users?'
     params = urllib.urlencode({'user_manager_id': self.id})        
     resp,content = http_obj.request(connection_url() + query + params, "GET")
     users = simplejson.loads(content)
     return users
示例#5
0
    def enumerateUsers(self,
                       id=None,
                       login=None,
                       exact_match=False,
                       sort_by=None,
                       max_results=None,
                       **kw):
        """See IUserEnumerationPlugin.
        """
        if id is None:
            id = login

        http_obj = httplib2.Http()
        query = '/++rest++brs/enumerateusers?'
        params = urllib.urlencode({
            'user_manager_id': self.id,
            'id': id,
            'login': login,
            'exact_match': exact_match,
            'sort_by': sort_by,
            'max_results': max_results,
            'kw': kw
        })

        resp, content = http_obj.request(connection_url() + query + params,
                                         "GET")
        return simplejson.loads(content)
示例#6
0
    def _uid(self, login, auth=False):

        http_obj=httplib2.Http()
        query = '/++rest++brs/users?'
        data = {"auth": auth,
                "login": login}
        params = urllib.urlencode(data)
        resp,content = http_obj.request(connection_url()+ query + params, "GET")
示例#7
0
 def getGroupIds(self):
     """
     Returns a list of the available groups
     """
     http_obj=httplib2.Http()
     query = "/++rest++brs/groups"
     resp,content = http_obj.request(connection_url() + query, "GET")
     groups = simplejson.loads(content)
示例#8
0
    def _uid(self, login, auth=False):

        http_obj = httplib2.Http()
        query = '/++rest++brs/users?'
        data = {"auth": auth, "login": login}
        params = urllib.urlencode(data)
        resp, content = http_obj.request(connection_url() + query + params,
                                         "GET")
示例#9
0
 def listUserInfo(self):
     http_obj = httplib2.Http()
     query = '/++rest++brs/users?'
     params = urllib.urlencode({'user_manager_id': self.id})
     resp, content = http_obj.request(connection_url() + query + params,
                                      "GET")
     users = simplejson.loads(content)
     return users
示例#10
0
 def _gid(self, name):
     http_obj=httplib2.Http()
     query = "/++rest++brs/groups?"
     params = urllib.urlencode({'name': name})
     resp,content = http_obj.request(connection_url() + query + params, "GET")
     groups = simplejson.loads(content)
     if not groups:
         return
     return groups["principal_name"]
示例#11
0
 def _uid(self, login):
     http_obj=httplib2.Http()
     query = "/++rest++brs/users?"
     params = urllib.urlencode({"login": login})
     resp,content = http_obj.request(connection_url() + query + params, "GET")
     user = simplejson.loads(content)
     if user is None:
         return
     return user.user_id        
示例#12
0
 def _gid(self, name):
     http_obj=httplib2.Http()
     query = '/++rest++brs/groups?'
     params = urllib.urlencode({'name': name})
     resp,content = http_obj.request(connection_url() + query + params, "GET")
     groups = simplejson.loads(content)        
     if not groups:
         return
     return groups[0].group_principal_id
示例#13
0
 def getGroups(self):
     """
     Returns an iteration of the available groups
     """
     http_obj=httplib2.Http()
     query = "/++rest++brs/groups"
     resp,content = http_obj.request(connection_url() + query, "GET")
     groups = simplejson.loads(content)
     return [PloneGroup(r).__of__(self) for r in groups]
示例#14
0
    def enumerateRoles(self,
                        id=None
                      , exact_match=False
                      , sort_by=None
                      , max_results=None
                      , **kw
                      ):

        """ -> ( role_info_1, ... role_info_N )

        o Return mappings for roles matching the given criteria.

        o 'id' in combination with 'exact_match' true, will
          return at most one mapping per supplied ID ('id' and 'login'
          may be sequences).

        o If 'exact_match' is False, then 'id' may be treated by 
          the plugin as "contains" searches (more complicated searches 
          may be supported by some plugins using other keyword arguments).

        o If 'sort_by' is passed, the results will be sorted accordingly.
          known valid values are 'id' (some plugins may support others).

        o If 'max_results' is specified, it must be a positive integer,
          limiting the number of returned mappings.  If unspecified, the
          plugin should return mappings for all roles satisfying the 
          criteria.

        o Minimal keys in the returned mappings:
        
          'id' -- (required) the role ID

          'pluginid' -- (required) the plugin ID (as returned by getId())

          'properties_url' -- (optional) the URL to a page for updating the
                              role's properties.

          'members_url' -- (optional) the URL to a page for updating the
                           principals to whom the role is assigned.

        o Plugin *must* ignore unknown criteria.

        o Plugin may raise ValueError for invalid critera.

        o Insufficiently-specified criteria may have catastrophic
          scaling issues for some implementations.
        """

        pluginid = self.getId()

        http_obj=httplib2.Http()
        query = '/++rest++brs/enumerateroles?'
        params = urllib.urlencode({'plugin_id': self.getId()})
        resp,content = http_obj.request(connection_url()+ query + params, "GET")

        return simplejson.loads(content)
示例#15
0
 def removeUser(self, user_id): # raises keyerror
     uid = self._uid( user_id )
     if not uid:
         raise KeyError("Invalid User"%uid)
     # update user to show as inactive
     http_obj=httplib2.Http()
     query = '/++rest++brs/users'
     data = {"uid": uid}
     params = urllib.urlencode(data)
     resp,content = http_obj.request(connection_url()+ query, params, "DELETE")
示例#16
0
 def getGroupMembers(self, group_id):
     """
     return the members of the given group
     """
     
     http_obj=httplib2.Http()
     query = "/++rest++brs/groupmembers?"
     params = urllib.urlencode({"group_id": group_id})
     resp,content = http_obj.request(connection_url() + query + params, "GET")
     return simplejson.loads(content)
示例#17
0
    def enumerateRoles(self,
                       id=None,
                       exact_match=False,
                       sort_by=None,
                       max_results=None,
                       **kw):
        """ -> ( role_info_1, ... role_info_N )

        o Return mappings for roles matching the given criteria.

        o 'id' in combination with 'exact_match' true, will
          return at most one mapping per supplied ID ('id' and 'login'
          may be sequences).

        o If 'exact_match' is False, then 'id' may be treated by 
          the plugin as "contains" searches (more complicated searches 
          may be supported by some plugins using other keyword arguments).

        o If 'sort_by' is passed, the results will be sorted accordingly.
          known valid values are 'id' (some plugins may support others).

        o If 'max_results' is specified, it must be a positive integer,
          limiting the number of returned mappings.  If unspecified, the
          plugin should return mappings for all roles satisfying the 
          criteria.

        o Minimal keys in the returned mappings:
        
          'id' -- (required) the role ID

          'pluginid' -- (required) the plugin ID (as returned by getId())

          'properties_url' -- (optional) the URL to a page for updating the
                              role's properties.

          'members_url' -- (optional) the URL to a page for updating the
                           principals to whom the role is assigned.

        o Plugin *must* ignore unknown criteria.

        o Plugin may raise ValueError for invalid critera.

        o Insufficiently-specified criteria may have catastrophic
          scaling issues for some implementations.
        """

        pluginid = self.getId()

        http_obj = httplib2.Http()
        query = '/++rest++brs/enumerateroles?'
        params = urllib.urlencode({'plugin_id': self.getId()})
        resp, content = http_obj.request(connection_url() + query + params,
                                         "GET")

        return simplejson.loads(content)
示例#18
0
 def removeUser(self, user_id):  # raises keyerror
     uid = self._uid(user_id)
     if not uid:
         raise KeyError("Invalid User" % uid)
     # update user to show as inactive
     http_obj = httplib2.Http()
     query = '/++rest++brs/users'
     data = {"uid": uid}
     params = urllib.urlencode(data)
     resp, content = http_obj.request(connection_url() + query, params,
                                      "DELETE")
示例#19
0
    def updateUserPassword(self, user_id, login_name, password): # raise keyerror, lookup error
        uid = self._uid( user_id )
        if uid is None:
            raise KeyError("Invalid User %s"%user_id )
        salt = generate_salt()
        e_pass = encrypt( password, salt )

        http_obj=httplib2.Http()
        query = '/++rest++brs/users'
        data = {"uid": uid,
                "salt": salt,
                "password": e_pass}
        params = urllib.urlencode(data)
        resp,content = http_obj.request(connection_url()+ query, params, "PUT") 
示例#20
0
    def updateUserPassword(self, user_id, login_name,
                           password):  # raise keyerror, lookup error
        uid = self._uid(user_id)
        if uid is None:
            raise KeyError("Invalid User %s" % user_id)
        salt = generate_salt()
        e_pass = encrypt(password, salt)

        http_obj = httplib2.Http()
        query = '/++rest++brs/users'
        data = {"uid": uid, "salt": salt, "password": e_pass}
        params = urllib.urlencode(data)
        resp, content = http_obj.request(connection_url() + query, params,
                                         "PUT")
示例#21
0
    def assignRolesToPrincipal(self, roles, principal_id, setting=True):
        if self._uid(principal_id) is None and self._gid(principal_id) is None:
            return

        if setting is True:
            # delete global mappings

            http_obj = httplib2.Http()
            query = '/++rest++brs/roles'
            data = {'principal_id': principal_id}
            params = urllib.urlencode(data)
            resp, content = http_obj.request(connection_url() + query, params,
                                             "DELETE")

            # update existing

            http_obj = httplib2.Http()
            query = '/++rest++brs/roles'
            data = {'principal_id': principal_id}
            params = urllib.urlencode(data)
            resp, content = http_obj.request(connection_url() + query, params,
                                             "PUT")

            # insert new global mappings

            http_obj = httplib2.Http()
            query = '/++rest++brs/roles'
            data = {
                'roles': roles,
                'principal_id': principal_id,
                'setting': setting
            }
            params = urllib.urlencode(data)
            resp, content = http_obj.request(connection_url() + query, params,
                                             "POST")

        return True
示例#22
0
 def addUser(self, user_id, login_name, password): # raises keyerror, lookup error
     salt = generate_salt()
     e_pass = encrypt( password, salt )
     if self._uid( login_name ):
         raise KeyError("Duplicate User Id: %s"%user_id)
     h=httplib2.Http()
     query = '/++rest++brs/users'
     data = {"login": user_id,
             "salt": salt,
             "password": e_pass,
             "type": "user",
             "first_name": u"unknown",
             "last_name": u"unknown",
             "email": u"unknown"}
     params = urllib.urlencode(data)
     resp,content = h.request(connection_url()+ query, params, "POST")
示例#23
0
 def enumerateGroups( self, id=None
                    , exact_match=False
                    , sort_by=None
                    , max_results=None
                    , **kw
                    ):
     """ see IGroupEnumeration """
     http_obj=httplib2.Http()
     querys = "/++rest++brs/enumerategroups?"
     params = urllib.urlencode({"group_manager_id": self.id,
                                "gid": id,
                                "exact_match": exact_match,
                                "sort_by": sort_by,
                                "max_results": max_results})
     resp,content = http_obj.request(connection_url() + querys + params, "GET")
     return simplejson.loads(content)            
示例#24
0
    def getGroupsForPrincipal(self, principal, request=None):
        """ principal -> ( group_1, ... group_N )

        o Return a sequence of group names to which the principal 
          (either a user or another group) belongs.

        o May assign groups based on values in the REQUEST object, if present
        """
        #XXX TODO: user delegations!, implement search for groups 
        # recursivly for this use case

        http_obj=httplib2.Http()
        query = "/++rest++brs/memberships?"
        params = urllib.urlencode({"principal_id": principal.getId()})
        resp,content = http_obj.request(connection_url() + query + params, "GET")
        return simplejson.loads(content)
示例#25
0
 def setPropertiesForUser(self, user, propertysheet):
     if user.isGroup():
         pass
         #we do not set any attributes from plone here
     else:
         h = httplib2.Http()
         query = '/++rest++brs/users'
         data = {'login': user.getUserName()}
         params = urllib.urlencode(data)
         resp, content = h.request(connection_url() + query + params, "GET")
         if propertysheet.getProperty('email'):
             data['email'] = propertysheet.getProperty('email')
         if propertysheet.getProperty('notification') != None:
             data['receive_notification'] = propertysheet.getProperty(
                 'notification')
     view_name = createViewName('getPropertiesForUser', user)
     cached_info = self.ZCacheable_invalidate(view_name=view_name)
示例#26
0
 def addUser(self, user_id, login_name,
             password):  # raises keyerror, lookup error
     salt = generate_salt()
     e_pass = encrypt(password, salt)
     if self._uid(login_name):
         raise KeyError("Duplicate User Id: %s" % user_id)
     h = httplib2.Http()
     query = '/++rest++brs/users'
     data = {
         "login": user_id,
         "salt": salt,
         "password": e_pass,
         "type": "user",
         "first_name": u"unknown",
         "last_name": u"unknown",
         "email": u"unknown"
     }
     params = urllib.urlencode(data)
     resp, content = h.request(connection_url() + query, params, "POST")
示例#27
0
    def getRolesForPrincipal(self, principal, request=None):
        """ principal -> ( role_1, ... role_N )

        o Return a sequence of role names which the principal has.

        o May assign roles based on values in the REQUEST object, if present.
        """

        http_obj = httplib2.Http()
        query = '/++rest++brs/roles?'
        params = urllib.urlencode({'principal_id': principal.getId()})
        resp, content = http_obj.request(connection_url() + query + params,
                                         "GET")
        if "bungeni.Owner" in content:
            roles = simplejson.loads(content)
            roles.append("Manager")
            return roles
        else:
            return simplejson.loads(content)
示例#28
0
    def getRolesForPrincipal(self, principal, request=None ):

        """ principal -> ( role_1, ... role_N )

        o Return a sequence of role names which the principal has.

        o May assign roles based on values in the REQUEST object, if present.
        """

        http_obj=httplib2.Http()
        query = '/++rest++brs/roles?'
        params = urllib.urlencode({'principal_id': principal.getId()})
        resp,content = http_obj.request(connection_url()+ query + params, "GET")
        if "bungeni.Owner" in content:
            roles = simplejson.loads(content)
            roles.append("Manager")
            return roles          
        else:
            return simplejson.loads(content)        
示例#29
0
 def listUserIds(self):
     http_obj = httplib2.Http()
     query = '/++rest++brs/users'
     resp, content = http_obj.request(connection_url() + query, "GET")
     users = simplejson.loads(content)
     return users
示例#30
0
 def listUserIds(self):
     http_obj=httplib2.Http()
     query = '/++rest++brs/users'
     resp,content = http_obj.request(connection_url() + query, "GET")
     users = simplejson.loads(content)
     return users