use of org.pentaho.platform.security.userroledao.PentahoUser in project pentaho-platform by pentaho.
the class AbstractJcrBackedUserRoleDao method convertToPentahoUser.
@VisibleForTesting
IPentahoUser convertToPentahoUser(User jackrabbitUser) throws RepositoryException {
if (getUserCache().containsKey(jackrabbitUser.getID())) {
return (IPentahoUser) getUserCache().get(jackrabbitUser.getID());
}
IPentahoUser pentahoUser = null;
Value[] propertyValues = null;
String description = null;
try {
// $NON-NLS-1$
propertyValues = jackrabbitUser.getProperty("description");
description = propertyValues.length > 0 ? propertyValues[0].getString() : null;
} catch (Exception ex) {
// CHECKSTYLES IGNORE
}
Credentials credentials = jackrabbitUser.getCredentials();
String password = null;
if (credentials instanceof CryptedSimpleCredentials) {
password = new String(((CryptedSimpleCredentials) credentials).getPassword());
}
pentahoUser = new PentahoUser(getTenantedUserNameUtils().getTenant(jackrabbitUser.getID()), getTenantedUserNameUtils().getPrincipleName(jackrabbitUser.getID()), password, description, !jackrabbitUser.isDisabled());
if (isUseJackrabbitUserCache()) {
getUserCache().put(jackrabbitUser.getID(), pentahoUser);
}
return pentahoUser;
}
use of org.pentaho.platform.security.userroledao.PentahoUser in project pentaho-platform by pentaho.
the class AbstractJcrBackedUserRoleDao method getUsers.
public List<IPentahoUser> getUsers(Session session, ITenant theTenant, boolean includeSubtenants) throws RepositoryException {
ArrayList<IPentahoUser> users = new ArrayList<IPentahoUser>();
if (theTenant == null || theTenant.getId() == null) {
theTenant = JcrTenantUtils.getTenant();
}
if (TenantUtils.isAccessibleTenant(theTenant)) {
UserManager userMgr = getUserManager(theTenant, session);
pPrincipalName = getJcrName(session);
Iterator<Authorizable> it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_USER);
while (it.hasNext()) {
User user = (User) it.next();
IPentahoUser pentahoUser = convertToPentahoUser(user);
if (includeSubtenants) {
users.add(pentahoUser);
} else {
if (pentahoUser.getTenant() != null && pentahoUser.getTenant().equals(theTenant)) {
users.add(pentahoUser);
}
}
}
}
return users;
}
use of org.pentaho.platform.security.userroledao.PentahoUser in project pentaho-platform by pentaho.
the class ProxyPentahoUserRoleHelper method syncUsers.
/**
* Synchronizes <code>user</code> with fields from <code>proxyUser</code>. The roles set of given
* <code>user</code> is unmodified.
*/
public static IPentahoUser syncUsers(IPentahoUser user, ProxyPentahoUser proxyUser) {
IPentahoUser syncedUser = user;
if (syncedUser == null) {
syncedUser = new PentahoUser(proxyUser.getName());
}
syncedUser.setDescription(proxyUser.getDescription());
// password is not changed. If the user enters a value, set the password.
if (!StringUtils.isBlank(proxyUser.getPassword())) {
PasswordEncoder encoder = // $NON-NLS-1$
PentahoSystem.get(PasswordEncoder.class, "passwordEncoder", PentahoSessionHolder.getSession());
syncedUser.setPassword(encoder.encodePassword(proxyUser.getPassword(), null));
}
syncedUser.setEnabled(proxyUser.getEnabled());
return syncedUser;
}
use of org.pentaho.platform.security.userroledao.PentahoUser 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.security.userroledao.PentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoIT 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
}
}
Aggregations