What is the best way to create AngularJS ACL? [closed]

做~自己de王妃 提交于 2019-12-10 10:27:53

问题


I want to share with you (community) my problem.

I use MEAN stack, so I use Node.js with Express and AngularJS and I have singe app application.

I use passport as an authentication strategy in Node \ Express \ Jade code. I want to create admin section on my page to manage users and others stuff.

I want also protect this AngularJS sites loaded asynchronously by adding some access control to my $routeProvider like:

$routeProvider.when('/admin/users', {
    templateUrl: '/views/admin/users.html',
    auth: {
        required: true,
        roles: ['admin']
    }
})

This is only pseudocode which I want to achive in my real solution. If user is not logged in, should be redirect to /signin page, and if user is logged in and does not have proper role to view this page, should be redirect to appropiate view with custom information.


回答1:


I prefer to handle access control on the server side, and just not serve anything up to the user if s/he shouldn't be able to access it. Then I field and interpret the response from the server to do things like rerouting to a sign-in form.

This allows for really flexible security mechanisms. For example, I can configure my backend security with a firewall for something like you've described (where a route "/admin" and all of its descendants should be protected). I can use ACLs to secure individual objects, or a SecurityManager that allows for more complex analyses of the user making the request.

Maybe this isn't a direct answer to your question, but instead encouragement to approach the problem differently. Still I think it's a better approach than anything that I've seen in terms of pure JS access control.




回答2:


Have a look at UI-Router: https://github.com/angular-ui/ui-router

It is pretty cool and you can intercept state changes based on whatever security scheme you want.

We are using it with a permission/role/group based security scheme and it works awesome.



来源:https://stackoverflow.com/questions/20926126/what-is-the-best-way-to-create-angularjs-acl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!