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: raise PopupException(_("You must be a superuser to add another group."), error_code=401) if request.method == 'POST': form = AddLdapGroupsForm(request.POST) if form.is_valid(): groupname_pattern = form.cleaned_data['groupname_pattern'] import_by_dn = form.cleaned_data['dn'] import_members = form.cleaned_data['import_members'] try: groups = import_ldap_groups(groupname_pattern, import_members, 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 groups: return redirect(reverse(list_groups)) else: errors = form._errors.setdefault('groupname_pattern', ErrorList()) errors.append(_('Could not get LDAP details for groups in pattern %s') % groupname_pattern)
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: raise PopupException(_("You must be a superuser to add another group."), error_code=401) if request.method == 'POST': form = AddLdapGroupsForm(request.POST) if form.is_valid(): groupname_pattern = form.cleaned_data['groupname_pattern'] import_by_dn = form.cleaned_data['dn'] import_members = form.cleaned_data['import_members'] import_members_recursive = form.cleaned_data['import_members_recursive'] try: groups = import_ldap_groups(groupname_pattern, import_members=import_members, import_members_recursive=import_members_recursive, sync_users=True, import_by_dn=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 groups: return redirect(reverse(list_groups)) else: errors = form._errors.setdefault('groupname_pattern', ErrorList()) errors.append(_('Could not get LDAP details for groups in pattern %s') % groupname_pattern)
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: raise PopupException( _("You must be a superuser to add another group."), error_code=401) if request.method == 'POST': form = AddLdapGroupsForm(request.POST) if form.is_valid(): groupname_pattern = form.cleaned_data['groupname_pattern'] import_by_dn = form.cleaned_data['dn'] import_members = form.cleaned_data['import_members'] import_members_recursive = form.cleaned_data[ 'import_members_recursive'] is_ensuring_home_directories = form.cleaned_data[ 'ensure_home_directories'] server = form.cleaned_data.get('server') try: connection = ldap_access.get_connection_from_server(server) groups = import_ldap_groups( connection, groupname_pattern, import_members=import_members, import_members_recursive=import_members_recursive, sync_users=True, import_by_dn=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)) unique_users = set() if is_ensuring_home_directories and groups: for group in groups: for user in group.user_set.all(): unique_users.add(user) for user in unique_users: try: ensure_home_directory(request.fs, user.username) except (IOError, WebHdfsException), e: raise PopupException(_( "Exception creating home directory for LDAP user %s in group %s." ) % (user, group), detail=e)
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: request.audit = { 'operation': 'ADD_LDAP_GROUPS', 'operationText': _get_failed_operation_text(request.user.username, 'ADD_LDAP_GROUPS'), 'allowed': False, } raise PopupException(_("You must be a superuser to add another group."), error_code=401) if request.method == 'POST': form = AddLdapGroupsForm(request.POST) if form.is_valid(): groupname_pattern = form.cleaned_data['groupname_pattern'] import_by_dn = form.cleaned_data['dn'] import_members = form.cleaned_data['import_members'] import_members_recursive = form.cleaned_data['import_members_recursive'] is_ensuring_home_directories = form.cleaned_data['ensure_home_directories'] server = form.cleaned_data.get('server') try: failed_ldap_users = [] connection = ldap_access.get_connection_from_server(server) groups = import_ldap_groups(connection, groupname_pattern, import_members=import_members, import_members_recursive=import_members_recursive, sync_users=True, import_by_dn=import_by_dn, failed_users=failed_ldap_users) except (ldap.LDAPError, LdapBindException), e: LOG.error(_("LDAP Exception: %s") % e) raise PopupException(_('There was an error when communicating with LDAP'), detail=str(e)) except ValidationError, e: raise PopupException(_('There was a problem with some of the LDAP information'), detail=str(e)) unique_users = set() if is_ensuring_home_directories and groups: for group in groups: for user in group.user_set.all(): unique_users.add(user) for user in unique_users: try: ensure_home_directory(request.fs, user.username) except (IOError, WebHdfsException), e: raise PopupException(_("Exception creating home directory for LDAP user %s in group %s.") % (user, group), detail=e)