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;
}
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;
}
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;
}
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();
}
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));
}
}
}
Aggregations