if(dimensionRules.isEmpty()) {
return;
}
ScriptableMondrianDrillThrough smdt = (ScriptableMondrianDrillThrough) olapModel.getExtension("drillThrough");
Connection monConnection = smdt.getConnection();
// get the connection role, cube and schema reader
RoleImpl connRole = (RoleImpl) monConnection.getRole();
//connRole.makeMutableClone();
logger.debug("DataSecurityManager::setMondrianRole:connection role retrived: " + connRole);
Query monQuery = monConnection.parseQuery(query);
Cube cube = monQuery.getCube();
logger.debug("DataSecurityManager::setMondrianRole: cube retrived: " + cube);
SchemaReader schemaReader = cube.getSchemaReader(null);
logger.debug("DataSecurityManager::setMondrianRole: schema reader retrived: " + schemaReader);
// FOR EACH DIMENSION NAME SET THE RIGHT GRANT TO THE DIMENSION OR HIERARCHY
logger.debug("DataSecurityManager::setMondrianRole: start setting grant for each dimension or hierachy");
Iterator iterDimRules = dimensionRules.iterator();
while(iterDimRules.hasNext()){
DimensionRulesBean drb = (DimensionRulesBean)iterDimRules.next();
String dimName = drb.getName();
String dimAccess = drb.getAccess();
String bottomLevel = drb.getBottomLevel();
String topLevel = drb.getTopLevel();
String rollupPolicy = drb.getRollupPolicy();
logger.debug("DataSecurityManager::setMondrianRole: processing dimension named: " + dimName);
//List dimMembs = drb.getMembers();
logger.debug("DataSecurityManager::setMondrianRole: try to search the dimension into the cube");
Dimension[] dimensions = cube.getDimensions();
for (int i = 0; i < dimensions.length; i++) {
Dimension dim = dimensions[i];
String cubeDimKey = dim.getName();
if(cubeDimKey.equalsIgnoreCase(dimName)) {
logger.debug("DataSecurityManager::setMondrianRole: dimension found into the cube");
mondrian.olap.Hierarchy[] hierarchies = dim.getHierarchies();
if(hierarchies == null || hierarchies.length == 0) {
if(dimAccess.equalsIgnoreCase("none")) {
connRole.grant(dim, Access.NONE);
logger.debug("DataSecurityManager::setMondrianRole: setted access.none to the dimension");
} else {
connRole.grant(dim, Access.ALL);
logger.debug("DataSecurityManager::setMondrianRole: setted access.all to the dimension");
}
break;
} else {
for (int j = 0; j < hierarchies.length; j++) {
mondrian.olap.Hierarchy aHierarchy = hierarchies[j];
if (aHierarchy.getName().equalsIgnoreCase(dimName)) {
Level[] levels = aHierarchy.getLevels();
Level topLev = null;
Level bottomLev = null;
for(int k=0; k<levels.length; k++) {
Level level = levels[k];
if(level.getUniqueName().equals(topLevel)) {
topLev = level;
}
if(level.getUniqueName().equals(bottomLevel)) {
bottomLev = level;
}
}
Role.RollupPolicy rp = null;
if (rollupPolicy == null) {
rp = Role.RollupPolicy.FULL;
} else {
try {
rp = Role.RollupPolicy.valueOf(rollupPolicy);
} catch (Exception e) {
logger.error("Error evaluating rollup policy: " + rollupPolicy, e);
logger.warn("Using default policy Role.RollupPolicy.FULL");
rp = Role.RollupPolicy.FULL;
}
}
logger.debug("DataSecurityManager::setMondrianRole: hierarchy found into the cube");
connRole.grant(aHierarchy, Access.CUSTOM, topLev, bottomLev, rp);
logger.debug("DataSecurityManager::setMondrianRole: setted access.custom to the hierarchy");
}
}
}
}
}
logger.debug("DataSecurityManager::setMondrianRole: end search dimension into the cube");
}
logger.debug("DataSecurityManager::setMondrianRole: end setting grant for each dimension or hierachy");
// FOR EACH MEMBER SET THE GRANT
logger.debug("DataSecurityManager::setMondrianRole: start setting grant for members of dimensions");
iterDimRules = dimensionRules.iterator();
while(iterDimRules.hasNext()){
DimensionRulesBean drb = (DimensionRulesBean)iterDimRules.next();
String dimName = drb.getName();
logger.debug("DataSecurityManager::setMondrianRole: processing dimension named: " + dimName);
List dimMembs = drb.getMembers();
logger.debug("DataSecurityManager::setMondrianRole: start processing dimension named: " + dimName);
Iterator iterDimMembs = dimMembs.iterator();
while(iterDimMembs.hasNext()) {
MemberRulesBean mrb = (MemberRulesBean)iterDimMembs.next();
String dimMemb = mrb.getName();
String membAccess = mrb.getAccess();
logger.debug("DataSecurityManager::setMondrianRole: processing member : " + dimMemb);
List<Id.Segment> membParts = Util.parseIdentifier(dimMemb);
mondrian.olap.Member member = schemaReader.getMemberByUniqueName(membParts,true);
logger.debug("DataSecurityManager::setMondrianRole: mondrian member object retrived: " + member);
if(membAccess.equalsIgnoreCase("none")) {
connRole.grant(member, Access.NONE);
logger.debug("DataSecurityManager::setMondrianRole: setted access.none to the member");
} else {
connRole.grant(member, Access.ALL);
logger.debug("DataSecurityManager::setMondrianRole: setted access.all to the member");
}
}
}
logger.debug("DataSecurityManager::setMondrianRole: end setting grant for members of dimensions");
// SET THE ROLE INTO CONNECTION
//connRole.makeImmutable();
monConnection.setRole(connRole);
logger.debug("DataSecurityManager::setMondrianRole: setted role with grants into connection");
logger.debug("DataSecurityManager::setMondrianRole: end setting data access");