Beispiel #1
0
def add_ldap_users(request):
  """
  add_ldap_users(request) -> reply

  Handler for importing LDAP users into the Hue database.

  If a user has been previously imported, this will sync their user information.
  If the LDAP request failed, the error message is generic right now.
  """
  if not request.user.is_superuser:
    raise PopupException(_("You must be a superuser to add another user."), error_code=401)

  if request.method == 'POST':
    form = AddLdapUsersForm(request.POST)
    if form.is_valid():
      username_pattern = form.cleaned_data['username_pattern']
      import_by_dn = form.cleaned_data['dn']
      try:
        users = import_ldap_users(username_pattern, import_by_dn)
      except LDAPError, e:
        LOG.error("LDAP Exception: %s" % e)
        raise PopupException(_('There was an error when communicating with LDAP'), detail=str(e))

      if users and form.cleaned_data['ensure_home_directory']:
        for user in users:
          try:
            ensure_home_directory(request.fs, user.username)
          except (IOError, WebHdfsException), e:
            request.error(_("Cannot make home directory for user %s." % user.username))

      if not users:
        errors = form._errors.setdefault('username_pattern', ErrorList())
        errors.append(_('Could not get LDAP details for users in pattern %s.') % username_pattern)
      else:
        return redirect(reverse(list_users))
Beispiel #2
0
def add_ldap_users(request):
  """
  add_ldap_users(request) -> reply

  Handler for importing LDAP users into the Hue database.

  If a user has been previously imported, this will sync their user information.
  If the LDAP request failed, the error message is generic right now.
  """
  if not request.user.is_superuser:
    raise PopupException(_("You must be a superuser to add another user."), error_code=401)

  if request.method == 'POST':
    form = AddLdapUsersForm(request.POST)
    if form.is_valid():
      username_pattern = form.cleaned_data['username_pattern']
      import_by_dn = form.cleaned_data['dn']
      server = form.cleaned_data.get('server')
      try:
        connection = ldap_access.get_connection_from_server(server)
        users = import_ldap_users(connection, username_pattern, False, import_by_dn)
      except ldap.LDAPError, e:
        LOG.error("LDAP Exception: %s" % e)
        raise PopupException(_('There was an error when communicating with LDAP'), detail=str(e))
      except AssertionError, e:
        raise PopupException(_('There was a problem with some of the LDAP information'), detail=str(e))

      if users and form.cleaned_data['ensure_home_directory']:
        for user in users:
          try:
            ensure_home_directory(request.fs, user.username)
          except (IOError, WebHdfsException), e:
            request.error(_("Cannot make home directory for user %s.") % user.username)
Beispiel #3
0
def add_ldap_users(request):
  """
  add_ldap_users(request) -> reply

  Handler for importing LDAP users into the Hue database.

  If a user has been previously imported, this will sync their user information.
  If the LDAP request failed, the error message is generic right now.
  """
  if not request.user.is_superuser:
    raise PopupException(_("You must be a superuser to add another user."), error_code=401)

  if request.method == 'POST':
    form = AddLdapUsersForm(request.POST)
    if form.is_valid():
      username_pattern = form.cleaned_data['username_pattern']
      import_by_dn = form.cleaned_data['dn']
      server = form.cleaned_data.get('server')
      try:
        connection = ldap_access.get_connection_from_server(server)
        users = import_ldap_users(connection, username_pattern, False, import_by_dn)
      except ldap.LDAPError, e:
        LOG.error("LDAP Exception: %s" % e)
        raise PopupException(_('There was an error when communicating with LDAP'), detail=str(e))
      except AssertionError, e:
        raise PopupException(_('There was a problem with some of the LDAP information'), detail=str(e))

      if users and form.cleaned_data['ensure_home_directory']:
        for user in users:
          try:
            ensure_home_directory(request.fs, user.username)
          except (IOError, WebHdfsException), e:
            request.error(_("Cannot make home directory for user %s.") % user.username)
Beispiel #4
0
def add_ldap_users(request):
  """
  add_ldap_users(request) -> reply

  Handler for importing LDAP users into the Hue database.

  If a user has been previously imported, this will sync their user information.
  If the LDAP request failed, the error message is generic right now.
  """
  if not request.user.is_superuser:
    raise PopupException(_("You must be a superuser to add another user."), error_code=401)

  if request.method == 'POST':
    form = AddLdapUsersForm(request.POST)
    if form.is_valid():
      username_pattern = form.cleaned_data['username_pattern']
      import_by_dn = form.cleaned_data['dn']
      try:
        users = import_ldap_users(username_pattern, False, import_by_dn)
      except ldap.LDAPError, e:
        LOG.error("LDAP Exception: %s" % e)
        raise PopupException(_('There was an error when communicating with LDAP'), detail=str(e))

      if users and form.cleaned_data['ensure_home_directory']:
        for user in users:
          try:
            ensure_home_directory(request.fs, user.username)
          except (IOError, WebHdfsException), e:
            request.error(_("Cannot make home directory for user %s." % user.username))

      if not users:
        errors = form._errors.setdefault('username_pattern', ErrorList())
        errors.append(_('Could not get LDAP details for users in pattern %s.') % username_pattern)
      else:
        return redirect(reverse(list_users))
Beispiel #5
0
                        ensure_home_directory(request.fs, user.username)
                    except (IOError, WebHdfsException), e:
                        request.error(
                            _("Cannot make home directory for user %s." %
                              user.username))

            if not users:
                errors = form._errors.setdefault('username_pattern',
                                                 ErrorList())
                errors.append(
                    _('Could not get LDAP details for users in pattern %s.') %
                    username_pattern)
            else:
                return redirect(reverse(list_users))
    else:
        form = AddLdapUsersForm()

    return render('add_ldap_users.mako', request, dict(form=form))


def add_ldap_groups(request):
    """
  add_ldap_groups(request) -> reply

  Handler for importing LDAP groups into the Hue database.

  If a group has been previously imported, this will sync membership within the
  group with the LDAP server. If --import-members is specified, it will import
  all unimported users.
  """
    if not request.user.is_superuser: