【问题标题】:Role Based Authorization in .NET with PrincipalPermission and SecurityAction.Assert.NET 中基于角色的授权与 PrincipalPermission 和 SecurityAction.Assert
【发布时间】:2010-08-01 22:55:11
【问题描述】:

我有一个带有

属性的类
[PrincipalPermission(SecurityAction.Demand, Authenticated = true)]
 public class MyProtectedClass { }

这按预期工作,当当前主体未通过身份验证时,调用者将被拒绝访问。在一个特定的场景中,我希望这个逻辑短路......也就是说,调用者不需要经过身份验证。实现这一点的一种方法当然是用一个 Identity 的 IsAuthenticated 属性为 true 的新线程重置线程的 CurrentPrincipal...

但是,我认为我应该能够通过调用者Assert 来实现这一点:

[PrincipalPermission(SecurityAction.Assert, Authenticated = true)]
 public class MyExemptedCallerClass { }

这不会产生预期的效果,但是MyExemptedCallerClass 中的方法仍然会抛出异常尝试实例化MyProtectedClass

有什么想法吗?是否有另一种/更好的方法来实现这一点?

谢谢。

【问题讨论】:

    标签: c# .net permissions assert


    【解决方案1】:

    这里有几个想法:

    1. 将 PrincipalPermission 属性放在要保护的方法上,而不是类上。
    2. 如果一段代码需要由经过身份验证和未经身份验证的用户运行,那么它可能不属于 MyProtectedClass。也许它属于 MyUnprotectedClass,它只能在您上面提到的一种特定场景中实例化。经过身份验证的客户端仍然可以通过调用 MyProtectedClass 上的外观方法来访问 MyUnprotectedClass 中的代码。

    【讨论】:

      猜你喜欢
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 2019-10-13
      • 2018-04-17
      • 2013-10-21
      • 1970-01-01
      相关资源
      最近更新 更多