use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class RepositoryPublishServiceTest method permittedForPublisher.
@Test
public void permittedForPublisher() throws PentahoAccessControlException {
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(PublishAction.NAME)).thenReturn(true);
doReturn(policy).when(repositoryPublishService).getPolicy();
repositoryPublishService.validateAccess();
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method registerMockAuthorizationPolicy.
private IAuthorizationPolicy registerMockAuthorizationPolicy(final boolean isAllowed) {
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(isAllowed);
PentahoSystem.registerObject(policy);
return policy;
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testSetUserSettingByName.
@Test
public void testSetUserSettingByName() throws Exception {
final String settingName = "settingName";
final String settingValue = "settingValue";
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(true);
PentahoSystem.registerObject(policy);
assertEquals(4, userSettings.size());
userSettingService.setUserSetting("test", settingName, settingValue);
assertEquals(5, userSettings.size());
final Serializable value = userSettings.get(UserSettingService.SETTING_PREFIX + settingName);
assertEquals(settingValue, value);
verify(repository).setFileMetadata(eq(USER_FOLDER_ID), anyMap());
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testDeleteUserSettings.
@Test
public void testDeleteUserSettings() throws Exception {
final RepositoryFile repositoryFile = mock(RepositoryFile.class);
when(repositoryFile.getId()).thenReturn(USER_FOLDER_ID);
when(repository.getFile(anyString())).thenReturn(repositoryFile);
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(true);
PentahoSystem.registerObject(policy);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Map<String, Serializable> settings = (Map<String, Serializable>) invocation.getArguments()[1];
assertNotNull(settings);
assertEquals(2, settings.size());
final Iterator<String> iterator = settings.keySet().iterator();
assertFalse(iterator.next().startsWith(UserSettingService.SETTING_PREFIX));
assertFalse(iterator.next().startsWith(UserSettingService.SETTING_PREFIX));
return null;
}
}).when(repository).setFileMetadata(eq(USER_FOLDER_ID), anyMap());
userSettingService.deleteUserSettings();
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class DefaultPluginPerspectiveManager method getPluginPerspectives.
public List<IPluginPerspective> getPluginPerspectives() {
// Compatibility check for old PerspectiveManager behavior. If the pluginPerspectives is empty,
// we'll look in PentahoSystem
List<IPluginPerspective> perspectives = (pluginPerspectives.isEmpty()) ? PentahoSystem.getAll(IPluginPerspective.class, null) : pluginPerspectives;
// don't return the actual list, otherwise the user could remove items without going through our api
ArrayList<IPluginPerspective> allowedPerspectives = new ArrayList<IPluginPerspective>();
for (IPluginPerspective perspective : perspectives) {
ArrayList<String> actions = perspective.getRequiredSecurityActions();
IAuthorizationPolicy policy = PentahoSystem.get(IAuthorizationPolicy.class);
boolean allowed = true;
if (policy != null && actions != null && !actions.isEmpty()) {
// we're going to have to check the user
for (String actionName : actions) {
allowed = policy.isAllowed(actionName);
if (!allowed) {
// don't need to check anymore
break;
}
}
}
if (allowed) {
allowedPerspectives.add(perspective);
}
}
return allowedPerspectives;
}
Aggregations