Search in sources :

Example 1 with FileRepository

use of mondrian.server.FileRepository in project pentaho-platform by pentaho.

the class PentahoXmlaServlet method createConnectionFactory.

@Override
protected ConnectionFactory createConnectionFactory(final ServletConfig servletConfig) throws ServletException {
    final ConnectionFactory delegate = super.createConnectionFactory(servletConfig);
    /*
     * This wrapper for the connection factory allows us to
     * override the list of roles with the ones defined in
     * the IPentahoSession and filter it through the
     * IConnectionUserRoleMapper.
     */
    return new ConnectionFactory() {

        public Map<String, Object> getPreConfiguredDiscoverDatasourcesResponse() {
            return delegate.getPreConfiguredDiscoverDatasourcesResponse();
        }

        public OlapConnection getConnection(String databaseName, String catalogName, String roleName, Properties props) throws SQLException {
            // What we do here is to filter the role names with the mapper.
            // First, get a user role mapper, if one is configured.
            final IPentahoSession session = PentahoSessionHolder.getSession();
            final IConnectionUserRoleMapper mondrianUserRoleMapper = PentahoSystem.get(IConnectionUserRoleMapper.class, MDXConnection.MDX_CONNECTION_MAPPER_KEY, // Don't use the user session here yet.
            null);
            String[] effectiveRoles = new String[0];
            /*
         * If Catalog/Schema are null (this happens with high level metadata requests,
         * like DISCOVER_DATASOURCES) we can't use the role mapper, even if it
         * is present and configured.
         */
            if (mondrianUserRoleMapper != null && catalogName != null) {
                // Use the role mapper.
                try {
                    effectiveRoles = mondrianUserRoleMapper.mapConnectionRoles(session, catalogName);
                    if (effectiveRoles == null) {
                        effectiveRoles = new String[0];
                    }
                } catch (PentahoAccessControlException e) {
                    throw new SQLException(e);
                }
            }
            // Now we tokenize that list.
            boolean addComma = false;
            // $NON-NLS-1$
            roleName = "";
            for (String role : effectiveRoles) {
                if (addComma) {
                    // $NON-NLS-1$
                    roleName = roleName.concat(",");
                }
                roleName = roleName.concat(role);
                addComma = true;
            }
            // Now let the delegate connection factory do its magic.
            if (catalogName == null) {
                return delegate.getConnection(databaseName, catalogName, roleName.equals("") ? null : roleName, props);
            } else {
                // We create a connection differently so we can ensure that
                // the XMLA servlet shares the same MondrianServer instance as the rest
                // of the platform
                IMondrianCatalogService mcs = PentahoSystem.get(IMondrianCatalogService.class);
                MondrianCatalog mc = mcs.getCatalog(catalogName, PentahoSessionHolder.getSession());
                if (mc == null) {
                    throw new XmlaException(CLIENT_FAULT_FC, HSB_BAD_RESTRICTION_LIST_CODE, HSB_BAD_RESTRICTION_LIST_FAULT_FS, new MondrianException("No such catalog: " + catalogName));
                }
                Connection con = DriverManager.getConnection(mc.getDataSourceInfo() + ";Catalog=" + mc.getDefinition(), catalogLocator);
                try {
                    final MondrianServer server = MondrianServer.forConnection(con);
                    FileRepository fr = new FileRepository(makeContentFinder(makeDataSourcesUrl(servletConfig)), catalogLocator);
                    OlapConnection connection = fr.getConnection(server, databaseName, catalogName, roleName, props);
                    fr.shutdown();
                    return connection;
                } finally {
                    con.close();
                }
            }
        }
    };
}
Also used : FileRepository(mondrian.server.FileRepository) MondrianServer(mondrian.olap.MondrianServer) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) SQLException(java.sql.SQLException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IConnectionUserRoleMapper(org.pentaho.platform.api.engine.IConnectionUserRoleMapper) OlapConnection(org.olap4j.OlapConnection) OlapConnection(org.olap4j.OlapConnection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) Connection(mondrian.olap.Connection) Properties(java.util.Properties) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ConnectionFactory(mondrian.xmla.XmlaHandler.ConnectionFactory) SolutionRepositoryVfsFileObject(org.pentaho.platform.repository.solution.filebased.SolutionRepositoryVfsFileObject) XmlaException(mondrian.xmla.XmlaException) MondrianException(mondrian.olap.MondrianException)

Aggregations

SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 Connection (mondrian.olap.Connection)1 MondrianException (mondrian.olap.MondrianException)1 MondrianServer (mondrian.olap.MondrianServer)1 FileRepository (mondrian.server.FileRepository)1 XmlaException (mondrian.xmla.XmlaException)1 ConnectionFactory (mondrian.xmla.XmlaHandler.ConnectionFactory)1 OlapConnection (org.olap4j.OlapConnection)1 IConnectionUserRoleMapper (org.pentaho.platform.api.engine.IConnectionUserRoleMapper)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)1 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)1 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)1 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)1 SolutionRepositoryVfsFileObject (org.pentaho.platform.repository.solution.filebased.SolutionRepositoryVfsFileObject)1