User context example for access policy
You can specify an access policy that makes access decisions based on context that is obtained from the user information.
User context contains, users, groups, and attributes information. The following example access policy makes an access decision based on user context.
var userJSON = (function() {
var user = context.getUser();
var userReturn = {};
var groupsJSON = (function() {
var groupsReturn = [];
var groups = user.getGroups();
for (var it = groups.iterator(); it.hasNext();) {
var group = it.next();
var groupName = group.getName();
groupsReturn.push("" + groupName);
}
return groupsReturn;
})();
var attributesJSON = (function() {
var attributesReturn = {};
var attributes = user.getAttributes();
for (var it = attributes.iterator(); it.hasNext();) {
var attribute = it.next();
var attributeName = attribute.getName();
var attributeValue = attribute.getValue();
attributesReturn["" + attributeName] = "" + attributeValue;
}
return attributesReturn;
})();
userReturn["username"] = "" + user.getUsername();
userReturn["groups"] = groupsJSON;
userReturn["attributes"] = attributesJSON;
return userReturn;
})();