Ejemplo n.º 1
0
 def get_config(self):
     """
     Load the updated server configuration
     """
     
     # Generate a new Django secret for the engine and portal
     engine_secret = "'%s'" % rstring(64)
     portal_secret = "'%s'" % rstring(64)
     
     # Return the updated server configuration
     return {
         'server': {
             'host': self.input.response.get('api_host'),
             'port': self.input.response.get('api_port'),
             'secret': engine_secret      
         },
         'db': {
             'host': self.input.response.get('db_host'),
             'port': self.input.response.get('db_port'),
             'user': self.input.response.get('db_user'),
             'password': self.input.response.get('db_user_password')
         },
         'portal': {
             'host': self.input.response.get('portal_host'),
             'port': self.input.response.get('portal_port'),
             'secret': portal_secret
         },
         'socket': {
             'host': self.input.response.get('socket_host'),
             'port': self.input.response.get('socket_port'),
             'bind_ip': self.input.response.get('socket_bind_ipaddr')
         }    
     }
Ejemplo n.º 2
0
 def get_or_create_user(self, username, ldap_user):
     """
     Retrieve or create a user account.
     """
     
     # Extract the user tree
     tree = re.compile(r'^.*(ou.*$)').sub(r'\g<1>', ldap_user.dn)
     
     # Extract the group attributes
     group_attrs = [x for x in self.map['groups'] if x['tree'].lower() == tree][0]
     
     # Map the user attributes
     user_attrs = self._map_user_attrs(ldap_user.attrs, group_attrs)
     
     # Add extra database attributes. Generate a random password (will be changed during authentication)
     user_attrs.update({
         'from_ldap': True,
         'password':  rstring()
     })
     
     # Look for a default group
     def_group = None if not ('default_group' in group_attrs) else group_attrs['default_group']
     
     # Get the user model
     user_model = get_user_model()
     
     # Get or create the user model and then return
     return user_model.objects.get_or_create(group=def_group, **user_attrs)