Search in sources :

Example 11 with HierarchyAccess

use of mondrian.olap.Role.HierarchyAccess in project mondrian by pentaho.

the class AccessControlTest method testRestrictLevelsAnalyzer3283.

public void testRestrictLevelsAnalyzer3283() {
    String dimensionsDef = "    <Dimension visible=\"true\" foreignKey=\"customer_id\" highCardinality=\"false\" name=\"Customers\">\n" + "      <Hierarchy visible=\"true\" hasAll=\"true\" allMemberName=\"All Customers\" primaryKey=\"customer_id\">\n" + "        <Table name=\"customer\">\n" + "        </Table>\n" + "        <Level name=\"Country\" visible=\"true\" column=\"country\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "        </Level>\n" + "        <Level name=\"State Province\" visible=\"true\" column=\"state_province\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "        </Level>\n" + "        <Level name=\"City\" visible=\"true\" column=\"city\" type=\"String\" uniqueMembers=\"false\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "        </Level>\n" + "        <Level name=\"Name1\" visible=\"true\" column=\"fname\" type=\"String\" uniqueMembers=\"false\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "          <Property name=\"Gender\" column=\"gender\" type=\"String\">\n" + "          </Property>\n" + "          <Property name=\"Marital Status\" column=\"marital_status\" type=\"String\">\n" + "          </Property>\n" + "          <Property name=\"Education\" column=\"education\" type=\"String\">\n" + "          </Property>\n" + "          <Property name=\"Yearly Income\" column=\"yearly_income\" type=\"String\">\n" + "          </Property>\n" + "        </Level>\n" + "        <Level name=\"First Name\" visible=\"true\" column=\"fname\" type=\"String\" uniqueMembers=\"false\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "        </Level>\n" + "      </Hierarchy>\n" + "      <Hierarchy name=\"Gender\" visible=\"true\" hasAll=\"true\" primaryKey=\"customer_id\">\n" + "        <Table name=\"customer\">\n" + "        </Table>\n" + "        <Level name=\"Gender\" visible=\"true\" column=\"gender\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "          <Annotations>\n" + "            <Annotation name=\"AnalyzerBusinessGroup\">\n" + "              <![CDATA[Customers]]>\n" + "            </Annotation>\n" + "          </Annotations>\n" + "        </Level>\n" + "      </Hierarchy>\n" + "      <Hierarchy name=\"Marital Status\" visible=\"true\" hasAll=\"true\" primaryKey=\"customer_id\">\n" + "        <Table name=\"customer\">\n" + "        </Table>\n" + "        <Level name=\"Marital Status\" visible=\"true\" column=\"marital_status\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "          <Annotations>\n" + "            <Annotation name=\"AnalyzerBusinessGroup\">\n" + "              <![CDATA[Customers]]>\n" + "            </Annotation>\n" + "          </Annotations>\n" + "        </Level>\n" + "      </Hierarchy>\n" + "    </Dimension>\n" + "  <Dimension visible=\"true\" highCardinality=\"false\" name=\"Store\" foreignKey=\"store_id\">\n" + "    <Hierarchy visible=\"true\" hasAll=\"true\" primaryKey=\"store_id\">\n" + "      <Table name=\"store\">\n" + "      </Table>\n" + "      <Level name=\"Store ID\" visible=\"true\" column=\"store_id\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "      </Level>\n" + "      <Level name=\"Store Country\" visible=\"true\" column=\"store_country\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "      </Level>\n" + "      <Level name=\"Store State\" visible=\"true\" column=\"store_state\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "      </Level>\n" + "      <Level name=\"Store City\" visible=\"true\" column=\"store_city\" type=\"String\" uniqueMembers=\"false\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "      </Level>\n" + "      <Level name=\"Store Name\" visible=\"true\" column=\"store_name\" type=\"String\" uniqueMembers=\"true\" levelType=\"Regular\" hideMemberIf=\"Never\">\n" + "        <Property name=\"Store Type\" column=\"store_type\" type=\"String\">\n" + "        </Property>\n" + "        <Property name=\"Store Manager\" column=\"store_manager\" type=\"String\">\n" + "        </Property>\n" + "        <Property name=\"Store Sqft\" column=\"store_sqft\" type=\"Numeric\">\n" + "        </Property>\n" + "        <Property name=\"Grocery Sqft\" column=\"grocery_sqft\" type=\"Numeric\">\n" + "        </Property>\n" + "        <Property name=\"Frozen Sqft\" column=\"frozen_sqft\" type=\"Numeric\">\n" + "        </Property>\n" + "        <Property name=\"Meat Sqft\" column=\"meat_sqft\" type=\"Numeric\">\n" + "        </Property>\n" + "        <Property name=\"Has coffee bar\" column=\"coffee_bar\" type=\"Boolean\">\n" + "        </Property>\n" + "        <Property name=\"Street address\" column=\"store_street_address\" type=\"String\">\n" + "        </Property>\n" + "      </Level>\n" + "    </Hierarchy>\n" + "  </Dimension>\n";
    String cubeDef = "<Cube name=\"Sales1\">" + "  <Table name=\"sales_fact_1997\"/>\n" + dimensionsDef + "</Cube>";
    final TestContext testContext = TestContext.instance().create(null, null, cubeDef, null, null, "<Role name=\"MR\">\n" + "  <SchemaGrant access=\"none\">\n" + "    <CubeGrant cube=\"Sales1\" access=\"all\">\n" + "      <HierarchyGrant hierarchy=\"[Store]\" access=\"all\">\n" + "      </HierarchyGrant>\n" + "      <HierarchyGrant hierarchy=\"[Customers]\" access=\"custom\" topLevel=\"[Customers].[State Province]\" bottomLevel=\"[Customers].[City]\">\n" + "\t  </HierarchyGrant>\n" + "    </CubeGrant>\n" + "  </SchemaGrant>\n" + "</Role>\n" + "<Role name=\"DBPentUsers\">\n" + "   <SchemaGrant access=\"none\">\n" + "   </SchemaGrant>\n" + "</Role>");
    Connection connection = testContext.withRole("MR,DBPentUsers").getConnection();
    final Role.HierarchyAccess hierarchyAccess = getHierarchyAccess(connection, "Sales1", "[Customers]");
    assertEquals(2, hierarchyAccess.getTopLevelDepth());
    assertEquals(3, hierarchyAccess.getBottomLevelDepth());
}
Also used : HierarchyAccess(mondrian.olap.Role.HierarchyAccess)

