Search in sources :

Example 31 with IUserRoleListService

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

the class SecurityHelperTest method testNestedCalls.

@Test
public /**
 * Authenticate as Suzy, make a runAsSystem() call with an embedded runAsUser(), verify that Authentication is
 * restored successfully.
 */
void testNestedCalls() throws Exception {
    IUserRoleListService userRoleListService = getUserRoleListServiceMock("admin", new String[] { "authenticated" });
    when(userRoleListService.getRolesForUser(Matchers.<ITenant>any(), eq("suzy"))).thenReturn(Collections.singletonList("authenticated"));
    PentahoSystem.registerObject(userRoleListService);
    PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<String>(String.class).object("admin").attributes(Collections.<String, Object>singletonMap("id", "singleTenantAdminUserName")).build());
    SecurityContextHolder.setStrategyName(PentahoSecurityContextHolderStrategy.class.getName());
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("suzy", "password");
    SecurityContextHolder.getContext().setAuthentication(token);
    SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try {
                SecurityHelper.getInstance().runAsUser("suzy", new Callable<Void>() {

                    @Override
                    public Void call() throws Exception {
                        assertEquals(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername(), "suzy");
                        throw new NullPointerException();
                    }
                });
            } catch (Exception e) {
            /* No-op */
            }
            assertEquals(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername(), "admin");
            return null;
        }
    });
    assertSame(SecurityContextHolder.getContext().getAuthentication(), token);
}
Also used : User(org.springframework.security.core.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 32 with IUserRoleListService

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

the class PentahoSamlUserRoleListService method initUserRoleListService.

protected void initUserRoleListService() {
    // If SAML is selected, default to the native user role list service
    if (getSelectedAuthorizationProvider().equals(getSamlId())) {
        setService(getSamlUserRoleListService());
        return;
    }
    Map<String, String> props = new HashMap<>();
    props.put(PROVIDER_NAME, getSelectedAuthorizationProvider());
    IUserRoleListService userRoleListService;
    if ((userRoleListService = PentahoSystem.get(IUserRoleListService.class, null, props)) != null) {
        setService(userRoleListService);
    } else {
        logger.error("No IUserRoleListService found for providerName '" + getSelectedAuthorizationProvider() + "'");
    }
}
Also used : HashMap(java.util.HashMap) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService)

Example 33 with IUserRoleListService

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

the class SerializeMultiTableServiceIT method setUp.

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

        protected PluginClassLoader getOverrideClassloader() {
            return new PluginClassLoader(new File(".", "target/test-classes/solution1/system/simple-jndi"), this);
        }
    });
    booter.defineInstance(IUserRoleListService.class, mockUserRoleListService);
    booter.setSettingsProvider(new SystemSettings());
    booter.start();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) PluginResourceLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) PluginClassLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader) Before(org.junit.Before)

Example 34 with IUserRoleListService

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

the class SerializeServiceIT method setUp.

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

        protected PluginClassLoader getOverrideClassloader() {
            return new PluginClassLoader(new File(".", "target/test-classes/solution1/system/simple-jndi"), this);
        }
    });
    booter.defineInstance(IUserRoleListService.class, mockUserRoleListService);
    booter.setSettingsProvider(new SystemSettings());
    booter.start();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) PluginResourceLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) PluginClassLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader) Before(org.junit.Before)

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