mirror of https://github.com/abpframework/abp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
79 lines
2.0 KiB
5 years ago
|
# Permission Management
|
||
5 years ago
|
|
||
5 years ago
|
A permission is a simple policy that is granted or prohibited for a particular user, role or client. You can read more about [authorization in ABP](../../Authorization.md) document.
|
||
5 years ago
|
|
||
5 years ago
|
You can get permission of authenticated user using `getGrantedPolicy` selector of `ConfigState`.
|
||
5 years ago
|
|
||
5 years ago
|
You can get permission as boolean value from store:
|
||
5 years ago
|
|
||
5 years ago
|
```js
|
||
5 years ago
|
import { Store } from '@ngxs/store';
|
||
|
import { ConfigState } from '../states';
|
||
|
|
||
|
export class YourComponent {
|
||
|
constructor(private store: Store) {}
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
const canCreate = this.store.selectSnapshot(ConfigState.getGrantedPolicy('AbpIdentity.Roles.Create'));
|
||
|
}
|
||
|
|
||
|
// ...
|
||
|
}
|
||
5 years ago
|
```
|
||
|
|
||
5 years ago
|
Or you can get it via `ConfigStateService`:
|
||
5 years ago
|
|
||
5 years ago
|
```js
|
||
5 years ago
|
import { ConfigStateService } from '../services/config-state.service';
|
||
|
|
||
|
export class YourComponent {
|
||
|
constructor(private configStateService: ConfigStateService) {}
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
const canCreate = this.configStateService.getGrantedPolicy('AbpIdentity.Roles.Create');
|
||
|
}
|
||
|
|
||
|
// ...
|
||
|
}
|
||
5 years ago
|
```
|
||
|
|
||
5 years ago
|
## Permission Directive
|
||
5 years ago
|
|
||
|
You can use the `PermissionDirective` to manage visibility of a DOM Element accordingly to user's permission.
|
||
|
|
||
|
```html
|
||
5 years ago
|
<div *abpPermission="AbpIdentity.Roles">
|
||
|
This content is only visible if the user has 'AbpIdentity.Roles' permission.
|
||
5 years ago
|
</div>
|
||
|
```
|
||
|
|
||
5 years ago
|
As shown above you can remove elements from DOM with `abpPermission` structural directive.
|
||
5 years ago
|
|
||
|
The directive can also be used as an attribute directive but we recommend to you to use it as a structural directive.
|
||
|
|
||
5 years ago
|
## Permission Guard
|
||
5 years ago
|
|
||
5 years ago
|
You can use `PermissionGuard` if you want to control authenticated user's permission to access to the route during navigation.
|
||
5 years ago
|
|
||
5 years ago
|
Add `requiredPolicy` to the `routes` property in your routing module.
|
||
5 years ago
|
|
||
5 years ago
|
```js
|
||
5 years ago
|
const routes: Routes = [
|
||
|
{
|
||
|
path: 'path',
|
||
|
component: YourComponent,
|
||
|
canActivate: [PermissionGuard],
|
||
|
data: {
|
||
5 years ago
|
routes: {
|
||
|
requiredPolicy: 'AbpIdentity.Roles.Create',
|
||
|
},
|
||
5 years ago
|
},
|
||
|
},
|
||
|
];
|
||
|
```
|
||
|
|
||
5 years ago
|
Granted Policies are stored in the `auth` property of `ConfigState`.
|
||
5 years ago
|
|
||
5 years ago
|
## What's Next?
|
||
5 years ago
|
|
||
5 years ago
|
* [Component Replacement](./Component-Replacement.md)
|