Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Custom MDX connection to dynamically change roles

  1. #1
    Join Date
    Sep 2011
    Posts
    26

    Default Custom MDX connection to dynamically change roles

    Hello. I am having problems to dynamically change the role of an user in Pentaho.

    I am trying it with the Steel Wheels schema and I hope to get some help here.

    First I added this to the mondrian schema:
    HTML Code:
    <Role name="Region Manager">
      <SchemaGrant access="all">
        <CubeGrant cube="SteelWheelsSales" access="all">
          <HierarchyGrant hierarchy="[Markets].[Markets]" access="custom" rollupPolicy="partial">
            <MemberGrant member="[Markets].[APAC]" access="all"/>
          </HierarchyGrant>
        </CubeGrant>
      </SchemaGrant>
    </Role>
    And I implemented my custom SteelWheelsMDXConnection class and added it to the connection-MDX bean in pentahoObjects.spring.xml:

    Code:
    import mondrian.olap.*;
    import org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection;
    
    public class SteelWheelsMDXConnection extends MDXConnection {
      @Override
      protected void init (Util.PropertyList properties) {
        super.init(properties);
        Connection thisConn = this.getConnection();
        Role authRole = thisConn.getSchema().lookupRole("Region Manager");
        SteelWheelsCustomRole customRole = new SteelWheelsCustomRole(authRole, thisConn.getSchema());
        thisConn.setRole(customRole);
        setRole(customRole);
      }
    }
    Finally this is the code for the SteelWheelsCustomRole class:

    Code:
    import mondrian.olap.*;
    import java.util.List;
    
    
    public class SteelWheelsCustomRole extends DelegatingRole {
    
    
     public SteelWheelsCustomRole(Role role, Schema schema) {
       super(((RoleImpl)role).makeMutableClone());
      defineGrantsForUser(schema);
     }
    
    
     private void defineGrantsForUser(Schema schema) {
      RoleImpl role = (RoleImpl) this.role;
      Cube cube = schema.lookupCube("SteelWheelsSales", true);
      Dimension dimension = null;
      for (Dimension d : cube.getDimensions()) {
       if (d.getName().compareTo("Markets") == 0) {
       dimension = d;
       break;
       }
      }
      Hierarchy hierarchy = dimension.getHierarchies()[0];
      Level[] levels = hierarchy.getLevels();
      Level topLevel = levels[1];
      List <Member> members = schema.getSchemaReader().withLocus().getLevelMembers(topLevel, true);
      for (Member member : members) {
       if (member.getName().compareTo("Japan") == 0) {
        role.grant(member, Access.ALL);
       } else {
        role.grant(member, Access.NONE);
       }
      }
     }
    }
    I removed Log lines for readability, but this code runs without errors. The result should be that the user that has the "Region Manager" role can only see the Japan market. But when I log in Pentaho and create a new analysis view, I still get the old role, and only APAC is visible.

    Do you know what I am doing wrong? It just looks like the role is being created well but it is not saved to the connection somehow.

    Any help would be much apreciated!

  2. #2

    Default

    Hello,

    I never do it this. But in the aplication "Workbench Schema" you had a tool to do that.

Tags for this Thread

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.