Search in sources :

Example 31 with IAuthorizationPolicy

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();
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Test(org.junit.Test)

Example 32 with IAuthorizationPolicy

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;
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy)

Example 33 with IAuthorizationPolicy

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());
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Serializable(java.io.Serializable) Test(org.junit.Test)

Example 34 with IAuthorizationPolicy

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();
}
Also used : Answer(org.mockito.stubbing.Answer) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Serializable(java.io.Serializable) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Iterator(java.util.Iterator) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 35 with IAuthorizationPolicy

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;
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) ArrayList(java.util.ArrayList) IPluginPerspective(org.pentaho.platform.api.engine.perspective.pojo.IPluginPerspective)

Aggregations

IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)40 Test (org.junit.Test)18 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)11 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)7 Serializable (java.io.Serializable)6 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)6 File (java.io.File)5 Before (org.junit.Before)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 FileNotFoundException (java.io.FileNotFoundException)4 HashMap (java.util.HashMap)4 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)4 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)4 PluginClassLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader)4 PluginResourceLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader)4 InputStream (java.io.InputStream)3 Matchers.anyString (org.mockito.Matchers.anyString)3 SystemSettings (org.pentaho.platform.engine.core.system.SystemSettings)3 MockSecurityHelper (org.pentaho.test.platform.engine.security.MockSecurityHelper)3 OutputStream (java.io.OutputStream)2