use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class UserRoleListServiceTest method testGetUsers.
@Test
public void testGetUsers() {
IUserRoleListService service = mock(IUserRoleListService.class);
doReturn(service).when(userRoleListService).getUserRoleListService();
List<String> users = new ArrayList<String>();
users.add("admin");
users.add("joe");
users.add("suzy");
doReturn(users).when(service).getAllUsers();
UserListWrapper usersWrapper = userRoleListService.getUsers();
assertTrue(usersWrapper.getUsers().size() == 3);
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryBase method initialize.
public void initialize(boolean multiByteEncoding) throws Exception {
loginAsRepositoryAdmin();
SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
mp = new MicroPlatform(getSolutionPath());
// used by DefaultPentahoJackrabbitAccessControlHelper
mp.defineInstance("tenantedUserNameUtils", userNameUtils);
mp.defineInstance("tenantedRoleNameUtils", roleNameUtils);
mp.defineInstance("ILockHelper", new DefaultLockHelper(userNameUtils));
mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
mp.defineInstance(ITenantManager.class, tenantManager);
mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(this.jcrTemplate, this.repositoryFileDao));
mp.defineInstance("ITenantedPrincipleNameResolver", new DefaultTenantedPrincipleNameResolver());
mp.defineInstance("useMultiByteEncoding", multiByteEncoding);
mp.defineInstance(IUnifiedRepository.class, repo);
mp.defineInstance(IRepositoryFileAclDao.class, repositoryFileAclDao);
IUserRoleListService userRoleListService = mock(IUserRoleListService.class);
when(userRoleListService.getRolesForUser(any(ITenant.class), anyString())).thenReturn(Arrays.asList(tenantAdminRoleName, AUTHENTICATED_ROLE_NAME));
mp.defineInstance(IUserRoleListService.class, userRoleListService);
mp.defineInstance("singleTenantAdminUserName", singleTenantAdminUserName);
mp.defineInstance("singleTenantAdminAuthorityName", tenantAdminRoleName);
// Start the micro-platform
mp.start();
loginAsRepositoryAdmin();
setAclManagement();
systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(systemTenant, sysAdminUserName, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class SecurityHelperTest method runAsSystemTest.
@Test
@SuppressWarnings("unchecked")
public void runAsSystemTest() throws Exception {
// creating environment
PentahoSystemBoot boot = new PentahoSystemBoot();
boot.setFilePath("test-src/solution");
IPentahoObjectFactory pentahoObjectFactory = mock(IPentahoObjectFactory.class, PENTAHO_OBJECT_FACTORY_MOCK_NAME);
when(pentahoObjectFactory.objectDefined(eq(SINGLE_TENANT_ADMIN_USER_NAME))).thenReturn(true);
when(pentahoObjectFactory.get(eq(String.class), eq(SINGLE_TENANT_ADMIN_USER_NAME), Matchers.<IPentahoSession>any())).thenReturn(ADMIN_USER_NAME);
when(pentahoObjectFactory.getName()).thenReturn(PENTAHO_OBJECT_FACTORY_MOCK_NAME);
boot.setFactory(pentahoObjectFactory);
IUserRoleListService mockUserRoleListService = getUserRoleListServiceMock(ADMIN_USER_NAME, ADMIN_ROLES_ARRAY);
doReturn(mockUserRoleListService).when(emptySecurityHelper).getUserRoleListService();
// test for call
Callable<String> callable = (Callable<String>) mock(Callable.class);
when(callable.call()).thenReturn(CALLABLE_RETURNED_VALUE_OK);
String runningResult = emptySecurityHelper.runAsSystem(callable);
assertEquals(CALLABLE_RETURNED_VALUE_OK, runningResult);
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class SecurityHelperTest method getUserRoleListServiceMock.
private IUserRoleListService getUserRoleListServiceMock(String userName, String[] roles) {
IUserRoleListService mockUserRoleListService = mock(IUserRoleListService.class);
List<String> noRoles = new ArrayList<String>();
List<String> allRoles = new ArrayList<String>(Arrays.asList(roles));
when(mockUserRoleListService.getRolesForUser(Matchers.<ITenant>any(), eq(userName))).thenReturn(allRoles);
when(mockUserRoleListService.getRolesForUser(Matchers.<ITenant>any(), AdditionalMatchers.not(eq(userName)))).thenReturn(noRoles);
return mockUserRoleListService;
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class SecurityHelperTest method testWithSharedSecurityContext.
@Test
public /**
* Verification for BISERVER-12365 where a Threads are sharing a SecurityContext and making concurrent calls to
* runAsSytem() and runAsUser()
*/
void testWithSharedSecurityContext() throws InterruptedException {
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");
final SecurityContext context = new SecurityContextImpl();
SecurityContextHolder.setContext(context);
SecurityContextHolder.getContext().setAuthentication(token);
final CountDownLatch startSignal = new CountDownLatch(1);
final CountDownLatch doneSignal = new CountDownLatch(1);
final Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
SecurityContextHolder.setContext(context);
SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {
@Override
public Void call() throws Exception {
System.out.println("Starting Thread 2");
startSignal.await();
// waiting for t1 to finish
doneSignal.await();
System.out.println("Finishing Thread 2");
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
});
final Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
SecurityContextHolder.setContext(context);
SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {
@Override
public Void call() throws Exception {
System.out.println("Starting Thread 1");
startSignal.await();
System.out.println("Finishing Thread 1");
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
});
t1.start();
t2.start();
// let all threads proceed
startSignal.countDown();
// waits for t1 to die
t1.join();
// t2 is waiting for t1 to finish, let t2 proceed
doneSignal.countDown();
// waits for t2 to die
t2.join();
assertSame(token.getPrincipal(), SecurityContextHolder.getContext().getAuthentication().getPrincipal());
}
Aggregations