mirror of https://github.com/jumpserver/jumpserver
feat: rdp协议新增username表达式,匹配更多特殊字符
parent
90de229631
commit
c2d271f00b
|
@ -4,7 +4,7 @@ from django.db.models import Count
|
||||||
|
|
||||||
from common.mixins.serializers import BulkSerializerMixin
|
from common.mixins.serializers import BulkSerializerMixin
|
||||||
from common.utils import ssh_pubkey_gen
|
from common.utils import ssh_pubkey_gen
|
||||||
from common.validators import alphanumeric_re, alphanumeric_cn_re
|
from common.validators import alphanumeric_re, alphanumeric_cn_re, alphanumeric_win_re
|
||||||
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
||||||
from ..models import SystemUser, Asset
|
from ..models import SystemUser, Asset
|
||||||
from .utils import validate_password_contains_left_double_curly_bracket
|
from .utils import validate_password_contains_left_double_curly_bracket
|
||||||
|
@ -107,9 +107,12 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
def validate_username(self, username):
|
def validate_username(self, username):
|
||||||
protocol = self.get_initial_value("protocol")
|
protocol = self.get_initial_value("protocol")
|
||||||
if username:
|
if username:
|
||||||
regx = alphanumeric_re
|
if protocol == SystemUser.Protocol.telnet:
|
||||||
if protocol == SystemUser.Protocol.telnet or protocol == SystemUser.Protocol.rdp:
|
|
||||||
regx = alphanumeric_cn_re
|
regx = alphanumeric_cn_re
|
||||||
|
elif protocol == SystemUser.Protocol.rdp:
|
||||||
|
regx = alphanumeric_win_re
|
||||||
|
else:
|
||||||
|
regx = alphanumeric_re
|
||||||
if not regx.match(username):
|
if not regx.match(username):
|
||||||
raise serializers.ValidationError(_('Special char not allowed'))
|
raise serializers.ValidationError(_('Special char not allowed'))
|
||||||
return username
|
return username
|
||||||
|
|
|
@ -15,7 +15,9 @@ alphanumeric = RegexValidator(r'^[0-9a-zA-Z_@\-\.]*$', _('Special char not allow
|
||||||
|
|
||||||
alphanumeric_re = re.compile(r'^[0-9a-zA-Z_@\-\.]*$')
|
alphanumeric_re = re.compile(r'^[0-9a-zA-Z_@\-\.]*$')
|
||||||
|
|
||||||
alphanumeric_cn_re = re.compile(r'^[0-9a-zA-Z_@\$\-\.\u4E00-\u9FA5]*$')
|
alphanumeric_cn_re = re.compile(r'^[0-9a-zA-Z_@\-\.\u4E00-\u9FA5]*$')
|
||||||
|
|
||||||
|
alphanumeric_win_re = re.compile(r'^[0-9a-zA-Z_@#%&~\^\$\-\.\u4E00-\u9FA5]*$')
|
||||||
|
|
||||||
|
|
||||||
class ProjectUniqueValidator(UniqueTogetherValidator):
|
class ProjectUniqueValidator(UniqueTogetherValidator):
|
||||||
|
|
Loading…
Reference in New Issue