mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-13 06:34:42 +00:00
commit
4f532f588b
@ -185,7 +185,7 @@ class Node(OrgModelMixin):
|
|||||||
else:
|
else:
|
||||||
set_current_org(Organization.root())
|
set_current_org(Organization.root())
|
||||||
org_nodes_roots = cls.objects.filter(key__regex=r'^[0-9]+$')
|
org_nodes_roots = cls.objects.filter(key__regex=r'^[0-9]+$')
|
||||||
org_nodes_roots_keys = org_nodes_roots.values_list('key', flat=True)
|
org_nodes_roots_keys = org_nodes_roots.values_list('key', flat=True) or [0]
|
||||||
key = max([int(k) for k in org_nodes_roots_keys]) + 1
|
key = max([int(k) for k in org_nodes_roots_keys]) + 1
|
||||||
set_current_org(_current_org)
|
set_current_org(_current_org)
|
||||||
root = cls.objects.create(key=key, value=_current_org.name)
|
root = cls.objects.create(key=key, value=_current_org.name)
|
||||||
|
@ -48,7 +48,7 @@ class LDAPTestingAPI(APIView):
|
|||||||
bind_dn = serializer.validated_data["AUTH_LDAP_BIND_DN"]
|
bind_dn = serializer.validated_data["AUTH_LDAP_BIND_DN"]
|
||||||
password = serializer.validated_data["AUTH_LDAP_BIND_PASSWORD"]
|
password = serializer.validated_data["AUTH_LDAP_BIND_PASSWORD"]
|
||||||
use_ssl = serializer.validated_data.get("AUTH_LDAP_START_TLS", False)
|
use_ssl = serializer.validated_data.get("AUTH_LDAP_START_TLS", False)
|
||||||
search_ou = serializer.validated_data["AUTH_LDAP_SEARCH_OU"]
|
search_ougroup = serializer.validated_data["AUTH_LDAP_SEARCH_OU"]
|
||||||
search_filter = serializer.validated_data["AUTH_LDAP_SEARCH_FILTER"]
|
search_filter = serializer.validated_data["AUTH_LDAP_SEARCH_FILTER"]
|
||||||
attr_map = serializer.validated_data["AUTH_LDAP_USER_ATTR_MAP"]
|
attr_map = serializer.validated_data["AUTH_LDAP_USER_ATTR_MAP"]
|
||||||
|
|
||||||
@ -64,18 +64,19 @@ class LDAPTestingAPI(APIView):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response({"error": str(e)}, status=401)
|
return Response({"error": str(e)}, status=401)
|
||||||
|
|
||||||
ok = conn.search(search_ou, search_filter % ({"user": "*"}),
|
|
||||||
attributes=list(attr_map.values()))
|
|
||||||
if not ok:
|
|
||||||
return Response({"error": "Search no entry matched"}, status=401)
|
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
for entry in conn.entries:
|
for search_ou in str(search_ougroup).split("|"):
|
||||||
user = {}
|
ok = conn.search(search_ou, search_filter % ({"user": "*"}),
|
||||||
for attr, mapping in attr_map.items():
|
attributes=list(attr_map.values()))
|
||||||
if hasattr(entry, mapping):
|
if not ok:
|
||||||
user[attr] = getattr(entry, mapping)
|
return Response({"error": _("Search no entry matched in ou {}").format(search_ou)}, status=401)
|
||||||
users.append(user)
|
|
||||||
|
for entry in conn.entries:
|
||||||
|
user = {}
|
||||||
|
for attr, mapping in attr_map.items():
|
||||||
|
if hasattr(entry, mapping):
|
||||||
|
user[attr] = getattr(entry, mapping)
|
||||||
|
users.append(user)
|
||||||
if len(users) > 0:
|
if len(users) > 0:
|
||||||
return Response({"msg": _("Match {} s users").format(len(users))})
|
return Response({"msg": _("Match {} s users").format(len(users))})
|
||||||
else:
|
else:
|
||||||
|
@ -114,7 +114,8 @@ class LDAPSettingForm(BaseForm):
|
|||||||
widget=forms.PasswordInput, required=False
|
widget=forms.PasswordInput, required=False
|
||||||
)
|
)
|
||||||
AUTH_LDAP_SEARCH_OU = forms.CharField(
|
AUTH_LDAP_SEARCH_OU = forms.CharField(
|
||||||
label=_("User OU"), initial='ou=tech,dc=jumpserver,dc=org'
|
label=_("User OU"), initial='ou=tech,dc=jumpserver,dc=org',
|
||||||
|
help_text=_("Use | split User OUs")
|
||||||
)
|
)
|
||||||
AUTH_LDAP_SEARCH_FILTER = forms.CharField(
|
AUTH_LDAP_SEARCH_FILTER = forms.CharField(
|
||||||
label=_("User search filter"), initial='(cn=%(user)s)',
|
label=_("User search filter"), initial='(cn=%(user)s)',
|
||||||
|
@ -5,7 +5,7 @@ from django.db import models
|
|||||||
from django.db.utils import ProgrammingError, OperationalError
|
from django.db.utils import ProgrammingError, OperationalError
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django_auth_ldap.config import LDAPSearch
|
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
|
||||||
|
|
||||||
|
|
||||||
class SettingQuerySet(models.QuerySet):
|
class SettingQuerySet(models.QuerySet):
|
||||||
@ -72,10 +72,11 @@ class Setting(models.Model):
|
|||||||
settings.AUTHENTICATION_BACKENDS.remove(settings.AUTH_LDAP_BACKEND)
|
settings.AUTHENTICATION_BACKENDS.remove(settings.AUTH_LDAP_BACKEND)
|
||||||
|
|
||||||
if self.name == "AUTH_LDAP_SEARCH_FILTER":
|
if self.name == "AUTH_LDAP_SEARCH_FILTER":
|
||||||
settings.AUTH_LDAP_USER_SEARCH = LDAPSearch(
|
settings.AUTH_LDAP_USER_SEARCH_UNION = [
|
||||||
settings.AUTH_LDAP_SEARCH_OU, ldap.SCOPE_SUBTREE,
|
LDAPSearch(USER_SEARCH, ldap.SCOPE_SUBTREE, settings.AUTH_LDAP_SEARCH_FILTER)
|
||||||
settings.AUTH_LDAP_SEARCH_FILTER,
|
for USER_SEARCH in str(settings.AUTH_LDAP_SEARCH_OU).split("|")
|
||||||
)
|
]
|
||||||
|
settings.AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(*settings.AUTH_LDAP_USER_SEARCH_UNION)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "settings"
|
db_table = "settings"
|
||||||
|
@ -79,7 +79,6 @@ class AdminUserRequiredMixin(UserPassesTestMixin):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
print("Current org: {}".format(current_org))
|
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
@ -92,6 +91,4 @@ class AdminUserRequiredMixin(UserPassesTestMixin):
|
|||||||
print("Is org admin")
|
print("Is org admin")
|
||||||
return redirect('orgs:switch-a-org')
|
return redirect('orgs:switch-a-org')
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
else:
|
|
||||||
print(current_org.can_admin_by(request.user))
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
@ -14,7 +14,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import ldap
|
import ldap
|
||||||
from django_auth_ldap.config import LDAPSearch
|
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
@ -357,9 +357,11 @@ AUTH_LDAP_SEARCH_OU = CONFIG.AUTH_LDAP_SEARCH_OU
|
|||||||
AUTH_LDAP_SEARCH_FILTER = CONFIG.AUTH_LDAP_SEARCH_FILTER
|
AUTH_LDAP_SEARCH_FILTER = CONFIG.AUTH_LDAP_SEARCH_FILTER
|
||||||
AUTH_LDAP_START_TLS = CONFIG.AUTH_LDAP_START_TLS
|
AUTH_LDAP_START_TLS = CONFIG.AUTH_LDAP_START_TLS
|
||||||
AUTH_LDAP_USER_ATTR_MAP = CONFIG.AUTH_LDAP_USER_ATTR_MAP
|
AUTH_LDAP_USER_ATTR_MAP = CONFIG.AUTH_LDAP_USER_ATTR_MAP
|
||||||
AUTH_LDAP_USER_SEARCH = LDAPSearch(
|
AUTH_LDAP_USER_SEARCH_UNION = [
|
||||||
AUTH_LDAP_SEARCH_OU, ldap.SCOPE_SUBTREE, AUTH_LDAP_SEARCH_FILTER,
|
LDAPSearch(USER_SEARCH, ldap.SCOPE_SUBTREE, AUTH_LDAP_SEARCH_FILTER)
|
||||||
)
|
for USER_SEARCH in str(AUTH_LDAP_SEARCH_OU).split("|")
|
||||||
|
]
|
||||||
|
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(*AUTH_LDAP_USER_SEARCH_UNION)
|
||||||
AUTH_LDAP_GROUP_SEARCH_OU = CONFIG.AUTH_LDAP_GROUP_SEARCH_OU
|
AUTH_LDAP_GROUP_SEARCH_OU = CONFIG.AUTH_LDAP_GROUP_SEARCH_OU
|
||||||
AUTH_LDAP_GROUP_SEARCH_FILTER = CONFIG.AUTH_LDAP_GROUP_SEARCH_FILTER
|
AUTH_LDAP_GROUP_SEARCH_FILTER = CONFIG.AUTH_LDAP_GROUP_SEARCH_FILTER
|
||||||
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
|
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
|
||||||
|
@ -43,7 +43,6 @@ class OrgManager(models.Manager):
|
|||||||
def all(self):
|
def all(self):
|
||||||
if not current_org:
|
if not current_org:
|
||||||
msg = 'You can `objects.set_current_org(org).all()` then run it'
|
msg = 'You can `objects.set_current_org(org).all()` then run it'
|
||||||
warnings.warn(msg)
|
|
||||||
return self
|
return self
|
||||||
else:
|
else:
|
||||||
return super(OrgManager, self).all()
|
return super(OrgManager, self).all()
|
||||||
|
@ -80,7 +80,7 @@
|
|||||||
{# <li id="download"><a href="">{% trans 'File download' %}</a></li>#}
|
{# <li id="download"><a href="">{% trans 'File download' %}</a></li>#}
|
||||||
{# </ul>#}
|
{# </ul>#}
|
||||||
{#</li>#}
|
{#</li>#}
|
||||||
{% if XPACK_ENABLED %}
|
{% if XPACK_PLUGINS %}
|
||||||
<li id="xpack">
|
<li id="xpack">
|
||||||
<a>
|
<a>
|
||||||
<i class="fa fa-sitemap" style="width: 14px"></i> <span class="nav-label">{% trans 'XPack' %}</span><span class="fa arrow"></span>
|
<i class="fa fa-sitemap" style="width: 14px"></i> <span class="nav-label">{% trans 'XPack' %}</span><span class="fa arrow"></span>
|
||||||
|
Loading…
Reference in New Issue
Block a user