
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
ngx-guardian
Advanced tools
Logo designed by Yomissmar
Empowering your Angular project using a powerful Permission Manager.
Explore Wiki »
Contributing
·
License
Ngx Guardian is a minimal, powerfull and easy configurable permission manager that grant the power to manage different roles in your Angular project.
ng add ngx-guardian
npm install ngx-guardian --save
Follow Setup & Permission Specification sections
In your App Module:
@NgModule({
declarations: [. . .],
providers: [. . .],
imports: [
NgxGuardianModule.forRoot({
// Set up your managers here (see Permission specification)
managers: [
fooPermissionManager,
otherFooPermissionManager,
...
],
// Manager role to set its manager as default
defaultRole: Role.ROLE_NAME,
// Set a manager by localStorage value (see below)
setFromStorage: true,
// Navigate to this route if no role set
unauthorizedRoute: '/no-auth',
// Navigate to this route if user is no granted for route
noGrantedRoute: '/no-granted'
})
],
exports: [. . .]
})
export class AppModule { }
You can delegate default manager setup to NgxGuardian setting a role in localStorage:
localStorage.setItem('ngx-guardian-role', 'ROLE_NAME');
Name | Type | Default | Required | Description |
---|---|---|---|---|
managers | NgxGuardianManager[] | - | :heavy_check_mark: | Permission Managers for application (with roles & actions over resources) |
defaultRole | string | - | - | Default role to set its manager (if no provided, manager is disabled) |
setFromStorage | boolean | false | - | Set role by localStorage value |
unauthorizedRoute | string | "no-auth" | - | Route to navigate if no manager set |
noGrantedRoute | string | "no-granted" | - | Route to navigate if user has no permissions |
As there are different strategies to configure the default manager, the following priority has been established:
├── src
└── ngx-guardian
├── ngx-roles.ts
├── ngx-permissions.ts
├── ngx-resources.ts
├── ngx-config.ts
├── ngx-foo-manager.ts
├── ...
└── ngx-other-foo-manager.ts
// ngx-roles.ts
export enum NgxGuardianRole {
ADMIN = 'ADMIN',
DEFAULT = 'DEFAULT',
ONLY_VIEW = 'ONLY_VIEW'
}
// ngx-actions.ts
export enum NgxGuardianAction {
CREATE = 'CREATE',
READ = 'READ',
UPDATE = 'UPDATE',
DELETE = 'DELETE',
APPROVE = 'APPROVE',
REJECT = 'REJECT'
}
// ngx-resources.ts
import { NgxGuardianResource } from 'ngx-guardian';
export const FOO: NgxGuardianResource = {
name: 'FOO',
routes: []
};
export const PIZZA: NgxGuardianResource = {
name: 'PIZZA',
routes: []
};
//ngx-foo-manager.ts
import { NgxGuardianManager } from 'ngx-guardian';
import { NgxGuardianRole } from './ngx-role';
import { FOO, PIZZA } from './ngx-resources';
import { NgxGuardianAction } from './ngx-permissions';
export const defaultManager: NgxGuardianManager = {
role: NgxGuardianRole.ADMIN,
permissions: [
{
FOO,
actions: [
NgxGuardianAction.CREATE,
NgxGuardianAction.READ
]
},
{
resource: PIZZA,
actions: [
NgxGuardianAction.CREATE,
NgxGuardianAction.READ
]
}
]
}
The purpose of ngx-guardian directives is to simplify the logic of the templates designed to show, hide or modify the components or HTML code blocks according to permissions or user roles.
This directive shows or hides a html block or component depending on whether a user has permission over a specific resource.
<!-- This component will be shown ONLY IF user has CREATE permission over PIZZA resource -->
<component-to-show-or-hide *ngxShowIfGranted="'CREATE - PIZZA'">
</component-to-show-or-hide>
<!-- This html block will be shown ONLY IF user has READ permission over PIZZA resource -->
<div *ngxShowIfGranted="'READ - PIZZA'">
<p> Paragraph intended for users with READ permissions over pizza </p>
</div>
This directive enable or disable a html block or component depending on whether a user has permission over a specific resource.
<!-- This component will be set disabled IF user HAS NOT CREATE permission over PIZZA resource -->
<component-to-enable-or-disable ngxDisableIfNoGranted="'READ - PIZZA'">
</component-to-enable-or-disable>
<!-- This html block will be set disabled IF user HAS NOT READ permission over PIZZA resource -->
<button ngxDisableIfNoGranted="'UPDATE - PIZZA'">
Update pizza toppings
</button>
The purpose of the Permission Service is to offer an interface for communication with the permission manager.
Method | Signature | Output | Description |
---|---|---|---|
isGranted | (action: string, resource: string) | boolean | If user can perform an action over resource |
disableManager | - | - | Disable default permission manager |
setManagerByRole | (role: string) | boolean | Set current manager for role provided |
canNavigateTo | (url: string) | boolean | Returns if the user is granted to navigate to the path provided |
FAQs
Logo designed by <a href="https://www.behance.net/y
The npm package ngx-guardian receives a total of 9 weekly downloads. As such, ngx-guardian popularity was classified as not popular.
We found that ngx-guardian demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.