This is an example of how you could create a JavaScript DSL for creating ABAC authorization policy, comparable to XACML, but much easier to read.
This policy will allow a user with a particular group to access any resource during business hours.
allow('read')
.of(anyResource())
.if(and(
User.department().is(equalTo('development')),
timeOfDay().isDuring('9:00 PST', '17:00 PST'))
);
new Policy((request)=>{
if (request.action == 'read') {
let start = Environment.timeStringAsUTCMillis("9:00 PST");
let end = Environment.timeStringAsUTCMillis("17:00 PST");
let range = new Range(start, end - start);
if (request.principal.department == 'development' && range.isIncluded(request.environment.now)) {
return true;
}
}
return false;
})
This policy will allow a user with a particular group to access the "/foo" resource.
allow('read')
.of(resourceByPath('/foo'))
.if(User.department().is(equalTo('development')));