router-authz.js revision 41b8a41890ba8f4574304c7ef42effe818413348
/*! @license
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright © 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).
*/
// If true, then allows HTTP requests from "openidm-cert" role.
const allowCert = false;
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;
}
/**
* Public methods are accessible by anonymous user. They are used
* during registration and forgotten password process.
*/
function isPublicMethodInvocation() {
var publicQueries = ['check-userName-availability','for-security-answer','for-credentials', 'get-security-question', 'set-newPassword-for-userName-and-security-answer'];
}
return true;
} else {
return false;
}
return true;
} else {
}
} else {
return false;
}
}
function userIsAuthorized(roles) {
}
function requestIsAQueryOfName(queryName) {
}
function authorizedUsernameEquals(userName) {
}
function requestIsAnActionOfName(actionName) {
return request.value && request.params && request.params['_action'] && request.params['_action'] == actionName;
}
var key = "replace";
return true;
}
}
}
function allow() {
return true;
}
//administrator can do everything
return true;
//certificated user can do everything
return true;
//authenticated user can only manage his data and cannot change a role attribute.
if (requestIsAnActionOfName('patch')) {
if (requestValueContainsReplaceValueWithKeyOfName('/role')) {
return false;
}
}
} else {
throw "Access denied (Manipulation with data of user not equal to logged-in is forbidden)";
}
return true;
} else {
return isPublicMethodInvocation();
}
}
if (!allow()) {
throw "Access denied";
}