use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class AbstractBaseResourceService method mapBaseAttributesToViewBean.
protected void mapBaseAttributesToViewBean(T resource, V viewBean) {
viewBean.setId(resource.getId());
// TBD: Need to review this change later
viewBean.setMObj(resource);
viewBean.setCreateDate(resource.getCreateTime());
viewBean.setUpdateDate(resource.getUpdateTime());
Long ownerId = resource.getAddedByUserId();
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
if (currentUserSession == null) {
return;
}
if (ownerId != null) {
XXPortalUser tUser = daoManager.getXXPortalUser().getById(resource.getAddedByUserId());
if (tUser != null) {
if (tUser.getPublicScreenName() != null && !tUser.getPublicScreenName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getPublicScreenName().trim())) {
viewBean.setOwner(tUser.getPublicScreenName());
} else {
if (tUser.getFirstName() != null && !tUser.getFirstName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getFirstName().trim())) {
if (tUser.getLastName() != null && !tUser.getLastName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getLastName().trim())) {
viewBean.setOwner(tUser.getFirstName() + " " + tUser.getLastName());
} else {
viewBean.setOwner(tUser.getFirstName());
}
} else {
viewBean.setOwner(tUser.getLoginId());
}
}
}
}
if (resource.getUpdatedByUserId() != null) {
XXPortalUser tUser = daoManager.getXXPortalUser().getById(resource.getUpdatedByUserId());
if (tUser != null) {
if (tUser.getPublicScreenName() != null && !tUser.getPublicScreenName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getPublicScreenName().trim())) {
viewBean.setUpdatedBy(tUser.getPublicScreenName());
} else {
if (tUser.getFirstName() != null && !tUser.getFirstName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getFirstName().trim())) {
if (tUser.getLastName() != null && !tUser.getLastName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getLastName().trim())) {
viewBean.setUpdatedBy(tUser.getFirstName() + " " + tUser.getLastName());
} else {
viewBean.setUpdatedBy(tUser.getFirstName());
}
} else {
viewBean.setUpdatedBy(tUser.getLoginId());
}
}
}
}
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class PatchMigration_J10002 method mapXAssetToService.
private RangerService mapXAssetToService(RangerService service, XXAsset xAsset) throws Exception {
String type = "";
String name = xAsset.getName();
String description = xAsset.getDescription();
Map<String, String> configs = null;
int typeInt = xAsset.getAssetType();
XXServiceDef serviceDef = daoMgr.getXXServiceDef().findByName(AppConstants.getLabelFor_AssetType(typeInt).toLowerCase());
if (serviceDef == null) {
throw new Exception("No ServiceDefinition found for repository: " + name);
}
type = serviceDef.getName();
configs = jsonUtil.jsonToMap(xAsset.getConfig());
List<XXServiceConfigDef> mandatoryConfigs = daoMgr.getXXServiceConfigDef().findByServiceDefName(type);
for (XXServiceConfigDef serviceConf : mandatoryConfigs) {
if (serviceConf.getIsMandatory()) {
if (!stringUtil.isEmpty(configs.get(serviceConf.getName()))) {
continue;
}
String dataType = serviceConf.getType();
String defaultValue = serviceConf.getDefaultvalue();
if (stringUtil.isEmpty(defaultValue)) {
defaultValue = getDefaultValueForDataType(dataType);
}
configs.put(serviceConf.getName(), defaultValue);
}
}
service.setType(type);
service.setName(name);
service.setDescription(description);
service.setConfigs(configs);
service.setCreateTime(xAsset.getCreateTime());
service.setUpdateTime(xAsset.getUpdateTime());
XXPortalUser createdByUser = daoMgr.getXXPortalUser().getById(xAsset.getAddedByUserId());
XXPortalUser updByUser = daoMgr.getXXPortalUser().getById(xAsset.getUpdatedByUserId());
if (createdByUser != null) {
service.setCreatedBy(createdByUser.getLoginId());
}
if (updByUser != null) {
service.setUpdatedBy(updByUser.getLoginId());
}
service.setId(xAsset.getId());
return service;
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class PatchPersmissionModel_J10003 method assignPermissionToExistingUsers.
public void assignPermissionToExistingUsers() {
int countUserPermissionUpdated = 0;
Long userCount = daoManager.getXXPortalUser().getAllCount();
List<XXPortalUser> xXPortalUsers = null;
Long patchModeMaxLimit = Long.valueOf(500L);
try {
if (userCount != null && userCount > 0) {
List<String> loginIdList = readUserNamesFromFile(usersListFileName);
if (!CollectionUtils.isEmpty(loginIdList)) {
xXPortalUsers = new ArrayList<XXPortalUser>();
XXPortalUser xXPortalUser = null;
for (String loginId : loginIdList) {
try {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(loginId);
if (xXPortalUser != null) {
xXPortalUsers.add(xXPortalUser);
} else {
logger.info("User " + loginId + " doesn't exist!");
}
} catch (Exception ex) {
}
}
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to " + countUserPermissionUpdated + " of " + loginIdList.size());
} else if (userCount.compareTo(Long.valueOf(patchModeMaxLimit)) < 0 || grantAllUsers) {
xXPortalUsers = daoManager.getXXPortalUser().findAllXPortalUser();
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to " + countUserPermissionUpdated + " of " + xXPortalUsers.size());
}
} else {
// if total no. of users are more than 500 then process ADMIN and KEY_ADMIN users only to avoid timeout
xXPortalUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_SYS_ADMIN);
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to users having role:" + RangerConstants.ROLE_SYS_ADMIN + ". Processed:" + countUserPermissionUpdated + " of total " + xXPortalUsers.size());
}
xXPortalUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_KEY_ADMIN);
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to users having role:" + RangerConstants.ROLE_KEY_ADMIN + ". Processed:" + countUserPermissionUpdated + " of total " + xXPortalUsers.size());
}
logger.info("Please execute this patch separately with argument 'ALL' to assign permission to remaining users ");
System.out.println("Please execute this patch separately with argument 'ALL' to assign module permissions to remaining users!!");
}
}
} catch (Exception ex) {
}
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class PatchPersmissionModel_J10003 method assignPermissions.
private int assignPermissions(List<XXPortalUser> xXPortalUsers) {
int countUserPermissionUpdated = 0;
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
for (XXPortalUser xPortalUser : xXPortalUsers) {
try {
if (xPortalUser != null) {
VXPortalUser vPortalUser = xPortalUserService.populateViewBean(xPortalUser);
if (vPortalUser != null) {
vPortalUser.setUserRoleList(daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(vPortalUser.getId()));
xUserMgr.assignPermissionToUser(vPortalUser, false);
countUserPermissionUpdated += 1;
logger.info("Permissions assigned/updated on base of User's Role, UserId [" + xPortalUser.getId() + "]");
}
}
} catch (Exception ex) {
}
}
}
return countUserPermissionUpdated;
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class ChangeUserNameUtil method updateUserName.
public void updateUserName() {
// if newUserName already exists
if (daoMgr.getXXPortalUser().findByLoginId(newUserName) != null) {
System.out.println("New user name already exist in DB!");
logger.error("New user name already exist in DB");
System.exit(1);
}
XXPortalUser xPortalUser = daoMgr.getXXPortalUser().findByLoginId(userLoginId);
if (xPortalUser != null) {
String dbPassword = xPortalUser.getPassword();
String currentEncryptedPassword = null;
try {
currentEncryptedPassword = userMgr.encrypt(userLoginId, currentPassword);
if (currentEncryptedPassword.equals(dbPassword)) {
userMgr.updateOldUserName(userLoginId, newUserName, currentPassword);
logger.info("User Name '" + userLoginId + "' updated to '" + newUserName + "' sucessfully.");
} else {
System.out.println("Invalid user password");
logger.error("Invalid user password");
System.exit(1);
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("User does not exist in DB!!");
logger.error("User does not exist in DB");
System.exit(1);
}
}
Aggregations