Применение безопасности данных к элементам иерархии
Устанавливает безопасность на уровне элементов для указанной иерархии атрибутов в конкретной модели данных для заданной роли.
Метод
- Раздел API: /API3/dataSources
- Версия API: 3.0
- Начиная с релиза: 2023.10
- Использование: REST API и клиентские библиотеки SDK. REST API — только через POST-запросы.
- Кто использует:
- Enterprise Admin
Сигнатура метода
Входные параметры
Имя
membersSecurityObject
Тип объекта
Описание
Подробные данные параметров безопасности для элементов иерархии.
Выходной ответ
Код успешного результата
200
Тип ответа
Описание типа ответа
Универсальный объект ответа API с флагом успеха или неудачи и связанными сообщениями.
Примечания
Параметры безопасности можно задать либо по имени конкретного элемента (в виде списка), либо с помощью логического PQL-скрипта, формирующего список элементов. Функции следует передать либо список элементов, либо скрипт. НЕ И ТО И ДРУГОЕ ВМЕСТЕ.
Примеры
Настройка безопасности модели данных (JavaScript):
В этом примере показано, как программно настроить безопасность на уровне иерархий, мер и элементов в модели данных.
В примере используется аутентификация API средствами JavaScript. См. API аутентификации для альтернативных вариантов.
// URL of the Pyramid installation and the path to the API 3.0 REST methods
var pyramidURL = "http://mysite.com/api3/";
// step 1: authenticate admin account and get token
// NOTE: callApi method is a generic REST method shown below.
let token = callApi(“authentication/authenticateUser”,{
“userName”:“adminUser”,
“password”:“abc123!”},
“",false);
log(“got token “+token);
//get database’s system ID
let databaseId = database[0].itemId
//step 2: find model by name for the chosen database
let model= callApi(“dataSources/findModelConnection”,{
“serverSearchCriteria”:{
“searchValue”:“Pyramid IMDB”
},
“databaseSearchCriteria”:{
“searchValue”:“PyramidDemo”
},
“modelSearchCriteria”:{
“searchValue”:“PyramidDemo”
}
},token);
//get model’s system ID
let modelId = model[0].modelId
//step 3: find role by name
let role= callApi(“access/findRoles”,{
“searchValue”:“role 1”
},token);
//get role’s system ID
let roleId = role[0].roleId
//step 4A: adding member security to the model by specific selection
// set this role to see 2009 and 2010 (and by definition hide any other year)
let addMembersSecurityToModel= callApi(“dataSources/addMembersSecurity”,{
“modelId”:modelId,
“roleId”:roleId,
“enableMode”: true,
“hierarchyUniqueName”: “[Date].[year]”, //this is the unique name of the parent hierarchy
“members”:[“2009”, “2010”] //list of members (using their captions)
},token);
//step 4B: adding member security to the model by script
// set this role to see any country where the non empty cross join
// to the ‘user’ column in the ‘security’ table matches the logged in user’s username (using the username function)
let addMembersSecurityToModel= callApi(“dataSources/addMembersSecurity”,{
“modelId”:modelId,
“roleId”:roleId,
“enableMode”: true,
“hierarchyUniqueName”: “[Geography].[Country]”, //this is the unique name of the parent hierarchy
“script”:“NonEmpty([Geography].[Country].AllMembers, {StrToMember([Security].[User],UserName())})” //logical PQL script for defining a list of members
},token);
//step 4C: adding member security to the model by script
// set this role to see any records in the model where it is inherently filtered (inner joined)
// against the value of the currently logged in user’s name in the ‘userIds’ column in the ‘Org’ table (from the username function)
let addMembersSecurityToModel= callApi(“dataSources/addMembersSecurity”,{
“modelId”:modelId,
“roleId”:roleId,
“enableMode”: true,
“hierarchyUniqueName”: “[Security].[User]”, //this is the unique name of the parent hierarchy
“script”:“StrToMember([Org].[UserIds],UserName())” //logical PQL script for defining a list of members
},token);
//step 5: adding hierarchy security to the model
// set this role to NOT see the state hierarchy in the customer dimension/table
let addHierarchySecurityToModel= callApi(“dataSources/addHierarchySecurity”,{
“modelId”:modelId,
“roleId”:roleId,
“enableMode”: false,
“uniqueNames”: ["[Customer].[State]”] //this is the unique name of the hierarchy, in a list
},token);
//step 6: adding measure security to the model
// set this role to see the the cost measure in the model (and by definition to hide all other measures)
let addMeasureSecurityToModel= callApi(“dataSources/addMeasureSecurity”,{
“modelId”:modelId,
“roleId”:roleId,
“enableMode”: true,
“uniqueNames”: ["[measures].[Cost]”] //this is the unique name of the measure, in a list
},token);
// ##### optional generic login method for debugging ##############
function log(msg){
document.write(msg);
console.log(msg);
}
// ##### generic REST API calling method ##############
function callApi(path,data,token=”",parseResult=true){
var xhttp = new XMLHttpRequest();
xhttp.open(“POST”, pyramidURL+path, false);
xhttp.setRequestHeader(“paToken”,token)
xhttp.send(JSON.stringify(data));
if(parseResult){
return JSON.parse(xhttp.responseText);
}else{
return xhttp.responseText;
}
}
</code></pre></details>
Примеры кода
Используйте методы Authentication API, чтобы сгенерировать «ключ» или «токен» доступа для использования в коде, как показано ниже.
TypeScript
Curl
Java
C#
Python
PHP
