Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Custom connection not applied

  1. #1
    Join Date
    Jun 2014
    Posts
    168

    Default Custom connection not applied

    Hello,

    I'm trying to use delegate roles. I have complete all the steps for multi-tenancy, but my custom connection is never applied.

    I modify the pentahoObjects.spring.xml file with:
    Code:
    <bean id="connection-MDXOlap4j" class="delegatingrolepackage.CustomMDXOlap4jConnection" scope="prototype">  <property name="useExtendedColumnNames" value="true" /> </bean>
    But it's not applied. Whatsmore, if I comment all the connections beans, everything seems to continue working, so that code doesn't do anything. Where Should I set the used connection?

    Thanks.

  2. #2
    Join Date
    Jun 2014
    Posts
    168

    Default

    My code:

    Schema Role:
    Code:
    <Role name="Reports User">
        <SchemaGrant access="all">
            <CubeGrant cube="Patients" access="all">
                <HierarchyGrant hierarchy="[Center]" rollupPolicy="partial" access="custom">
                    <MemberGrant member="[Center].[Center].[Institut G]" access="all">
                    </MemberGrant>
                </HierarchyGrant>
            </CubeGrant>
            <CubeGrant cube="Functions" access="all">
                <HierarchyGrant hierarchy="[Center]" rollupPolicy="partial" access="custom">
                    <MemberGrant member="[Center].[Center].[Institut G]" access="all">
                    </MemberGrant>
                </HierarchyGrant>
            </CubeGrant>
            <CubeGrant cube="Tests" access="all">
                <HierarchyGrant hierarchy="[Center]" rollupPolicy="partial" access="custom">
                    <MemberGrant member="[Center].[Center].[Institut G]" access="all">
                    </MemberGrant>
                </HierarchyGrant>
            </CubeGrant>
        </SchemaGrant>
    </Role>
    Custom connection:
    Code:
    package org.cognitio;
    
    
    import java.util.Properties;
    import mondrian.olap.Role;
    import mondrian.rolap.RolapConnection;
    import org.pentaho.platform.engine.core.system.PentahoSystem;
    import org.pentaho.platform.plugin.services.connections.mondrian.MDXOlap4jConnection;
    
    
    public class CustomMDXOlap4jConnection extends MDXOlap4jConnection {
    
    
        @Override
        public boolean connect(Properties props) {
            boolean result = super.connect(props);
            if (result && this.connection != null) {
                try {
                    RolapConnection rolapConnection = 
                        this.connection.unwrap(RolapConnection.class);
                    Role delegateRole = 
                        rolapConnection.getSchema().lookupRole("Reports User");
                    if (delegateRole != null) {
                        CustomDelegatingRole customRole = 
                            new CustomDelegatingRole(delegateRole);
                        rolapConnection.setRole(customRole);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
    
    
            return result;
        }
    }
    Custom role:
    Code:
    package org.cognitio;
    
    
    import mondrian.olap.Access;
    import mondrian.olap.DelegatingRole;
    import mondrian.olap.Hierarchy;
    import mondrian.olap.Level;
    import mondrian.olap.Member;
    import mondrian.olap.Role;
    import mondrian.olap.RoleImpl;
    import org.pentaho.platform.engine.core.system.PentahoSessionHolder;
    import org.pentaho.platform.engine.core.system.PentahoSystem;
    
    
    public class CustomDelegatingRole extends DelegatingRole {
    
    
        private String myCenter;
        private String myAccess;
        private static String HIERARCHY_NAME = "Center";
        
        public CustomDelegatingRole(Role role) {
            super(((RoleImpl) role).makeMutableClone());
            this.myCenter = (String) PentahoSessionHolder.getSession().
                getAttribute("CENTER");
            this.myAccess = (String) PentahoSessionHolder.getSession().
                getAttribute("ACCESS");
        }
        
        @Override
        public HierarchyAccess getAccessDetails(Hierarchy hierarchy) {
            HierarchyAccess ha = super.getAccessDetails(hierarchy);
            return (ha == null ? null : new CustomHierarchyAccess(ha));
        }
        
        protected class CustomHierarchyAccess extends RoleImpl.DelegatingHierarchyAccess {
            
            public CustomHierarchyAccess(HierarchyAccess ha) {
                super(ha);
            }
            
            @Override
            public Access getAccess(Member member) {
                return CustomDelegatingRole.this.
                    getAccess(member, hierarchyAccess.getAccess(member));
            }
        }
        
        @Override
        public Access getAccess(Hierarchy hierarchy) {
            return role.getAccess(hierarchy);
        }
        
        @Override
        public Access getAccess(Member member) {
            return getAccess(member, role.getAccess(member));
        }
        
        protected Access getAccess(Member member, Access access) {
            String memberHierarchyName = member.getHierarchy().getName();
            if (memberHierarchyName.contains(HIERARCHY_NAME)) {
                if (this.myAccess.equalsIgnoreCase("Total")) {
                    return Access.ALL;
                } else {
                    if (member.getName().equalsIgnoreCase(this.myCenter)) {
                        return Access.ALL;
                    }
    
    
                    for (Member mem : member.getAncestorMembers()) {
                        if (mem.getName().equalsIgnoreCase(this.myCenter)) {
                            return Access.ALL;
                        }
                    }
                }
                
                Access acc = (access == Access.CUSTOM) ? access : Access.NONE;
                return acc;
            }
            
            return access;
        }
        
        @Override
        public Access getAccess(Level level) {
            return role.getAccess(level);
        }
    }
    Connection bean:
    Code:
    <bean id="connection-MDXOlap4j" class="org.cognitio.CustomMDXOlap4jConnection" scope="prototype">
        <property name="useExtendedColumnNames" value="true" />
      </bean>
    What's wrong?

    Thanks.

  3. #3
    Join Date
    Jun 2014
    Posts
    168

    Default

    Can anyone confirm if this approach should work in BI Server 6.1?

  4. #4
    Join Date
    Jun 2014
    Posts
    168

    Default

    Any idea how to check why the connection is not used? I have set to DEBUG the Pentaho logs, but I don't see anyhting related with it.

    Is anyone using this approach?

    Thanks.

    PD: Are the Adventure Works database and schema (I think it's the catalog used in the documentation) available?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.