コード例 #1
0
ファイル: middleware.py プロジェクト: soongxin/hhue
  def process_request(self, request):
    user = request.user
    server = None

    # Used by tests only
    if request.method == "GET":
      server = request.GET.get('server')

    if not user or not user.is_authenticated:
      return

    if not User.objects.filter(username=user.username, userprofile__creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
      LOG.warn("User %s is not an Ldap user" % user.username)
      return

    # Cache should be cleared when user logs out.
    if self.USER_CACHE_NAME not in request.session:
      if LDAP.LDAP_SERVERS.get():
        connection = ldap_access.get_connection_from_server(next(LDAP.LDAP_SERVERS.__iter__()))
      else:
        connection = ldap_access.get_connection_from_server()

      import_ldap_users(connection, user.username, sync_groups=True, import_by_dn=False, server=server)

      request.session[self.USER_CACHE_NAME] = True
      request.session.modified = True
コード例 #2
0
ファイル: backend.py プロジェクト: ziq211/hue
    def check_ldap_access_groups(self, server, username):
        #Avoid circular import from is_admin
        from useradmin.views import get_find_groups_filter
        allowed_group = False

        if LDAP.LOGIN_GROUPS.get() and LDAP.LOGIN_GROUPS.get() != ['']:
            login_groups = LDAP.LOGIN_GROUPS.get()
            connection = ldap_access.get_connection_from_server(server)
            try:
                user_info = connection.find_users(username, find_by_dn=False)
            except Exception as e:
                LOG.warn("Failed to find LDAP user: %s" % e)

            if not user_info:
                LOG.warn(
                    "Could not get LDAP details for users with pattern %s" %
                    username)
                return False

            ldap_info = user_info[0]
            group_ldap_info = connection.find_groups(
                "*", group_filter=get_find_groups_filter(ldap_info, server))
            for group in group_ldap_info:
                if group['name'] in login_groups:
                    return True

        else:
            #Login groups not set default to True
            allowed_group = True

        return allowed_group
コード例 #3
0
ファイル: backend.py プロジェクト: zkenstein/hue
 def import_groups(self, server, user):
     connection = ldap_access.get_connection_from_server(server)
     import_ldap_users(connection,
                       user.username,
                       sync_groups=True,
                       import_by_dn=False,
                       server=server)
コード例 #4
0
ファイル: backend.py プロジェクト: ziq211/hue
 def import_groups(self, server, user):
     connection = ldap_access.get_connection_from_server(server)
     #Avoid circular import from is_admin
     from useradmin.views import import_ldap_users
     import_ldap_users(connection,
                       user.username,
                       sync_groups=True,
                       import_by_dn=False,
                       server=server)
コード例 #5
0
ファイル: import_ldap_user.py プロジェクト: bopopescu/hue-3
  def handle(self, user=None, **options):
    if user is None:
      raise CommandError(_("A username must be provided."))

    import_by_dn = options['dn']
    sync_groups = options['sync_groups']
    server = options['server']

    connection = ldap_access.get_connection_from_server(server)

    import_ldap_users(connection, user, sync_groups, import_by_dn)
コード例 #6
0
ファイル: import_ldap_user.py プロジェクト: cloudera/hue
  def handle(self, user=None, **options):
    if user is None:
      raise CommandError(_("A username must be provided."))

    import_by_dn = options['dn']
    sync_groups = options['sync_groups']
    server = options['server']

    connection = ldap_access.get_connection_from_server(server)

    import_ldap_users(connection, user, sync_groups, import_by_dn)
コード例 #7
0
  def handle(self, group=None, **options):
    if group is None:
      raise CommandError(_("A group name must be provided."))

    import_members = options['import_members']
    import_by_dn = options['dn']
    import_members_recursive = options['import_members_recursive']
    sync_users = options['sync_users']
    server = options['server']

    connection = ldap_access.get_connection_from_server(server)

    import_ldap_groups(connection, group, import_members, import_members_recursive, sync_users, import_by_dn)
コード例 #8
0
ファイル: backend.py プロジェクト: cloudera/hue
  def check_ldap_access_groups(self, server, username):
    #Avoid circular import from is_admin
    from useradmin.views import get_find_groups_filter
    allowed_group = False

    if desktop.conf.LDAP.LOGIN_GROUPS.get() and desktop.conf.LDAP.LOGIN_GROUPS.get() != ['']:
      login_groups = desktop.conf.LDAP.LOGIN_GROUPS.get()
      connection = ldap_access.get_connection_from_server(server)
      try:
        user_info = connection.find_users(username, find_by_dn=False)
      except Exception, e:
        LOG.warn("Failed to find LDAP user: %s" % e)

      if not user_info:
        LOG.warn("Could not get LDAP details for users with pattern %s" % username)
        return False

      ldap_info = user_info[0]
      group_ldap_info = connection.find_groups("*", group_filter=get_find_groups_filter(ldap_info, server))
      for group in group_ldap_info:
        if group['name'] in login_groups:
          return True
コード例 #9
0
    def check_ldap_access_groups(self, server, username):
        allowed_group = False

        if desktop.conf.LDAP.LOGIN_GROUPS.get(
        ) and desktop.conf.LDAP.LOGIN_GROUPS.get() != ['']:
            login_groups = desktop.conf.LDAP.LOGIN_GROUPS.get()
            connection = ldap_access.get_connection_from_server(server)
            try:
                user_info = connection.find_users(username, find_by_dn=False)
            except LdapSearchException, e:
                LOG.warn("Failed to find LDAP user: %s" % e)

            if not user_info:
                LOG.warn(
                    "Could not get LDAP details for users with pattern %s" %
                    username_pattern)
                return None

            ldap_info = user_info[0]
            group_ldap_info = connection.find_groups(
                "*", group_filter=get_find_groups_filter(ldap_info))
            for group in group_ldap_info:
                if group['name'] in login_groups:
                    allowed_group = True
コード例 #10
0
ファイル: backend.py プロジェクト: 9629831527/hue
 def import_groups(self, server, user):
   connection = ldap_access.get_connection_from_server(server)
   import_ldap_users(connection, user.username, sync_groups=True, import_by_dn=False)
コード例 #11
0
  def handle(self, **options):
    server = options['server']

    connection = ldap_access.get_connection_from_server(server)

    sync_ldap_users_and_groups(connection)
コード例 #12
0
ファイル: backend.py プロジェクト: cloudera/hue
 def import_groups(self, server, user):
   connection = ldap_access.get_connection_from_server(server)
   #Avoid circular import from is_admin
   from useradmin.views import import_ldap_users
   import_ldap_users(connection, user.username, sync_groups=True, import_by_dn=False, server=server)
コード例 #13
0
    def handle(self, **options):
        server = options['server']

        connection = ldap_access.get_connection_from_server(server)

        sync_ldap_users_and_groups(connection)