Pentaho中的动态模式处理器

时间:2015-09-25 12:46:11

标签: pentaho mondrian

我有一个使用以下代码配置的工作dsp。我还想检索用户角色并在稍后的查询中使用它。有谁知道如何从用户那里检索角色?

public class SubscriptionCountry extends FilterDynamicSchemaProcessorimplements DynamicSchemaProcessor {
private static final String BBDD_HOST = "xxx";
private static final String BBDD_PORT = "xxx";
private static final String BBDD_NAME = "xxx";
private static final String BBDD_USER = "xxx";
private static final String BBDD_PASSWORD = "xxx";
public SubscriptionCountry() {

}
@Override
public String filter(String schemaUrl, Util.PropertyList connectInfo, InputStream stream) throws Exception {
    String schema = super.filter(schemaUrl, connectInfo, stream);

    Connection c = null;
    String country_list = "";

    try {
        // Get Pentaho Session
        IPentahoSession session = PentahoSessionHolder.getSession();

        // Get user from session variable
        String userName = session.getName().toString();

        String query_countries = "";
        query_countries = "SELECT something from a table where username = + userName";

        Class.forName("org.postgresql.Driver");
        c = DriverManager.getConnection("jdbc:postgresql://" + BBDD_HOST + ":" + BBDD_PORT + "/" + BBDD_NAME,BBDD_USER, BBDD_PASSWORD);
        Statement st = c.createStatement();
        ResultSet rs = st.executeQuery(query_countries);
        rs.next();
        country_list = rs.getString("country_list");
        rs.close();
        st.close();
    } 
    try {
        schema = schema.replaceAll("%COUNTRY_LIST%", country_list);
    }
    return schema;
}

}

1 个答案:

答案 0 :(得分:0)

我在jsp中完成了它:我想它也适用于你:

那些是我的jsp中的导入(也许你不需要所有东西......):

<%@page import="org.pentaho.platform.api.engine.IAuthorizationPolicy" %>
<%@page import="org.pentaho.platform.api.engine.IPluginManager" %>
<%@page import="org.pentaho.platform.engine.core.system.PentahoSessionHolder" %>
<%@page import="org.pentaho.platform.engine.core.system.PentahoSystem" %>
<%@page import="org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction" %>
<%@page import="org.pentaho.platform.security.policy.rolebased.actions.RepositoryCreateAction" %>
<%@page import="java.util.List" %>
<%@page import="java.util.Locale"%>
<%@page import="javax.servlet.http.HttpServletRequest"%>
<%@page import="org.pentaho.platform.api.engine.IPentahoSession"%>
<%@page import="org.pentaho.platform.engine.security.SecurityParameterProvider"%>

然后:

SecurityParameterProvider secpro= new SecurityParameterProvider(PentahoSessionHolder.getSession() );
 String listroles = secpro.getStringParameter("principalRoles","aucun");

listroles包含角色列表

另见:

http://javadoc.pentaho.com/bi-platform/dev/org/pentaho/platform/engine/security/SecurityParameterProvider.html