emqx_authz_ldap_schema.erl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_authz_ldap_schema).
  17. -include("emqx_auth_ldap.hrl").
  18. -include_lib("hocon/include/hoconsc.hrl").
  19. -behaviour(emqx_authz_schema).
  20. -export([
  21. type/0,
  22. fields/1,
  23. desc/1,
  24. source_refs/0,
  25. select_union_member/2,
  26. namespace/0
  27. ]).
  28. namespace() -> "authz".
  29. type() -> ?AUTHZ_TYPE.
  30. fields(ldap) ->
  31. emqx_authz_schema:authz_common_fields(?AUTHZ_TYPE) ++
  32. [
  33. {publish_attribute, attribute_meta(publish_attribute, <<"mqttPublishTopic">>)},
  34. {subscribe_attribute, attribute_meta(subscribe_attribute, <<"mqttSubscriptionTopic">>)},
  35. {all_attribute, attribute_meta(all_attribute, <<"mqttPubSubTopic">>)},
  36. {query_timeout,
  37. ?HOCON(
  38. emqx_schema:timeout_duration_ms(),
  39. #{
  40. desc => ?DESC(query_timeout),
  41. default => <<"5s">>
  42. }
  43. )}
  44. ] ++
  45. emqx_ldap:fields(config).
  46. desc(ldap) ->
  47. emqx_authz_ldap:description();
  48. desc(_) ->
  49. undefined.
  50. source_refs() ->
  51. [?R_REF(ldap)].
  52. select_union_member(#{<<"type">> := ?AUTHZ_TYPE_BIN}, _) ->
  53. ?R_REF(ldap);
  54. select_union_member(_Value, _) ->
  55. undefined.
  56. %%--------------------------------------------------------------------
  57. %% Internal Functions
  58. %%--------------------------------------------------------------------
  59. attribute_meta(Name, Default) ->
  60. ?HOCON(
  61. string(),
  62. #{
  63. default => Default,
  64. desc => ?DESC(Name)
  65. }
  66. ).