本文讨论可用于简化动态成员身份组规则的最常见方法。 更简单、更高效的规则可以更好地处理动态组。
为动态成员身份组编写成员身份规则时,请遵循本文中的提示,确保尽可能高效地创建这些规则。
最小化 -match 运算符的使用
在规则中尽可能少地使用-match
运算符。 相反,请浏览是否可以使用 -startswith
或 -eq
运算符。 请考虑使用其他属性,来编写规则以在不使用 -match
运算符的情况下选择组的用户。
例如,如果要为包含所有城市为拉各斯的用户的组创建规则,请不要使用以下规则:
user.city -match "ago"
user.city -match ".*?ago.*"
最好使用类似于以下示例的规则:
user.city -startswith "Lag"
或者,最重要的是:
user.city -eq "Lagos"
最小化 -contains 运算符的使用
同样 -match
,在规则中尽量减少使用 -contains
运算符。 相反,请浏览是否可以使用 -startswith
或 -eq
运算符。 使用 -contains
可能会增加处理时间,尤其是对于拥有众多动态成员组的租户。
使用更少的 -or 运算符
确定规则何时对同一属性使用各种值(与 -or
运算符链接在一起)。 请改用 -in
运算符将它们分组为单个条件。 单个条件使规则更易于评估。
例如,不要使用如下所示的规则:
(user.department -eq "Accounts" -and user.city -eq "Lagos") -or
(user.department -eq "Accounts" -and user.city -eq "Ibadan") -or
(user.department -eq "Accounts" -and user.city -eq "Kaduna") -or
(user.department -eq "Accounts" -and user.city -eq "Abuja") -or
(user.department -eq "Accounts" -and user.city -eq "Port Harcourt")
最好使用类似于以下示例的规则:
user.department -eq "Accounts" -and user.city -in ["Lagos", "Ibadan", "Kaduna", "Abuja", "Port Harcourt"]
相反,识别具有相同属性但不等于不同值,并且与 -and
操作符链接的类似子标准。 然后使用 -notin
运算符将这些值分组为单个条件,使规则更易于理解和评估。
例如,不要使用如下所示的规则:
(user.city -ne "Lagos") -and (user.city -ne "Ibadan") -and (user.city -ne "Kaduna") -and (user.city -ne "Abuja") -and (user.city -ne "Port Harcourt")
最好使用类似于以下示例的规则:
user.city -notin ["Lagos", "Ibadan", "Kaduna", "Abuja", "Port Harcourt"]
避免冗余条件
确保不要在规则中使用冗余条件。 例如,不要使用如下所示的规则:
user.city -eq "Lagos" or user.city -startswith "Lag"
最好使用类似于以下示例的规则:
user.city -startswith "Lag"