Search in sources :

Example 11 with IUserRoleListService

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

the class HttpWebService method getUsers.

/**
 * Returns XML for list of users.
 */
protected Document getUsers() throws ServletException, IOException {
    IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class);
    Element rootElement = new DefaultElement("users");
    Document doc = DocumentHelper.createDocument(rootElement);
    if (service != null) {
        List users = service.getAllUsers();
        for (Iterator usersIterator = users.iterator(); usersIterator.hasNext(); ) {
            String username = usersIterator.next().toString();
            if ((null != username) && (username.length() > 0)) {
                rootElement.addElement("user").addCDATA(username);
            }
        }
    }
    return doc;
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Document(org.dom4j.Document)

Example 12 with IUserRoleListService

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

the class SystemServiceTest method testGetUsers.

@Test
public void testGetUsers() throws Exception {
    IUserRoleListService service = mock(IUserRoleListService.class);
    PentahoSystem.registerObject(service);
    doReturn(true).when(systemService).canAdminister();
    assertNotNull(systemService.getUsers());
    PentahoSystem.clearObjectFactory();
}
Also used : IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 13 with IUserRoleListService

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

the class UserRoleListServiceTest method testDoGetRoles.

@Test
public void testDoGetRoles() {
    List<String> roles = new ArrayList<String>();
    roles.add("ROLE1");
    roles.add("ROLE2");
    IUserRoleListService userRoleListService1 = mock(IUserRoleListService.class);
    doReturn(userRoleListService1).when(userRoleListService).getUserRoleListService();
    doReturn(roles).when(userRoleListService1).getAllRoles();
    RoleListWrapper roleListWrapper = userRoleListService.getRoles();
    verify(userRoleListService).getUserRoleListService();
    verify(userRoleListService1).getAllRoles();
    assertEquals(roles, roleListWrapper.getRoles());
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) ArrayList(java.util.ArrayList) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 14 with IUserRoleListService

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

the class UserRoleListServiceTest method testGetPermissionRoles.

@Test
public void testGetPermissionRoles() {
    List<String> roles = new ArrayList<String>();
    roles.add("ROLE1");
    roles.add("ROLE2");
    roles.add("ADMIN_ROLE");
    IUserRoleListService userRoleListService1 = mock(IUserRoleListService.class);
    doReturn(userRoleListService1).when(userRoleListService).getUserRoleListService();
    doReturn(roles).when(userRoleListService1).getAllRoles();
    ArrayList<String> extraRoles = new ArrayList<String>();
    extraRoles.add("EXTRA_ROLE1");
    extraRoles.add("EXTRA_ROLE2");
    userRoleListService.setExtraRoles(extraRoles);
    RoleListWrapper roleWrapper = userRoleListService.getPermissionRoles("ADMIN_ROLE");
    assertTrue(!roleWrapper.getRoles().contains("ADMIN_ROLE"));
    assertTrue(roleWrapper.getRoles().size() == 4);
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) ArrayList(java.util.ArrayList) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 15 with IUserRoleListService

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

the class DatasourceResourceIT method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.root", "target/test-classes/solution1/system/simple-jndi");
    mp = new MicroPlatform("target/test-classes/solution1");
    IAuthorizationPolicy mockAuthorizationPolicy = mock(IAuthorizationPolicy.class);
    when(mockAuthorizationPolicy.isAllowed(anyString())).thenReturn(true);
    IUserRoleListService mockUserRoleListService = mock(IUserRoleListService.class);
    IDataAccessPermissionHandler mockDataAccessPermHandler = mock(IDataAccessPermissionHandler.class);
    when(mockDataAccessPermHandler.hasDataAccessPermission(any(IPentahoSession.class))).thenReturn(true);
    mp.define(ISolutionEngine.class, SolutionEngine.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
    mp.define(IUnifiedRepository.class, TestFileSystemBackedUnifiedRepository.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
    mp.define(IMondrianCatalogService.class, MondrianCatalogHelper.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
    mp.define("connection-SQL", SQLConnection.class);
    mp.define("connection-MDX", MDXConnection.class);
    mp.define("connection-MDXOlap4j", MDXOlap4jConnection.class);
    mp.define(IDBDatasourceService.class, JndiDatasourceService.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
    mp.define(MDXConnection.MDX_CONNECTION_MAPPER_KEY, MondrianOneToOneUserRoleListMapper.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
    mp.define(IDatasourceMgmtService.class, MockDatasourceMgmtService.class);
    mp.define(IClientRepositoryPathsStrategy.class, MockClientRepositoryPathsStrategy.class);
    mp.define(ISecurityHelper.class, MockSecurityHelper.class);
    mp.define(UserDetailsService.class, MockUserDetailService.class);
    mp.define("singleTenantAdminUserName", "admin");
    mp.defineInstance(IMetadataDomainRepository.class, createMetadataDomainRepository());
    mp.defineInstance(IAuthorizationPolicy.class, mockAuthorizationPolicy);
    mp.defineInstance(IPluginResourceLoader.class, new PluginResourceLoader() {

        protected PluginClassLoader getOverrideClassloader() {
            return new PluginClassLoader(new File(".", "target/test-classes/solution1/system/simple-jndi"), this);
        }
    });
    mp.defineInstance(IUserRoleListService.class, mockUserRoleListService);
    mp.defineInstance(IDataAccessPermissionHandler.class, mockDataAccessPermHandler);
    mp.setSettingsProvider(new SystemSettings());
    mp.start();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}
Also used : PluginResourceLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) PluginClassLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader) BeforeClass(org.junit.BeforeClass)

Aggregations

IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)34 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)8 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)5 List (java.util.List)4 Document (org.dom4j.Document)4 Element (org.dom4j.Element)4 DefaultElement (org.dom4j.tree.DefaultElement)4 RoleListWrapper (org.pentaho.platform.web.http.api.resources.RoleListWrapper)4 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)4 File (java.io.File)3 Callable (java.util.concurrent.Callable)3 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)3 ITenant (org.pentaho.platform.api.mt.ITenant)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 SystemSettings (org.pentaho.platform.engine.core.system.SystemSettings)3 PluginClassLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader)3 PluginResourceLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2