use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testGetRolesForUser.
@Test
public void testGetRolesForUser() throws Exception {
String user = "admin";
RoleListWrapper roleListWrapper = new RoleListWrapper(new ArrayList<IPentahoRole>());
when(userRoleService.getRolesForUser(user)).thenReturn(roleListWrapper);
assertEquals(roleListWrapper, userRoleResource.getRolesForUser(user));
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testGetRolesForUserError.
@Test
public void testGetRolesForUserError() throws Exception {
String user = "admin";
RoleListWrapper roleListWrapper = new RoleListWrapper(new ArrayList<IPentahoRole>());
when(userRoleService.getRolesForUser(user)).thenReturn(roleListWrapper);
assertEquals(roleListWrapper, userRoleResource.getRolesForUser(user));
try {
when(userRoleService.getRolesForUser(user)).thenThrow(new UncategorizedUserRoleDaoException("testException"));
} catch (WebApplicationException e) {
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus());
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoResource_RolesUpdatedTest method setUp.
@Before
public void setUp() {
UserRoleDaoService service = mock(UserRoleDaoService.class);
doReturn(new RoleListWrapper(allRoles)).when(service).getRolesForUser(eq(SESSION_USER_NAME));
resource = new UserRoleDaoResource(mock(IRoleAuthorizationPolicyRoleBindingDao.class), mock(ITenantManager.class), new ArrayList<String>(), ROLE_NAME_ADMINISTRATOR, service);
session = new StandaloneSession(SESSION_USER_NAME);
resource = spy(resource);
doReturn(session).when(resource).getSession();
userRoleDao = mock(IUserRoleDao.class);
doReturn(new ArrayList<IPentahoRole>()).when(userRoleDao).getRoles(any(ITenant.class));
doReturn(mock(ITenant.class)).when(resource).getTenant(anyString());
doReturn(userRoleDao).when(resource).getUserRoleDao();
doReturn(true).when(resource).canAdminister();
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT method testGetRoles.
@Test
public void testGetRoles() throws Exception {
int DEFAULT_ROLE_COUNT = 3;
loginAsRepositoryAdmin();
systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_7, ROLE_DESCRIPTION_7, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_8, ROLE_DESCRIPTION_8, null);
List<IPentahoRole> roles = userRoleDaoProxy.getRoles(mainTenant_1);
assertEquals(2 + DEFAULT_ROLE_COUNT, roles.size());
for (IPentahoRole user : roles) {
if (user.getName().equals(ROLE_7)) {
assertEquals(user.getTenant(), mainTenant_1);
assertEquals(user.getDescription(), ROLE_DESCRIPTION_7);
} else if (user.getName().equals(ROLE_8)) {
assertEquals(user.getTenant(), mainTenant_1);
assertEquals(user.getDescription(), ROLE_DESCRIPTION_8);
}
}
try {
roles = userRoleDaoProxy.getRoles(UNKNOWN_TENANT);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT method testCreateRole.
@Test
public void testCreateRole() throws Exception {
loginAsRepositoryAdmin();
systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
subTenant1_1 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant1_1, "admin", "password", "", new String[] { adminRoleName });
subTenant1_2 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant1_2, "admin", "password", "", new String[] { adminRoleName });
subTenant2_1 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_1, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant2_1, "admin", "password", "", new String[] { adminRoleName });
subTenant2_2 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_2, adminRoleName, authenticatedRoleName, "Anonymous");
userRoleDaoProxy.createUser(subTenant2_2, "admin", "password", "", new String[] { adminRoleName });
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
IPentahoRole pentahoRole;
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_1);
assertEquals(pentahoRole.getTenant(), mainTenant_1);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
int DEFAULT_ROLE_COUNT = 3;
List<IPentahoRole> roles = userRoleDaoProxy.getRoles(mainTenant_1);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_1) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), mainTenant_1);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
logout();
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
try {
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
pentahoRole = userRoleDaoProxy.createRole(mainTenant_2, ROLE_1, ROLE_DESCRIPTION_2, null);
pentahoRole = userRoleDaoProxy.getRole(mainTenant_2, ROLE_1);
assertEquals(pentahoRole.getTenant(), mainTenant_2);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_2);
roles = userRoleDaoProxy.getRoles(mainTenant_2);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_1) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), mainTenant_2);
assertEquals(pentahoRole.getName(), ROLE_1);
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_2);
logout();
login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
try {
pentahoRole = userRoleDaoProxy.createRole(mainTenant_2, ROLE_1, ROLE_DESCRIPTION_1, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
userRoleDaoProxy.createRole(null, ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_3, null);
pentahoRole = userRoleDaoProxy.getRole(null, ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getTenant(), subTenant2_1);
assertEquals(pentahoRole.getName(), ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_3);
roles = userRoleDaoProxy.getRoles(subTenant2_1);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath()) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), subTenant2_1);
assertEquals(pentahoRole.getName(), ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_3);
logout();
login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
try {
pentahoRole = userRoleDaoProxy.createRole(subTenant2_1, ROLE_3, ROLE_DESCRIPTION_3, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
pentahoRole = userRoleDaoProxy.createRole(null, ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_4, null);
pentahoRole = userRoleDaoProxy.getRole(null, ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getTenant(), subTenant1_1);
assertEquals(pentahoRole.getName(), ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_4);
roles = userRoleDaoProxy.getRoles(subTenant1_1);
assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
for (IPentahoRole role : roles) {
if (role.getName() == ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath()) {
pentahoRole = role;
}
}
assertEquals(pentahoRole.getTenant(), subTenant1_1);
assertEquals(pentahoRole.getName(), ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_4);
logout();
login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
try {
pentahoRole = userRoleDaoProxy.createRole(subTenant1_1, ROLE_3, ROLE_DESCRIPTION_3, null);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
try {
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
fail("Exception not thrown");
} catch (AlreadyExistsException e) {
// Expected exception
}
logout();
}
Aggregations