asp.net-mvc-4 – 使用ASP.NET MVC进行基于声明的授权
我正在阅读很多博客文章和stackoverflow答案,但我仍然无法找到一个使用基于声明的身份验证和授权的真实世界开源项目,以便我可以了解如何实际实现这些.
到目前为止,我能找到的是Thinktecture.IdentityModel和this blog在示例网站上实现基于声明的授权.如果你们可以指出一些使用声明的开源项目,那将非常有帮助. 我感兴趣的是如何使用数据库检索我的应用程序的声明. 到目前为止,我所尝试的是使用内存声明存储来模拟数据库,我已经创建了一个CustomClaimsTransformer和CustomAuthorisationManager. public class CustomClaimsTransformer : ClaimsAuthenticationManager { public override ClaimsPrincipal Authenticate(string resourceName,ClaimsPrincipal incomingPrincipal) { //validate name claim string nameClaimValue = incomingPrincipal.Identity.Name; return CreatePrincipal(nameClaimValue); } private ClaimsPrincipal CreatePrincipal(string userName) { int userId = ClaimStore.Users.First(u => u.Value == userName).Key; var claims = ClaimStore.ClaimsSet.Where(c => c.Key == userId); var claimsCollection = claims.Select(kp => kp.Value).ToList(); return new ClaimsPrincipal(new ClaimsIdentity(claimsCollection,"Custom")); } } public class CustomAuthorisationManager : ClaimsAuthorizationManager { public override bool CheckAccess(AuthorizationContext context) { string resource = context.Resource.First().Value; string action = context.Action.First().Value; if (action == "Show" && resource == "Code") { bool likesJava = context.Principal.HasClaim(ClaimStore._httpMyclaimsUsers,"True"); return likesJava; } else if (action == "Read" && resource == "Departments") { bool readDeps = context.Principal.HasClaim(ClaimStore._httpMyclaimsDepartments,"Read"); return readDeps; } return false; } } 如何在没有太多IF条件的情况下在现实场景中实现这些? 解决方法
尝试以下链接,它似乎是一个体面的解决方案
http://developers.axiomatics.com/blog/index/entry/custom-claims-based-authorization-in-net-using-axiomatics-pep-sdk-for-net.html 您还可以定义策略并加载它 http://msdn.microsoft.com/en-us/library/system.security.claims.claimsauthorizationmanager.loadcustomconfiguration.aspx 如何:使用WIF和ACS在声明感知的ASP.NET应用程序中实现声明授权 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Asp.net mvc 知多少(六)
- asp.net-mvc-3 – ASP.NET Web API问题 – 授权/认证
- asp.net – 页面生命周期中的哪个位置是母版页的加载事件(不
- asp.net – PlaceHolder vs Literal,用于添加在运行时生成的
- asp.net – .NET PrivateFontCollection – 完成后如何释放
- asp.net – Response.End()和Response.Flush()之间的差异
- 部署ASP.Net MVC应用程序的最便宜的方法是什么?
- asp.net-mvc – MVC中的Ws-Federation身份验证在SAML2.0验证
- asp.net-mvc – 在IIS Express中测试SignalR应用程序
- asp.net-mvc – Automapper和Windsor的问题
- asp.net-mvc – 如何在MVC5中从AccountControlle
- asp.net – 选择框更改事件中的setTimeout
- asp.net – 从多个Web.config文件访问appSetting
- asp.net – 如何在listview上执行不受控件约束的
- asp.net-mvc – 阻止MVC控制器动作的后台工作者
- asp.net – ListView与DataPager不工作
- asp.net – 在本地主机(Chrome和FF)上过期不到1年
- asp.net-mvc – MVC 3 – Razor – 从模型打印值
- asp.net – 如何关闭.NET站点进行维护?
- asp.net-mvc – Web API错误:’ObjectContent`1