Search in sources :

Example 1 with IPluginResourceLoader

use of org.pentaho.platform.api.engine.IPluginResourceLoader in project data-access by pentaho.

the class SimpleDataAccessPermissionHandler method hasDataAccessPermission.

@Override
public boolean hasDataAccessPermission(IPentahoSession session) {
    if (policy.isAllowed("org.pentaho.platform.dataaccess.datasource.security.manage")) {
        return true;
    }
    Authentication auth = SecurityHelper.getInstance().getAuthentication(session, true);
    IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null);
    String roles = null;
    String users = null;
    try {
        // $NON-NLS-1$
        roles = resLoader.getPluginSetting(getClass(), "settings/data-access-roles");
        // $NON-NLS-1$
        users = resLoader.getPluginSetting(getClass(), "settings/data-access-users");
    } catch (Exception e) {
        logger.debug("Error getting data access plugin settings", e);
    }
    if (roles != null && roles.length() > 0) {
        // $NON-NLS-1$
        String[] roleArr = roles.split(",");
        for (String role : roleArr) {
            for (GrantedAuthority userRole : auth.getAuthorities()) {
                if (role != null && role.trim().equals(userRole.getAuthority())) {
                    return true;
                }
            }
        }
    }
    if (users != null && users.length() > 0) {
        // $NON-NLS-1$
        String[] userArr = users.split(",");
        for (String user : userArr) {
            if (user != null && user.trim().equals(auth.getName())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader)

Example 2 with IPluginResourceLoader

use of org.pentaho.platform.api.engine.IPluginResourceLoader in project data-access by pentaho.

the class SimpleDataAccessViewPermissionHandler method getPermittedUserList.

@Override
public List<String> getPermittedUserList(IPentahoSession session) {
    List<String> userList = new ArrayList<String>();
    IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null);
    String users = null;
    try {
        // $NON-NLS-1$
        users = resLoader.getPluginSetting(getClass(), "settings/data-access-view-users");
    } catch (Exception e) {
        logger.debug("Error getting plugin setting", e);
    }
    if (users != null && users.length() > 0) {
        // $NON-NLS-1$
        String[] userArr = users.split(",");
        for (String user : userArr) {
            if (user != null && user.trim().length() > 0) {
                userList.add(user);
            }
        }
    }
    return userList;
}
Also used : ArrayList(java.util.ArrayList) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader)

Example 3 with IPluginResourceLoader

use of org.pentaho.platform.api.engine.IPluginResourceLoader in project data-access by pentaho.

the class SimpleDataAccessViewPermissionHandler method getDefaultAcls.

public int getDefaultAcls(IPentahoSession session) {
    IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null);
    String defaultAclsAsString = null;
    int defaultAcls = -1;
    try {
        defaultAclsAsString = // $NON-NLS-1$
        resLoader.getPluginSetting(getClass(), "settings/data-access-default-view-acls");
    } catch (Exception e) {
        logger.debug("Error getting plugin setting", e);
    }
    if (defaultAclsAsString != null && defaultAclsAsString.length() > 0) {
        defaultAcls = Integer.parseInt(defaultAclsAsString);
    }
    return defaultAcls;
}
Also used : IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader)

Example 4 with IPluginResourceLoader

use of org.pentaho.platform.api.engine.IPluginResourceLoader in project data-access by pentaho.

the class DataSourcePublishIT method setUp.

@Before
public void setUp() throws Exception {
    repositoryBase.setUp();
    repositoryBase.loginAsRepositoryAdmin();
    defaultTenant = repositoryBase.createTenant(repositoryBase.getSystemTenant(), TenantUtils.getDefaultTenant());
    singleTenantAdminUserName = (String) applicationContext.getBean("singleTenantAdminUserName");
    repositoryBase.createUser(defaultTenant, singleTenantAdminUserName, PASSWORD, new String[] { repositoryBase.getTenantAdminRoleName() });
    final String singleTenantAuthenticatedAuthorityName = (String) applicationContext.getBean("singleTenantAuthenticatedAuthorityName");
    repositoryBase.createUser(defaultTenant, USERNAME_SUZY, PASSWORD, new String[] { singleTenantAuthenticatedAuthorityName });
    repositoryBase.createUser(defaultTenant, USERNAME_TIFFANY, PASSWORD, new String[] { singleTenantAuthenticatedAuthorityName });
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName() });
    final IUnifiedRepository repo = PentahoSystem.get(IUnifiedRepository.class);
    String etcID = String.valueOf(repo.getFile(ClientRepositoryPaths.getEtcFolderPath()).getId());
    repo.createFolder(etcID, new RepositoryFile.Builder(MondrianCatalogHelper.MONDRIAN_DATASOURCE_FOLDER).folder(true).build(), "initialization");
    repo.createFolder(etcID, new RepositoryFile.Builder(PentahoMetadataDomainRepositoryInfo.getMetadataFolderName()).folder(true).build(), "initialization");
    final MicroPlatform mp = repositoryBase.getMp();
    mp.define(IMondrianCatalogService.class, MondrianCatalogHelper.class);
    mp.define(ISystemConfig.class, SystemConfig.class);
    mp.defineInstance(IPlatformMimeResolver.class, applicationContext.getBean("IPlatformImportMimeResolver"));
    mp.defineInstance(IPlatformImporter.class, applicationContext.getBean("IPlatformImporter"));
    mp.defineInstance(ICacheManager.class, applicationContext.getBean("ICacheManager"));
    mp.defineInstance(IMetadataDomainRepository.class, applicationContext.getBean("IMetadataDomainRepository"));
    final PluginResourceLoader pluginResourceLoader = (PluginResourceLoader) applicationContext.getBean("IPluginResourceLoader");
    pluginResourceLoader.setRootDir(new File("target/test-classes/solutionACL/system/data-access"));
    mp.defineInstance(IPluginResourceLoader.class, pluginResourceLoader);
    mp.define(IDataAccessPermissionHandler.class, SimpleDataAccessPermissionHandler.class);
    mp.define(IDataAccessViewPermissionHandler.class, SimpleDataAccessViewPermissionHandler.class);
    mp.defineInstance(IAclVoter.class, new PentahoAllowAllAclVoter());
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
    super.setUp();
}
Also used : PluginResourceLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) PentahoAllowAllAclVoter(org.pentaho.platform.engine.security.acls.voter.PentahoAllowAllAclVoter) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Example 5 with IPluginResourceLoader

