effectiveRoles.js revision 4c612d257b4ff240d2dc04785126f91a54a0c56c
0N/A/**
2362N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
0N/A * Copyright (c) 2014 ForgeRock AS. All rights reserved.
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the License). You may not use this file except in
0N/A * compliance with the License.
0N/A *
0N/A * You can obtain a copy of the License at
0N/A * http://forgerock.org/license/CDDLv1.0.html
0N/A * See the License for the specific language governing
0N/A * permission and limitations under the License.
2362N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * Header Notice in each file and include the License file
0N/A * at http://forgerock.org/license/CDDLv1.0.html
0N/A * If applicable, add the following below the CDDL Header,
0N/A * with the fields enclosed by brackets [] replaced by
0N/A * your own identifying information:
0N/A * "Portions Copyrighted [year] [name of copyright owner]"
0N/A */
0N/A
0N/A/**
0N/A * Calculates the effective roles
0N/A */
0N/A
0N/A/*global object */
0N/A
0N/Avar directRoles = null,
0N/A response;
0N/A
0N/Alogger.debug("Invoked effectiveRoles script on property {}", propertyName);
0N/A
0N/A// Allow for configuration in virtual attribute config, but default
0N/Aif (rolesPropName === undefined) {
0N/A var rolesPropName = "roles";
0N/A}
0N/A
0N/Alogger.trace("Configured rolesPropName: {}", rolesPropName);
0N/A
0N/Aif (object[rolesPropName] === undefined) {
0N/A logger.trace("User's " + rolesPropName + " is not present so querying the roles", rolesPropName);
0N/A response = openidm.query("managed/user/" + object._id + "/" + rolesPropName, {"_queryFilter": "true"});
0N/A directRoles = response.result;
0N/A} else {
0N/A directRoles = object[rolesPropName];
0N/A}
0N/A
0N/Avar effectiveRoles = directRoles == null ? [] : directRoles;
0N/A
0N/A// This is the location to expand to dynamic roles,
0N/A// project role script return values can then be added via
0N/A// effectiveRoles = effectiveRoles.concat(dynamicRolesArray);
0N/A
0N/AeffectiveRoles;
0N/A