use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class PentahoPlatformExporter method exportUsersAndRoles.
protected void exportUsersAndRoles() {
log.debug("export users & roles");
IUserRoleListService userRoleListService = PentahoSystem.get(IUserRoleListService.class);
UserDetailsService userDetailsService = PentahoSystem.get(UserDetailsService.class);
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = PentahoSystem.get(IRoleAuthorizationPolicyRoleBindingDao.class);
ITenant tenant = TenantUtils.getCurrentTenant();
// get the user settings for this user
IUserSettingService service = getUserSettingService();
// User Export
List<String> userList = userRoleListService.getAllUsers(tenant);
for (String user : userList) {
UserExport userExport = new UserExport();
userExport.setUsername(user);
userExport.setPassword(userDetailsService.loadUserByUsername(user).getPassword());
for (String role : userRoleListService.getRolesForUser(tenant, user)) {
userExport.setRole(role);
}
if (service != null && service instanceof IAnyUserSettingService) {
IAnyUserSettingService userSettings = (IAnyUserSettingService) service;
List<IUserSetting> settings = userSettings.getUserSettings(user);
if (settings != null) {
for (IUserSetting setting : settings) {
userExport.addUserSetting(new ExportManifestUserSetting(setting));
}
}
}
this.getExportManifest().addUserExport(userExport);
}
// export the global user settings
if (service != null) {
List<IUserSetting> globalUserSettings = service.getGlobalUserSettings();
if (globalUserSettings != null) {
for (IUserSetting setting : globalUserSettings) {
getExportManifest().addGlobalUserSetting(new ExportManifestUserSetting(setting));
}
}
}
// RoleExport
List<String> roles = userRoleListService.getAllRoles();
for (String role : roles) {
RoleExport roleExport = new RoleExport();
roleExport.setRolename(role);
roleExport.setPermission(roleBindingDao.getRoleBindingStruct(null).bindingMap.get(role));
exportManifest.addRoleExport(roleExport);
}
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class SolutionImportHandler method importUsers.
/**
* Imports UserExport objects into the platform as users.
*
* @param users
* @return A map of role names to list of users in that role
*/
protected Map<String, List<String>> importUsers(List<UserExport> users) {
Map<String, List<String>> roleToUserMap = new HashMap<>();
IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class);
ITenant tenant = new Tenant("/pentaho/" + TenantUtils.getDefaultTenant(), true);
if (users != null && roleDao != null) {
for (UserExport user : users) {
String password = user.getPassword();
log.debug("Importing user: " + user.getUsername());
// map the user to the roles he/she is in
for (String role : user.getRoles()) {
List<String> userList;
if (!roleToUserMap.containsKey(role)) {
userList = new ArrayList<>();
roleToUserMap.put(role, userList);
} else {
userList = roleToUserMap.get(role);
}
userList.add(user.getUsername());
}
String[] userRoles = user.getRoles().toArray(new String[] {});
try {
roleDao.createUser(tenant, user.getUsername(), password, null, userRoles);
} catch (AlreadyExistsException e) {
// it's ok if the user already exists, it is probably a default user
log.info(Messages.getInstance().getString("USER.Already.Exists", user.getUsername()));
try {
if (isOverwriteFile()) {
// set the roles, maybe they changed
roleDao.setUserRoles(tenant, user.getUsername(), userRoles);
// set the password just in case it changed
roleDao.setPassword(tenant, user.getUsername(), password);
}
} catch (Exception ex) {
// couldn't set the roles or password either
log.debug("Failed to set roles or password for existing user on import", ex);
}
} catch (Exception e) {
log.error(Messages.getInstance().getString("ERROR.CreatingUser", user.getUsername()));
}
importUserSettings(user);
}
}
return roleToUserMap;
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class AbstractJcrBackedUserRoleDaoTest method testIsMyself.
@Test(expected = RepositoryException.class)
public void testIsMyself() throws NotFoundException, RepositoryException {
Session jcrSession = mock(Session.class);
ITenant tenant = mock(ITenant.class);
String[] newRoles = { "first_role" };
setUserName("user-mock");
roleDao.setUserRoles(jcrSession, tenant, "user-mock", newRoles);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class MockUserRoleDao method getUsers.
public List<IPentahoUser> getUsers(ITenant tenant, boolean includeSubTenants) throws UncategorizedUserRoleDaoException {
ArrayList<IPentahoUser> users = new ArrayList<IPentahoUser>();
users.addAll(getUsers(tenant));
if (includeSubTenants) {
for (ITenant tmpTenant : tenants) {
if (tmpTenant.getRootFolderAbsolutePath().startsWith(tenant.getRootFolderAbsolutePath() + "/", 0)) {
users.addAll(getUsers(tmpTenant));
}
}
}
return users;
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class MockUserRoleDao method getRoles.
public List<IPentahoRole> getRoles(ITenant tenant, boolean includeSubTenants) throws UncategorizedUserRoleDaoException {
ArrayList<IPentahoRole> roles = new ArrayList<IPentahoRole>();
roles.addAll(getRoles(tenant));
if (includeSubTenants) {
for (ITenant tmpTenant : tenants) {
if (tmpTenant.getRootFolderAbsolutePath().startsWith(tenant.getRootFolderAbsolutePath() + "/", 0)) {
roles.addAll(getRoles(tmpTenant));
}
}
}
return roles;
}
Aggregations