Reputation: 21
Is there any way to fully manage the Security in SSAS tabular 2017 (1400)?
I would like to manage roles from C# using the Microsoft.AnalysisServices.Tabular dll.
I am not able to access ColumnPermissions (or I don't know how) and to set TablePermissions filters.
This is my code:
private static void ReplaceRolesAndMembersWithInitialValues(Database db, Model model, List<CubeRoleModel> initRolesForPostgres)
{
var roles = model.Roles;
if (roles.Count > 0)
{
var rolesName = roles.Select(x => x.Name).Distinct().ToList();
foreach (var n in rolesName)
{
roles.Remove(n);
}
model.SaveChanges();
}
if (initRolesForPostgres.Count > 0)
{
var tablesNames = new HashSet<string>(model.Tables.Select(a => a.Name).Distinct().ToList());
var tables = model.Tables;
Dictionary<string, Table> dictTables = new Dictionary<string, Table>();
foreach (var t in tables)
{
dictTables.Add(t.Name, t);
}
foreach (var n in initRolesForPostgres)
{
ModelRole newRole = new ModelRole
{
Name = n.RoleName,
Description = n.RoleDescription,
ModelPermission = n.ModelPermission
};
if (n.Members.Count > 0)
{
foreach (var m in n.Members)
{
var nMem = new WindowsModelRoleMember
{
MemberName = m.MemberName
};
newRole.Members.Add(nMem);
}
}
if (n.TablePermissions.Count > 0)
{
var tb = newRole.TablePermissions;
foreach (var tabPerm in n.TablePermissions)
{
if (tables.Contains(tabPerm.TableName) && string.IsNullOrWhiteSpace(tabPerm.TableFilters) == false)
{
TablePermission newTablePer = new TablePermission
{
Name = tabPerm.TableName,
FilterExpression = tabPerm.TableFilters
};
if (newTablePer.Validate().ContainsErrors) { continue; }
tb.Add(newTablePer);
}
}
}
if (newRole.Validate().ContainsErrors) { continue; }
model.Roles.Add(newRole);
}
model.SaveChanges();
}
}
Any idea?
Upvotes: 1
Views: 351
Reputation: 21
After 1 day I manage to solve this. First of all you should get the last DLL for Microsoft.AnalysisServices.Tabular and Microsoft.AnalysisServices.Core. You will find this dlls in the Microsoft SQL Server 2017 installation folder.
After this you will find all info that you need here.
Upvotes: 1