我正在尝试以角度为我的应用程序进行基于角色的访问,我需要一些帮助,因为我是角度的新手......
\n\n首先,这是我在路线中确定哪些角色可以访问它的内容......
\n\n来自 app-routing.module.ts
\n\n{\n path: 'profile',\n component: ComunityComponent,\n canActivate: [AuthGuard],\n data: {\n allowedRoles: ['admin', 'user']\n }\n},\nRun Code Online (Sandbox Code Playgroud)\n\n其次,我使用 canActivate 函数来检查用户是否可以访问该路由。\n来自 auth.guard.ts
\n\nprivate hasAccess: boolean;\n\nconstructor(private router: Router, private auth: AuthService) {}\n\ncanActivate(next: ActivatedRouteSnapshot,\n state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {\n const allowedRoles = next.data.allowedRoles;\n if (localStorage.getItem('currentUser')) {\n return this.checkAccess(localStorage.getItem('currentUser'), allowedRoles);\n }\n\n this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});\n return false;\n }\nRun Code Online (Sandbox Code Playgroud)\n\n第三,我开发了 accessLoginToken 函数,它将通过 httpclient.get 服务查找登录用户的角色,该服务返回一个包含分配给用户的角色的数组。例子{success: true, roles:['user']}\n来自 auth.service.ts
accessLoginToken(token: string) {\n const check = …Run Code Online (Sandbox Code Playgroud) role-base-authorization typescript role-based-access-control angular auth-guard
在我的典型应用程序中,用户单击aspx页面中的按钮,调用C#业务对象,然后运行存储过程.
是应该在堆栈顶部,堆栈底部还是每个级别进行角色检查?似乎如果恶意用户可以调用一个方法,他可以调用任何方法,因此为了有效的安全性,您需要检查每个方法(并且这需要编写很多额外的代码).
这是一个典型的调用堆栈来说明我的问题:
Page_Load()
{
if(p.IsInRole("Managers")) //or equivalent attribute
{
AddAccount.Visible =true;
}
}
AddAccount_OnClick()
{
if(p.IsInRole("Managers")) //or equivalent attribute
{
//Add the account
Account.Add(...); //and maybe another role check...
}
}
-- TSQL doesn't understand .NET authorization, this call is in a 'trusted' subsystem
create proc Add_Account @user, @account_name
If @user in (Select user from role_table where role='manager')
-- Add the account
Run Code Online (Sandbox Code Playgroud) 我想对 DNN 角色的 API 调用应用授权。这样 DNN 本身就会检查登录的用户是否有权访问特定的 API 调用。我得到了一种解决方案,但不完全是我想要的。=>如何在基于 DNN 的 Web API 上处理安全/身份验证。此链接建议使用单独的模块进行 API 授权,以便我们可以为该模块分配角色,并通过在 API 调用上使用 [SupportedModules("ModuleName")] 属性来限制授权。我检查了这个例子,但没有运气......请建议我正确的方法来做到这一点。
我正在尝试了解ASP.NET身份验证和授权机制。我了解什么是要求和什么角色。在几乎所有相关的博客文章或此处的问题中,建议使用声明并避免使用角色。在这一点上,我感到困惑。如何使用没有角色的声明?(我通常会在用户注册后为他们分配角色。)
任何帮助表示赞赏。
谢谢
asp.net claims-based-identity role-base-authorization asp.net-identity
我正在尝试在 Rails 中实现基于角色的授权。
我们的要求:
发现:
punditgem,因为它的策略是静态的,我们不能使其动态。cancangem,并且可以动态使用它,但我不知道如何做到这一点?它如何与“数据库”一起工作?这是我在授权部分的第一个项目。我们以 Rails 作为后端,以 vue.js 作为前端。无论有什么角色,数据库上的所有数据首先都应该是空的。我们将使用种子创建超级管理员角色并授予所有权限。超级管理员会创建角色、编辑角色、销毁角色,最后还会添加权限、编辑权限、销毁权限。
如果还有其他有用的方法请告诉我。
谢谢。
我正在寻找在我的应用程序中实现授权(非身份验证)方案的方法。
系统中目前有两个角色:A 和 B,但可能还有更多。用户只有一个角色。
基本上,我现在设置的是两个数据库表。一种是针对模型的基于角色的权限,另一种是针对特定用户的权限。我认为这样,用户可以根据他们基于角色的权限拥有一组默认权限,但他们也可以授予/撤销特定的权限。
例如:
table: user_permissions
columns:
user_id: [int]
action: [string]
allowed: [boolean]
model_id: [int]
model_type: [string]
table: role_permissions
columns:
role: [int]
action: [string]
model_type: [string]
Run Code Online (Sandbox Code Playgroud)
在user_permissions表中,该allowed字段指定是否允许该操作,因此如果该值为 0,则可以撤消权限。
在另一个表中,我有每个动作的定义:
table: model_actions
columns:
action: [string]
bitvalue: [int]
model_type: [string]
Run Code Online (Sandbox Code Playgroud)
我这样做是为了当我检查模型的权限时,例如 ['create', 'delete'],我可以使用按位和操作来比较用户的权限和我正在检查的权限。例如,模型 X 可能具有以下 model_actions:
action: 'create'
bitvalue: 4
model_type: X
action: 'delete'
bitvalue: 2
model_type: X
action: 'view'
bitvalue: 1
model_type: X
Run Code Online (Sandbox Code Playgroud)
如果我的用户/角色权限指定模型 X 的创建、查看和删除操作分别为 1、0 和 1,则根据model_actions表将其表示为 110 。当我检查是否可以创建模型X时,我使用create为4的事实来构造位数组100。如果110和100的按位AND运算为100,则该权限有效。
无论如何,我想我已经找到了一个细粒度的权限设计模式。如果不是,请随时就该主题对我进行教育。
我的问题的实际重点涉及以下方面: …
我正在查看 GCP 控制面板中的 IAM 服务帐户选项卡。我正在编辑服务帐户。我单击“授予访问权限”,输入我正在创建的服务帐户的电子邮件,并尝试添加存储管理员。
但是,列表中没有这样的选项。
此外,通过 CLI 执行此操作的看似等效的尝试失败了:
gcloud projects add-iam-policy-binding my-project-id \
--member='serviceAccount:github-actions@my-project-id.iam.gserviceaccount.com' \
--role='projects/my-project-id/roles/storage.admin'
ERROR: Policy modification failed. For a binding with condition, run "gcloud alpha iam policies lint-condition" to identify issues in condition.
ERROR: (gcloud.projects.add-iam-policy-binding) INVALID_ARGUMENT: Role (projects/my-project-id/roles/storage.admin) does not exist in the resource's hierarchy.
Run Code Online (Sandbox Code Playgroud)
显然,我无法理解服务帐户应该如何被授予角色。
authorization role-base-authorization google-cloud-storage google-cloud-platform google-iam
.net ×1
angular ×1
asp.net ×1
auth-guard ×1
dotnetnuke ×1
google-iam ×1
permissions ×1
rbac ×1
roles ×1
security ×1
typescript ×1