Example 12 with HierarchyAccess

use of mondrian.olap.Role.HierarchyAccess in project mondrian by pentaho.

the class RolapHierarchy method createMemberReader.

/**
 * Creates a member reader which enforces the access-control profile of
 * <code>role</code>.
 *
 * <p>This method may not be efficient, so the caller should take care
 * not to call it too often. A cache is a good idea.
 *
 * @param role Role
 * @return Member reader that implements access control
 *
 * @pre role != null
 * @post return != null
 */
MemberReader createMemberReader(Role role) {
    final Access access = role.getAccess(this);
    switch(access) {
        case NONE:
            // todo: remove
            role.getAccess(this);
            throw Util.newInternal("Illegal access to members of hierarchy " + this);
        case ALL:
            return (isRagged()) ? new SmartRestrictedMemberReader(getMemberReader(), role) : getMemberReader();
        case CUSTOM:
            final Role.HierarchyAccess hierarchyAccess = role.getAccessDetails(this);
            final Role.RollupPolicy rollupPolicy = hierarchyAccess.getRollupPolicy();
            final NumericType returnType = new NumericType();
            switch(rollupPolicy) {
                case FULL:
                    return new SmartRestrictedMemberReader(getMemberReader(), role);
                case PARTIAL:
                    Type memberType1 = new mondrian.olap.type.MemberType(getDimension(), this, null, null);
                    SetType setType = new SetType(memberType1);
                    ListCalc listCalc = new AbstractListCalc(new DummyExp(setType), new Calc[0]) {

                        public TupleList evaluateList(Evaluator evaluator) {
                            return new UnaryTupleList(getLowestMembersForAccess(evaluator, hierarchyAccess, null));
                        }

                        public boolean dependsOn(Hierarchy hierarchy) {
                            return true;
                        }
                    };
                    final Calc partialCalc = new LimitedRollupAggregateCalc(returnType, listCalc);
                    final Exp partialExp = new ResolvedFunCall(new FunDefBase("$x", "x", "In") {

                        public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
                            return partialCalc;
                        }

                        public void unparse(Exp[] args, PrintWriter pw) {
                            pw.print("$RollupAccessibleChildren()");
                        }
                    }, new Exp[0], returnType);
                    return new LimitedRollupSubstitutingMemberReader(getMemberReader(), role, hierarchyAccess, partialExp);
                case HIDDEN:
                    Exp hiddenExp = new ResolvedFunCall(new FunDefBase("$x", "x", "In") {

                        public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
                            return new ConstantCalc(returnType, null);
                        }

                        public void unparse(Exp[] args, PrintWriter pw) {
                            pw.print("$RollupAccessibleChildren()");
                        }
                    }, new Exp[0], returnType);
                    return new LimitedRollupSubstitutingMemberReader(getMemberReader(), role, hierarchyAccess, hiddenExp);
                default:
                    throw Util.unexpected(rollupPolicy);
            }
        default:
            throw Util.badValue(access);
    }
}
Also used : HierarchyAccess(mondrian.olap.Role.HierarchyAccess) PrintWriter(java.io.PrintWriter) HierarchyAccess(mondrian.olap.Role.HierarchyAccess) DimensionType(mondrian.olap.DimensionType) LevelType(mondrian.olap.LevelType) mondrian.olap(mondrian.olap)

Aggregations

HierarchyAccess (mondrian.olap.Role.HierarchyAccess)12 Hierarchy (mondrian.olap.Hierarchy)7 Role (mondrian.olap.Role)7 MultiCardinalityDefaultMember (mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)5 Dimension (mondrian.olap.Dimension)2 Level (mondrian.olap.Level)2 Schema (mondrian.olap.Schema)2 PrintWriter (java.io.PrintWriter)1 mondrian.olap (mondrian.olap)1 DimensionType (mondrian.olap.DimensionType)1 LevelType (mondrian.olap.LevelType)1 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)1