在计入使用配额之前检查用户是否属于特定组
Check if user belongs to specific group before counting towards usage quota
我想制定一项政策,让我们的员工可以在不计入任何配额的情况下拨打 API。我们的员工属于 API 管理解决方案中的一个特定组。我希望不属于该组的所有其他用户都计入其订阅的使用配额。
我的问题是我不知道如何检查用户是否在 when
条件下的特定组中,because the group list on the user object is a list of objects。
当它是一个映射(例如 headers)或只是一个字符串数组时,它看起来很简单:
<!-- for maps, but it is not a map -->
<when condition="@(context.User.Groups.ContainsKey("myGroup"))" />
<!-- for arrays if you know all properties -->
<when condition="@(context.User.Groups.Contains("myGroup"))" />
当我只有组名而没有组 ID 时,如何创建这样的策略?
<when condition="@(!context.User.isInGroup("myGroup")">
<quota calls="10000" bandwidth="40000" renewal-period="3600" />
</when>
或者换一种说法;
如何确定 object 的列表是否包含 object 以及 属性 的特定值? Kind of like find in JavaScript.
使用 Linq Any method 判断真假,取决于给定名称是否存在。
检查 User
是否在给定组中:
<when condition="@(context.User.Groups.Any(x => x.Name == "myGroup"))">
如果你想要超级安全,还检查 User
对象是否存在(如果你调用 API 使用“内置所有访问订阅”,它可以为空):
<when condition="@(context.User != null && context.User.Groups.Any(x => x.Name == "myGroup"))">
并恢复上述条件并检查 User
是否不在给定组中:
<when condition="@(context.User == null || !context.User.Groups.Any(x => x.Name == "myGroup"))">
我想制定一项政策,让我们的员工可以在不计入任何配额的情况下拨打 API。我们的员工属于 API 管理解决方案中的一个特定组。我希望不属于该组的所有其他用户都计入其订阅的使用配额。
我的问题是我不知道如何检查用户是否在 when
条件下的特定组中,because the group list on the user object is a list of objects。
当它是一个映射(例如 headers)或只是一个字符串数组时,它看起来很简单:
<!-- for maps, but it is not a map -->
<when condition="@(context.User.Groups.ContainsKey("myGroup"))" />
<!-- for arrays if you know all properties -->
<when condition="@(context.User.Groups.Contains("myGroup"))" />
当我只有组名而没有组 ID 时,如何创建这样的策略?
<when condition="@(!context.User.isInGroup("myGroup")">
<quota calls="10000" bandwidth="40000" renewal-period="3600" />
</when>
或者换一种说法;
如何确定 object 的列表是否包含 object 以及 属性 的特定值? Kind of like find in JavaScript.
使用 Linq Any method 判断真假,取决于给定名称是否存在。
检查 User
是否在给定组中:
<when condition="@(context.User.Groups.Any(x => x.Name == "myGroup"))">
如果你想要超级安全,还检查 User
对象是否存在(如果你调用 API 使用“内置所有访问订阅”,它可以为空):
<when condition="@(context.User != null && context.User.Groups.Any(x => x.Name == "myGroup"))">
并恢复上述条件并检查 User
是否不在给定组中:
<when condition="@(context.User == null || !context.User.Groups.Any(x => x.Name == "myGroup"))">