use of org.pentaho.platform.api.engine.IPluginResourceLoader in project pentaho-platform by pentaho.

the class PluginGwtRpcTest method testLoadSerializationPolicyWhenPluginResource.

@Test
public void testLoadSerializationPolicyWhenPluginResource() throws MalformedURLException {
    String pathInfo = "/serviceName";
    String pluginId = "data-access";
    String moduleContextPath = "/content/data-access/resources/gwt/";
    String strongName = "ABC";
    String policyFilename = strongName + ".gwt.rpc";
    URL policy1Url = new URL("file:///resources/gwt/a/" + policyFilename);
    try (MockedStatic<PluginUtil> pluginUtilMock = mockStatic(PluginUtil.class)) {
        pluginUtilMock.when(() -> PluginUtil.getPluginIdFromPath(moduleContextPath)).thenReturn(pluginId);
        // ----
        // There is no configured SP bean.
        pentahoSystemMock = mockStatic(PentahoSystem.class);
        pentahoSystemMock.when(() -> PentahoSystem.get(eq(SerializationPolicy.class), eq(null), anyMap())).thenReturn(null);
        // ---
        ClassLoader pluginClassLoader = mock(ClassLoader.class);
        when(PluginUtil.getClassLoaderForService(moduleContextPath)).thenReturn(pluginClassLoader);
        // ---
        // More than one serialization policy resource found.
        IPluginResourceLoader resLoaderMock = mock(IPluginResourceLoader.class);
        when(resLoaderMock.findResources(pluginClassLoader, policyFilename)).thenReturn(Collections.singletonList(policy1Url));
        when(PentahoSystem.get(eq(IPluginResourceLoader.class), eq(null))).thenReturn(resLoaderMock);
        // ---
        InputStream pluginPolicyInputStreamMock = mock(InputStream.class);
        // Spying requires a non-final class. Lambda expression is not suitable.
        @SuppressWarnings("Convert2Lambda") ThrowingSupplier<InputStream, IOException> pluginPolicyInputStreamSupplierSpy = spy(new ThrowingSupplier<InputStream, IOException>() {

            @Override
            public InputStream get() {
                return pluginPolicyInputStreamMock;
            }
        });
        // ---
        SerializationPolicy pluginPolicyMock = mock(SerializationPolicy.class);
        try (MockedStatic<AbstractGwtRpc> abstractGwtRpcMock = mockStatic(AbstractGwtRpc.class)) {
            abstractGwtRpcMock.when(() -> AbstractGwtRpc.loadSerializationPolicyFromInputStream(pluginPolicyInputStreamSupplierSpy, policyFilename)).thenReturn(pluginPolicyMock);
            // ---
            HttpServletRequest httpRequestMock = setupHttpRequest(pathInfo);
            PluginGwtRpc gwtRpcSpy = spy(new PluginGwtRpc(httpRequestMock));
            doReturn(pluginPolicyInputStreamSupplierSpy).when(gwtRpcSpy).getInputStreamSupplier(policy1Url);
            // ---
            SerializationPolicy result = gwtRpcSpy.loadSerializationPolicy(moduleContextPath, strongName);
            // ---
            assertEquals(pluginPolicyMock, result);
            verify(loggerMock, times(0)).error(nullable(String.class));
            verify(loggerMock, times(0)).warn(nullable(String.class));
        }
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) IOException(java.io.IOException) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) URL(java.net.URL) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) HttpServletRequest(javax.servlet.http.HttpServletRequest) PluginUtil(org.pentaho.platform.plugin.services.pluginmgr.PluginUtil) Test(org.junit.Test)

Aggregations

IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)19 InputStream (java.io.InputStream)6 URL (java.net.URL)4 SerializationPolicy (com.google.gwt.user.server.rpc.SerializationPolicy)3 IOException (java.io.IOException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Test (org.junit.Test)3 PentahoSystem (org.pentaho.platform.engine.core.system.PentahoSystem)3 PluginUtil (org.pentaho.platform.plugin.services.pluginmgr.PluginUtil)3 ArrayList (java.util.ArrayList)2 IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)2 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)2 Authentication (org.springframework.security.core.Authentication)2 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Properties (java.util.Properties)1 Document (org.dom4j.Document)1