use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class PatchPermissionModel_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.view.VXPortalUser in project ranger by apache.
the class PatchGrantAuditPermissionToKeyRoleUser_J10014 method assignAuditAndUserGroupPermissionToKeyAdminRoleUser.
private void assignAuditAndUserGroupPermissionToKeyAdminRoleUser() {
try {
int countUserPermissionUpdated = 0;
XXModuleDef xAuditModDef = daoManager.getXXModuleDef().findByModuleName(RangerConstants.MODULE_AUDIT);
XXModuleDef xUserGrpModDef = daoManager.getXXModuleDef().findByModuleName(RangerConstants.MODULE_USER_GROUPS);
logger.warn("Audit Module Object : " + xAuditModDef);
logger.warn("USer Group Module Object : " + xUserGrpModDef);
if (xAuditModDef == null && xUserGrpModDef == null) {
logger.warn("Audit Module and User Group module not found");
return;
}
List<XXPortalUser> allKeyAdminUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_KEY_ADMIN);
if (!CollectionUtils.isEmpty(allKeyAdminUsers)) {
for (XXPortalUser xPortalUser : allKeyAdminUsers) {
boolean isUserUpdated = false;
VXPortalUser vPortalUser = xPortalUserService.populateViewBean(xPortalUser);
if (vPortalUser != null) {
vPortalUser.setUserRoleList(daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(vPortalUser.getId()));
if (xAuditModDef != null) {
xUserMgr.createOrUpdateUserPermisson(vPortalUser, xAuditModDef.getId(), true);
isUserUpdated = true;
logger.info("Added '" + xAuditModDef.getModule() + "' permission to user '" + xPortalUser.getLoginId() + "'");
}
if (xUserGrpModDef != null) {
xUserMgr.createOrUpdateUserPermisson(vPortalUser, xUserGrpModDef.getId(), true);
isUserUpdated = true;
logger.info("Added '" + xUserGrpModDef.getModule() + "' permission to user '" + xPortalUser.getLoginId() + "'");
}
if (isUserUpdated) {
countUserPermissionUpdated += 1;
}
}
}
logger.info(countUserPermissionUpdated + " permissions were assigned");
} else {
logger.info("There are no user with Key Admin role");
}
} catch (Exception ex) {
logger.error("Error while granting Audit and User group permission ", ex);
}
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class ServiceDBStore method validateUserAndProvideTabTagBasedPolicyPermission.
private void validateUserAndProvideTabTagBasedPolicyPermission(String username) {
XXPortalUser xxPortalUser = daoMgr.getXXPortalUser().findByLoginId(username);
if (xxPortalUser == null) {
throw restErrorUtil.createRESTException("Username : " + username + " does not exist. Please provide valid user as service admin for tag service .", MessageEnums.ERROR_CREATING_OBJECT);
} else {
VXPortalUser vXPortalUser = userMgr.mapXXPortalUserToVXPortalUserForDefaultAccount(xxPortalUser);
if (CollectionUtils.isNotEmpty(vXPortalUser.getUserRoleList()) && vXPortalUser.getUserRoleList().size() == 1) {
for (String userRole : vXPortalUser.getUserRoleList()) {
if (userRole.equals(RangerConstants.ROLE_USER)) {
HashMap<String, Long> moduleNameId = xUserMgr.getAllModuleNameAndIdMap();
xUserMgr.createOrUpdateUserPermisson(vXPortalUser, moduleNameId.get(RangerConstants.MODULE_TAG_BASED_POLICIES), true);
}
}
}
}
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class UserMgr method mapXXPortalUserToVXPortalUserForDefaultAccount.
protected VXPortalUser mapXXPortalUserToVXPortalUserForDefaultAccount(XXPortalUser user) {
VXPortalUser userProfile = new VXPortalUser();
userProfile.setLoginId(user.getLoginId());
userProfile.setEmailAddress(user.getEmailAddress());
userProfile.setStatus(user.getStatus());
userProfile.setUserRoleList(new ArrayList<String>());
userProfile.setId(user.getId());
userProfile.setFirstName(user.getFirstName());
userProfile.setLastName(user.getLastName());
userProfile.setPublicScreenName(user.getPublicScreenName());
userProfile.setOtherAttributes(user.getOtherAttributes());
userProfile.setSyncSource(user.getSyncSource());
List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
for (XXPortalUserRole gjUserRole : gjUserRoleList) {
userProfile.getUserRoleList().add(gjUserRole.getUserRole());
}
return userProfile;
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class UserMgr method searchUsers.
/**
* @param searchCriteria
* @return
*/
public VXPortalUserList searchUsers(SearchCriteria searchCriteria) {
VXPortalUserList returnList = new VXPortalUserList();
ArrayList<VXPortalUser> objectList = new ArrayList<VXPortalUser>();
String queryStr = "SELECT u FROM XXPortalUser u ";
String countQueryStr = "SELECT COUNT(u) FROM XXPortalUser u ";
// Get total count first
Query query = createUserSearchQuery(countQueryStr, null, searchCriteria);
Long count = (Long) query.getSingleResult();
int resultSize = count != null ? count.intValue() : 0;
if (resultSize == 0) {
return returnList;
}
// Get actual data
// Add sort by
String sortBy = searchCriteria.getSortBy();
String querySortBy = "u.loginId";
if (sortBy != null && !sortBy.trim().isEmpty()) {
sortBy = sortBy.trim();
if (sortBy.equalsIgnoreCase("userId")) {
querySortBy = "u.id";
} else if (sortBy.equalsIgnoreCase("loginId")) {
querySortBy = "ua.loginId";
} else if (sortBy.equalsIgnoreCase("emailAddress")) {
querySortBy = "u.emailAddress";
} else if (sortBy.equalsIgnoreCase("firstName")) {
querySortBy = "u.firstName";
} else if (sortBy.equalsIgnoreCase("lastName")) {
querySortBy = "u.lastName";
} else {
sortBy = "loginId";
logger.error("Invalid sortBy provided. sortBy=" + sortBy);
}
} else {
sortBy = "loginId";
}
// Default sort field
String sortClause = " order by " + querySortBy + " ";
// Add sort type
String sortType = searchCriteria.getSortType();
String querySortType = "asc";
if (sortType != null) {
if (sortType.equalsIgnoreCase("asc") || sortType.equalsIgnoreCase("desc")) {
querySortType = sortType;
} else {
logger.error("Invalid sortType. sortType=" + sortType);
}
}
sortClause += querySortType;
query = createUserSearchQuery(queryStr, sortClause, searchCriteria);
// Set start index
query.setFirstResult(searchCriteria.getStartIndex());
searchUtil.updateQueryPageSize(query, searchCriteria);
@SuppressWarnings("rawtypes") List resultList = query.getResultList();
// Iterate over the result list and create the return list
for (Object object : resultList) {
XXPortalUser gjUser = (XXPortalUser) object;
VXPortalUser userProfile = new VXPortalUser();
gjUserToUserProfile(gjUser, userProfile);
objectList.add(userProfile);
}
returnList.setResultSize(resultSize);
returnList.setPageSize(query.getMaxResults());
returnList.setSortBy(sortBy);
returnList.setSortType(querySortType);
returnList.setStartIndex(query.getFirstResult());
returnList.setTotalCount(count.longValue());
returnList.setVXPortalUsers(objectList);
return returnList;
}
Aggregations