router-authz.js revision 923784d59ac065eee98b208dfacda6fbc24c71d6
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2011-2012 ForgeRock AS. All rights reserved.
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*/
/*
* This script is called from the router "onRequest" trigger, to enforce a central
* set of authorization rules.
*
* This default implemention simply restricts requests via HTTP to users that are assigned
* an "openidm-admin" role, and optionally to those that authenticate with TLS mutual
* authentication (assigned an "openidm-cert" role).
*/
/**
* A configuration for allowed requests. Each entry in the config contains a pattern to match
* against the incoming request ID and, in the event of a match, the associated roles, methods,
* and actions that are allowed for requests on that particular pattern.
*
* pattern: A pattern to match against an incoming request's resource ID
* roles: A comma separated list of allowed roles
* methods: A comma separated list of allowed methods
* actions: A comma separated list of allowed actions
*
* A single '*' character indicates all possible values. With patterns ending in "/*", the "*"
* acts as a wild card to indicate the pattern accepts all resource IDs "below" the specified
* starting with "managed/". Note: it would not match "managed", which would need to have its
* own entry in the config.
*/
var accessConfig =
{
"configs" : [
// Anyone can read from these endpoints
{
"pattern" : "info/*",
"roles" : "*",
"methods" : "read",
"actions" : "*"
},
{
"pattern" : "config/ui/configuration",
"roles" : "openidm-reg,openidm-authorized",
"methods" : "read",
"actions" : "*"
},
// These options should only be available anonymously if selfReg is enabled
{
"roles" : "openidm-reg",
"methods" : "read",
"actions" : "*",
"customAuthz" : "checkIfUIIsEnabled('selfRegistration')"
},
{
"roles" : "openidm-reg",
"methods" : "create",
"actions" : "*",
"customAuthz" : "checkIfUIIsEnabled('selfRegistration') && managedUserRestrictedToAllowedRoles('openidm-authorized')"
},
// Anonymous user can call the siteIdentification endpoint if it is enabled:
{
"pattern" : "endpoint/siteIdentification",
"roles" : "openidm-reg",
"methods" : "*",
"actions" : "*",
"customAuthz" : "checkIfUIIsEnabled('siteIdentification')"
},
// Anonymous user can call the securityQA endpoint if it enabled:
{
"pattern" : "endpoint/securityQA",
"roles" : "openidm-reg",
"methods" : "*",
"actions" : "*",
"customAuthz" : "checkIfUIIsEnabled('securityQuestions')"
},
// This is needed by both self reg and security questions
{
"roles" : "openidm-reg",
"methods" : "read,action",
"actions" : "*",
"customAuthz" : "checkIfUIIsEnabled('selfRegistration') || checkIfUIIsEnabled('securityQuestions')"
},
// openidm-admin can request anything
{
"pattern" : "*",
"roles" : "openidm-admin",
"methods" : "*", // default to all methods allowed
"actions" : "*" // default to all actions allowed
},
// Additional checks for authenticated users
{
"pattern" : "policy/*",
"roles" : "openidm-authorized", // openidm-authorized is logged-in users
"methods" : "read,action",
"actions" : "*"
},
{
"roles" : "openidm-authorized",
"methods" : "read",
"actions" : "*"
},
{
"pattern" : "authentication",
"roles" : "openidm-authorized",
"methods" : "action",
"actions" : "reauthenticate"
},
{
"pattern" : "*",
"roles" : "openidm-authorized",
"methods" : "create,read,update,patch,action,query", // note the missing 'delete' - by default, users cannot delete things
"actions" : "*",
"customAuthz" : "ownDataOnly() && managedUserRestrictedToAllowedRoles('openidm-authorized')"
},
// enforcement of which notifications you can read and delete is done within the endpoint
{
"pattern" : "endpoint/usernotifications",
"roles" : "openidm-authorized",
"methods" : "read,delete",
"actions" : "*"
},
// Workflow-related endpoints for authorized users
{
"pattern" : "workflow/taskinstance/*",
"roles" : "openidm-authorized",
"methods" : "action",
"actions" : "complete",
"customAuthz" : "isMyTask()"
},
{
"pattern" : "workflow/taskinstance/*",
"roles" : "openidm-authorized",
"methods" : "read,update",
"actions" : "*",
"customAuthz" : "canUpdateTask()"
},
{
"pattern" : "workflow/processinstance/",
"roles" : "openidm-authorized",
"methods" : "action",
"actions" : "createProcessInstance",
"customAuthz": "isAllowedToStartProcess()"
},
{
"pattern" : "workflow/processdefinition/*",
"roles" : "openidm-authorized",
"methods" : "*",
"actions" : "read",
"customAuthz": "isOneOfMyWorkflows()"
},
// Clients authenticated via SSL mutual authentication
{
"pattern" : "*",
"roles" : "openidm-cert",
"methods" : "", // default to no methods allowed
"actions" : "" // default to no actions allowed
}
]
};
function isMyTask() {
}
function canUpdateTask() {
}
function isUserCandidateForTask(taskInstanceId) {
var userCandidateTasksQueryParams = {
"_queryId": "filtered-query",
};
var userCandidateTasks = openidm.query("workflow/taskinstance", userCandidateTasksQueryParams).result;
return true;
}
}
var roles = "";
if (i === 0) {
} else {
}
}
"_queryId": "filtered-query",
"taskCandidateGroup": roles
};
var userGroupCandidateTasks = openidm.query("workflow/taskinstance", userGroupCandidateTasksQueryParams).result;
return true;
}
}
return false;
}
function isAllowedToStartProcess() {
return isProcessOnUsersList(processDefinitionId);
}
function isOneOfMyWorkflows() {
return isProcessOnUsersList(processDefinitionId);
}
function isProcessOnUsersList(processDefinitionId) {
var processesForUserQueryParams = {
"_queryId": "query-processes-for-user",
};
var isProcessOneOfUserProcesses = false;
var processForUser = processesForUser[i];
isProcessOneOfUserProcesses = true;
}
}
return isProcessOneOfUserProcesses;
}
function isQueryOneOf(allowedQueries) {
if (
)
{
return true
}
return false;
}
function checkIfUIIsEnabled(param) {
var returnVal = false;
}
function ownDataOnly() {
var userId = "";
{
}
{
// something funny going on if we have two different values for userId
return false;
}
}
{
// something funny going on if we have two different values for userId
return false;
}
}
}
function managedUserRestrictedToAllowedRoles(allowedRolesList) {
return true;
}
}
else { // this would be strange, but worth checking
return true; // true because they don't appear to be setting anything
}
if (request.method === "patch" || (request.method === "action" && request.params["_action"] === "patch")) {
for (i in params) {
}
}
if (typeof params.roles !== "string" && typeof params["/roles"] !== "string") { // this would also be strange, but worth checking
return false; // false because I don't know (and so don't trust) what they are trying to set.
}
}
if (params["/roles"]) {
}
}
// we could accept a csv list or an array of roles for the rolesList arg.
if (typeof allowedRolesList === "string") {
}
for (i in requestedRoles) {
return false;
}
}
}
return true;
}
//////// Do not alter functions below here as part of your authz configuration
// Check resource ID
// Check roles
// Check method
// Check action
return true;
}
} else {
return true;
}
}
}
}
}
}
return false;
}
if (pattern == "*") {
// Accept all patterns
return true;
// pattern matches exactly
return true;
// Ends with "/*" or "/"
// See if parent pattern matches
if (id.length >= parentResource.length && id.substring(0, parentResource.length) == parentResource) {
return true
}
}
return false;
}
if (configItems == "*") {
return true;
}
return true;
}
}
return false
}
if (configItems == "*") {
return true;
}
}
function contains(a, o) {
if (typeof(a) != 'undefined' && a != null) {
for (var i = 0; i <= a.length; i++) {
if (a[i] === o) {
return true;
}
}
}
return false;
}
function allow() {
return true;
}
var action = "";
}
// Check REST requests against the access configuration
return true;
}
}
}
if (!allow()) {
// java.lang.System.out.println(request);
throw {
"openidmCode" : 403,
"message" : "Access denied"
}
}