ソースを参照

feat(ldap): supported the `memberOf` syntax in the extensible match filter

firest 1 年間 前
コミット
d410440783

+ 1 - 1
apps/emqx_ldap/src/emqx_ldap.app.src

@@ -1,6 +1,6 @@
 {application, emqx_ldap, [
     {description, "EMQX LDAP Connector"},
-    {vsn, "0.1.10"},
+    {vsn, "0.1.11"},
     {registered, []},
     {applications, [
         kernel,

+ 29 - 25
apps/emqx_ldap/src/emqx_ldap_filter_parser.yrl

@@ -1,21 +1,22 @@
-Header "%%--------------------------------------------------------------------
-%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
-%%
-%% Licensed under the Apache License, Version 2.0 (the \"License\");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%%     http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an \"AS IS\" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%%--------------------------------------------------------------------".
+Header
+"%%--------------------------------------------------------------------\n"
+"%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.\n"
+"%%\n"
+"%% Licensed under the Apache License, Version 2.0 (the \"License\");\n"
+"%% you may not use this file except in compliance with the License.\n"
+"%% You may obtain a copy of the License at\n"
+"%%\n"
+"%%     http://www.apache.org/licenses/LICENSE-2.0\n"
+"%%\n"
+"%% Unless required by applicable law or agreed to in writing, software\n"
+"%% distributed under the License is distributed on an \"AS IS\" BASIS,\n"
+"%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
+"%% See the License for the specific language governing permissions and\n"
+"%% limitations under the License.\n"
+"%%--------------------------------------------------------------------".
 
 Nonterminals
-filter filtercomp filterlist item simple present substring initial any final extensible attr value type dnattrs matchingrule dnvalue.
+filter filtercomp filterlist item simple present substring initial any final extensible attr value type dnattrs matchingrule dnvalue complexValue.
 
 Terminals
 lparen rparen 'and' 'or' 'not' equal approx greaterOrEqual lessOrEqual asterisk colon dn string comma.
@@ -51,9 +52,7 @@ item->
     extensible: '$1'.
 
 simple ->
-    attr equal value: equal('$1', '$3').
-simple ->
-    attr equal dnvalue: equal('$1', '$3').
+    attr equal complexValue: equal('$1', '$3').
 simple ->
     attr approx value: approx('$1', '$3').
 simple ->
@@ -83,18 +82,18 @@ any -> any value asterisk: 'any'('$1', '$2').
 any -> '$empty': [].
 
 extensible ->
-    type dnattrs matchingrule colon equal value : extensible('$6', ['$1', '$2', '$3']).
+    type dnattrs matchingrule colon equal complexValue : extensible('$6', ['$1', '$2', '$3']).
 extensible ->
-    type dnattrs colon equal value: extensible('$5', ['$1', '$2']).
+    type dnattrs colon equal complexValue: extensible('$5', ['$1', '$2']).
 extensible ->
-    type matchingrule colon equal value: extensible('$5', ['$1', '$2']).
+    type matchingrule colon equal complexValue: extensible('$5', ['$1', '$2']).
 extensible ->
-    type colon equal value: extensible('$4', ['$1']).
+    type colon equal complexValue: extensible('$4', ['$1']).
 
 extensible ->
-    dnattrs matchingrule colon equal value: extensible('$5', ['$1', '$2']).
+    dnattrs matchingrule colon equal complexValue: extensible('$5', ['$1', '$2']).
 extensible ->
-    matchingrule colon equal value: extensible('$4', ['$1']).
+    matchingrule colon equal complexValue: extensible('$4', ['$1']).
 
 attr ->
     string: get_value('$1').
@@ -107,6 +106,11 @@ dnvalue ->
 dnvalue ->
     string equal string: make_dn_value('$1', '$3').
 
+complexValue ->
+    value: '$1'.
+complexValue ->
+    dnvalue: '$1'.
+
 type ->
     value: {type, '$1'}.
 

+ 11 - 0
apps/emqx_ldap/test/emqx_ldap_filter_SUITE.erl

@@ -264,6 +264,17 @@ t_member_of(_Config) ->
         parse("(&(a=b)(memberOf=CN=GroupName,OU=emqx,DC=WL,DC=com))")
     ).
 
+t_extensible_member_of(_Config) ->
+    ?assertEqual(
+        'and'([
+            equalityMatch("a", "b"),
+            extensibleMatch("CN=GroupName,OU=emqx,DC=WL,DC=com", [
+                {type, "memberOf"}, {matchingRule, "1.2.840.113556.1.4.1941"}
+            ])
+        ]),
+        parse("(&(a=b)(memberOf:1.2.840.113556.1.4.1941:=CN=GroupName,OU=emqx,DC=WL,DC=com))")
+    ).
+
 % %%------------------------------------------------------------------------------
 % %% Helpers
 % %%------------------------------------------------------------------------------

+ 3 - 0
changes/ce/feat-14147.en.md

@@ -0,0 +1,3 @@
+Added support for using `memberOf` syntax in LDAP extensible match filter, for example:
+
+`(&(objectClass=class)(memberOf:1.2.840.113556.1.4.1941:=CN=GroupName,OU=emqx,DC=WL,DC=com))`