Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)          
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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
Ejemplo n.º 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"]
Ejemplo n.º 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        
Ejemplo n.º 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
Ejemplo n.º 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]
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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") 
Ejemplo n.º 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")
Ejemplo n.º 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
Ejemplo n.º 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")
Ejemplo n.º 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)            
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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)        
Ejemplo n.º 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
Ejemplo n.º 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