-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding IdentityBased and Resource Based Policies (#8)
* Adding IdentityBased and ResourceBased Policies * Support for notAction, notResource, principal and notPrincipal attributes.
- Loading branch information
1 parent
4a5b3e0
commit 58210b7
Showing
20 changed files
with
1,648 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from "./src/Role"; | ||
export * from "./src/Statement"; | ||
export * from './src/Statement'; | ||
export * from './src/IdentityBasedStatement'; | ||
export * from './src/ResourceBasedStatement'; | ||
export * from './src/Policies'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
Context, | ||
IdentityBasedType, | ||
MatchIdentityBasedInterface | ||
} from './types' | ||
import { | ||
instanceOfResourceBlock, | ||
instanceOfActionBlock | ||
} from './utils' | ||
import {Matcher} from './Matcher' | ||
import {Statement, applyContext} from './Statement' | ||
|
||
class IdentityBased extends Statement{ | ||
private resource?: string[]; | ||
private action?: string[]; | ||
private notResource?: string[]; | ||
private notAction?: string[]; | ||
|
||
constructor(identity: IdentityBasedType) { | ||
super(identity); | ||
if(instanceOfResourceBlock(identity)){ | ||
this.resource = typeof identity.resource === 'string' ? [identity.resource] : identity.resource; | ||
}else{ | ||
this.notResource = typeof identity.notResource === 'string' ? [identity.notResource] : identity.notResource; | ||
} | ||
if(instanceOfActionBlock(identity)){ | ||
this.action = typeof identity.action === 'string' ? [identity.action] : identity.action; | ||
}else{ | ||
this.notAction = typeof identity.notAction === 'string' ? [identity.notAction] : identity.notAction; | ||
} | ||
} | ||
|
||
matches({ | ||
action, | ||
resource, | ||
context, | ||
conditionResolver | ||
}:MatchIdentityBasedInterface) | ||
: boolean { | ||
return ( | ||
this.matchActions(action,context) && | ||
this.matchNotActions(action,context) && | ||
this.matchResources(resource,context) && | ||
this.matchNotResources(resource,context) && | ||
this.matchConditions({context,conditionResolver}) | ||
); | ||
} | ||
|
||
private matchActions( action: string, context?: Context): boolean { | ||
return this.action?this.action.some(a => | ||
new Matcher(applyContext(a, context)).match(action)):true } | ||
|
||
private matchNotActions( action: string, context?: Context): boolean { | ||
return this.notAction?!this.notAction.some(a => | ||
new Matcher(applyContext(a, context)).match(action)):true } | ||
|
||
|
||
private matchResources( resource: string, context?: Context): boolean { | ||
return this.resource?this.resource.some(a => | ||
new Matcher(applyContext(a, context)).match(resource)):true } | ||
|
||
private matchNotResources( resource: string, context?: Context): boolean { | ||
return this.notResource?!this.notResource.some(a => | ||
new Matcher(applyContext(a, context)).match(resource)):true } | ||
} | ||
|
||
export { IdentityBased }; | ||
|
Oops, something went wrong.