use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class MockUserRoleDao method getUser.
public IPentahoUser getUser(ITenant tenant, String userName) throws UncategorizedUserRoleDaoException {
if (tenant == null) {
tenant = getTenant(userName, true);
userName = getPrincipalName(userName, true);
}
if (tenant == null || tenant.getId() == null) {
tenant = getCurrentTenant();
}
HashSet<IPentahoUser> users = tenantUsers.get(tenant);
if (users != null) {
for (IPentahoUser user : users) {
if (user.getUsername().equals(userName)) {
return user;
}
}
}
return null;
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class MockUserRoleDao method setRoleMembers.
public void setRoleMembers(ITenant tenant, String roleName, String[] userNames) throws NotFoundException, UncategorizedUserRoleDaoException {
if (tenant == null) {
tenant = getTenant(roleName, false);
roleName = getPrincipalName(roleName, false);
}
if (tenant == null || tenant.getId() == null) {
tenant = getCurrentTenant();
}
IPentahoRole role = getRole(tenant, roleName);
HashSet<IPentahoUser> users = roleMembers.get(role);
users.clear();
if (userNames != null) {
for (String userName : userNames) {
IPentahoUser user = getUser(tenant, userName);
if (!userRoles.containsKey(user)) {
userRoles.put(user, new HashSet<IPentahoRole>());
}
userRoles.get(user).add(role);
if (user != null) {
users.add(user);
}
}
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT method testDeleteUser.
@Test
public void testDeleteUser() throws Exception {
int DEFAULT_TENANT_USER = 1;
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 });
IPentahoUser pentahoUser = userRoleDaoProxy.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null);
pentahoUser = userRoleDaoProxy.getUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
assertNotNull(pentahoUser);
logout();
login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
try {
userRoleDaoProxy.deleteUser(pentahoUser);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
pentahoUser = userRoleDaoProxy.getUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
assertNull(pentahoUser);
assertEquals(DEFAULT_TENANT_USER, userRoleDaoProxy.getUsers(mainTenant_1).size());
pentahoUser = userRoleDaoProxy.createUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), PASSWORD_6, USER_DESCRIPTION_6, null);
pentahoUser = userRoleDaoProxy.getUser(mainTenant_1, USER_6);
assertNotNull(pentahoUser);
userRoleDaoProxy.deleteUser(pentahoUser);
assertNull(userRoleDaoProxy.getUser(null, USER_6 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath()));
try {
userRoleDaoProxy.deleteUser(pentahoUser);
fail("Exception not thrown");
} catch (NotFoundException e) {
// Expected exception
}
try {
pentahoUser = new PentahoUser(null, USER_6, PASSWORD_6, USER_DESCRIPTION_6, true);
userRoleDaoProxy.deleteUser(pentahoUser);
fail("Exception not thrown");
} catch (Exception ex) {
// Expected exception
}
try {
pentahoUser = new PentahoUser(mainTenant_1, null, PASSWORD_6, USER_DESCRIPTION_6, true);
userRoleDaoProxy.deleteUser(pentahoUser);
fail("Exception not thrown");
} catch (NotFoundException e) {
// Expected exception
}
try {
pentahoUser = new PentahoUser(mainTenant_1, UNKNOWN_USER, PASSWORD_6, USER_DESCRIPTION_6, true);
userRoleDaoProxy.deleteUser(pentahoUser);
fail("Exception not thrown");
} catch (NotFoundException e) {
// Expected exception
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT method testGetUsers.
@Test
public void testGetUsers() throws Exception {
int DEFAULT_USER_COUNT = 1;
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.createUser(mainTenant_1, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_8, PASSWORD_8, USER_DESCRIPTION_8, null);
List<IPentahoUser> users = userRoleDaoProxy.getUsers(mainTenant_1);
assertEquals(2 + DEFAULT_USER_COUNT, users.size());
for (IPentahoUser user : users) {
if (user.getUsername().equals(USER_1)) {
assertEquals(user.getTenant(), mainTenant_1);
assertEquals(user.isEnabled(), true);
} else if (user.getUsername().equals(USER_7)) {
assertEquals(user.getTenant(), mainTenant_1);
assertEquals(user.getDescription(), USER_DESCRIPTION_7);
assertEquals(user.isEnabled(), true);
} else if (user.getUsername().equals(USER_8)) {
assertEquals(user.getTenant(), mainTenant_1);
assertEquals(user.getDescription(), USER_DESCRIPTION_8);
assertEquals(user.isEnabled(), true);
} else {
fail("Invalid user name");
}
}
try {
users = userRoleDaoProxy.getUsers(UNKNOWN_TENANT);
fail("Exception not thrown");
} catch (Throwable th) {
assertNotNull(th);
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoEncodeIT method testRoleWithMembers.
@Test
public void testRoleWithMembers() 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 });
login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, new String[] { ROLE_1 });
userRoleDaoProxy.createUser(mainTenant_1, USER_3, PASSWORD_3, USER_DESCRIPTION_3, new String[] { ROLE_1, ROLE_2 });
List<IPentahoUser> users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_2);
assertEquals(1, users.size());
assertEquals(USER_3, users.get(0).getUsername());
ArrayList<String> expectedUserNames = new ArrayList<String>();
expectedUserNames.add(USER_2);
expectedUserNames.add(USER_3);
ArrayList<String> actualUserNames = new ArrayList<String>();
String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
users = userRoleDaoProxy.getRoleMembers(null, ROLE_1 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
for (IPentahoUser user : users) {
actualUserNames.add(user.getUsername());
}
assertEquals(2, actualUserNames.size());
assertTrue(actualUserNames.containsAll(expectedUserNames));
users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_3);
assertEquals(0, users.size());
userRoleDaoProxy.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null);
userRoleDaoProxy.createUser(mainTenant_1, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
userRoleDaoProxy.createRole(mainTenant_1, ROLE_5, ROLE_DESCRIPTION_6, new String[] { USER_5 });
userRoleDaoProxy.createRole(mainTenant_1, ROLE_6, ROLE_DESCRIPTION_7, new String[] { USER_5, USER_6 });
ArrayList<String> expectedRoleNames = new ArrayList<String>();
expectedRoleNames.add(ROLE_6);
expectedRoleNames.add(authenticatedRoleName);
ArrayList<String> actualRoleNames = new ArrayList<String>();
List<IPentahoRole> roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_6);
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(2, roles.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
expectedRoleNames = new ArrayList<String>();
expectedRoleNames.add(ROLE_5);
expectedRoleNames.add(ROLE_6);
expectedRoleNames.add(authenticatedRoleName);
actualRoleNames = new ArrayList<String>();
roles = userRoleDaoProxy.getUserRoles(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(3, actualRoleNames.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_7);
assertEquals(1, roles.size());
assertEquals(authenticatedRoleName, roles.get(0).getName());
userRoleDaoProxy.setUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), new String[] { ROLE_5, ROLE_6 });
roles = userRoleDaoProxy.getUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath());
actualRoleNames.clear();
for (IPentahoRole role : roles) {
actualRoleNames.add(role.getName());
}
assertEquals(3, actualRoleNames.size());
assertTrue(actualRoleNames.containsAll(expectedRoleNames));
expectedUserNames = new ArrayList<String>();
expectedUserNames.add(USER_1);
expectedUserNames.add(USER_2);
expectedRoleNames.add(authenticatedRoleName);
userRoleDaoProxy.setRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), new String[] { USER_1, USER_2 });
users = userRoleDaoProxy.getRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
actualUserNames.clear();
for (IPentahoUser user : users) {
actualUserNames.add(user.getUsername());
}
assertEquals(2, actualUserNames.size());
assertTrue(actualUserNames.containsAll(expectedUserNames));
}
Aggregations