use of org.apache.ranger.entity.XXUser in project ranger by apache.
the class XUserMgr method modifyUserActiveStatus.
public void modifyUserActiveStatus(HashMap<Long, Integer> statusMap) {
checkAdminAccess();
UserSessionBase session = ContextUtil.getCurrentUserSession();
String currentUser = null;
if (session != null) {
currentUser = session.getLoginId();
if (currentUser == null || currentUser.trim().isEmpty()) {
currentUser = null;
}
}
if (currentUser == null) {
return;
}
Set<Map.Entry<Long, Integer>> entries = statusMap.entrySet();
for (Map.Entry<Long, Integer> entry : entries) {
if (entry != null && entry.getKey() != null && entry.getValue() != null) {
XXUser xUser = daoManager.getXXUser().getById(entry.getKey());
if (xUser != null) {
VXPortalUser vXPortalUser = userMgr.getUserProfileByLoginId(xUser.getName());
if (vXPortalUser != null) {
if (vXPortalUser.getLoginId() != null && !vXPortalUser.getLoginId().equalsIgnoreCase(currentUser)) {
vXPortalUser.setStatus(entry.getValue());
userMgr.updateUser(vXPortalUser);
}
}
}
}
}
}
use of org.apache.ranger.entity.XXUser in project ranger by apache.
the class XUserMgr method createServiceConfigUser.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public VXUser createServiceConfigUser(String userName) {
if (userName == null || "null".equalsIgnoreCase(userName) || userName.trim().isEmpty()) {
logger.error("User Name: " + userName);
throw restErrorUtil.createRESTException("Please provide a valid username.", MessageEnums.INVALID_INPUT_DATA);
}
VXUser vXUser = null;
VXPortalUser vXPortalUser = null;
XXUser xxUser = daoManager.getXXUser().findByUserName(userName);
XXPortalUser xXPortalUser = daoManager.getXXPortalUser().findByLoginId(userName);
String actualPassword = "";
if (xxUser != null) {
vXUser = xUserService.populateViewBean(xxUser);
return vXUser;
}
if (xxUser == null) {
vXUser = new VXUser();
vXUser.setName(userName);
vXUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
vXUser.setDescription(vXUser.getName());
actualPassword = vXUser.getPassword();
}
if (xXPortalUser == null) {
vXPortalUser = new VXPortalUser();
vXPortalUser.setLoginId(userName);
vXPortalUser.setEmailAddress(vXUser.getEmailAddress());
vXPortalUser.setFirstName(vXUser.getFirstName());
vXPortalUser.setLastName(vXUser.getLastName());
vXPortalUser.setPassword(vXUser.getPassword());
vXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
ArrayList<String> roleList = new ArrayList<String>();
roleList.add(RangerConstants.ROLE_USER);
vXPortalUser.setUserRoleList(roleList);
xXPortalUser = userMgr.mapVXPortalUserToXXPortalUser(vXPortalUser);
xXPortalUser = userMgr.createUser(xXPortalUser, RangerCommonEnums.STATUS_ENABLED, roleList);
}
VXUser createdXUser = null;
if (xxUser == null && vXUser != null) {
try {
createdXUser = xUserService.createResource(vXUser);
} catch (Exception ex) {
logger.error("Error creating user: " + vXUser.getName(), ex);
}
}
if (createdXUser != null) {
try {
logger.info("User created: " + createdXUser.getName());
createdXUser.setPassword(actualPassword);
List<XXTrxLog> trxLogList = xUserService.getTransactionLog(createdXUser, "create");
String hiddenPassword = PropertiesUtil.getProperty("ranger.password.hidden", "*****");
createdXUser.setPassword(hiddenPassword);
xaBizUtil.createTrxLog(trxLogList);
if (xXPortalUser != null) {
vXPortalUser = userMgr.mapXXPortalUserToVXPortalUserForDefaultAccount(xXPortalUser);
assignPermissionToUser(vXPortalUser, true);
}
} catch (Exception ex) {
logger.error("Error while assigning permissions to user: " + createdXUser.getName(), ex);
}
} else {
xxUser = daoManager.getXXUser().findByUserName(userName);
if (xxUser != null) {
createdXUser = xUserService.populateViewBean(xxUser);
}
}
return createdXUser;
}
use of org.apache.ranger.entity.XXUser in project ranger by apache.
the class RangerBizUtil method getXUserId.
/**
* returns current user's userID from active user sessions
*
* @return
*/
public Long getXUserId() {
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
if (currentUserSession == null) {
logger.debug("Unable to find session.");
return null;
}
XXPortalUser user = daoManager.getXXPortalUser().getById(currentUserSession.getUserId());
if (user == null) {
logger.debug("XXPortalUser not found with logged in user id : " + currentUserSession.getUserId());
return null;
}
XXUser xUser = daoManager.getXXUser().findByUserName(user.getLoginId());
if (xUser == null) {
logger.debug("XXPortalUser not found for user id :" + user.getId() + " with name " + user.getFirstName());
return null;
}
return xUser.getId();
}
use of org.apache.ranger.entity.XXUser in project ranger by apache.
the class ServiceDBStore method createNewPolicyItemForPolicy.
private XXPolicyItem createNewPolicyItemForPolicy(RangerPolicy policy, XXPolicy xPolicy, RangerPolicyItem policyItem, XXServiceDef xServiceDef, int itemOrder, int policyItemType) throws Exception {
XXPolicyItem xPolicyItem = new XXPolicyItem();
xPolicyItem = rangerAuditFields.populateAuditFields(xPolicyItem, xPolicy);
xPolicyItem.setDelegateAdmin(policyItem.getDelegateAdmin());
xPolicyItem.setItemType(policyItemType);
xPolicyItem.setIsEnabled(Boolean.TRUE);
xPolicyItem.setComments(null);
xPolicyItem.setPolicyId(policy.getId());
xPolicyItem.setOrder(itemOrder);
xPolicyItem = daoMgr.getXXPolicyItem().create(xPolicyItem);
List<RangerPolicyItemAccess> accesses = policyItem.getAccesses();
for (int i = 0; i < accesses.size(); i++) {
RangerPolicyItemAccess access = accesses.get(i);
XXAccessTypeDef xAccTypeDef = daoMgr.getXXAccessTypeDef().findByNameAndServiceId(access.getType(), xPolicy.getService());
if (xAccTypeDef == null) {
throw new Exception(access.getType() + ": is not a valid access-type. policy='" + policy.getName() + "' service='" + policy.getService() + "'");
}
XXPolicyItemAccess xPolItemAcc = new XXPolicyItemAccess();
xPolItemAcc = (XXPolicyItemAccess) rangerAuditFields.populateAuditFields(xPolItemAcc, xPolicyItem);
xPolItemAcc.setIsAllowed(access.getIsAllowed());
xPolItemAcc.setType(xAccTypeDef.getId());
xPolItemAcc.setPolicyitemid(xPolicyItem.getId());
xPolItemAcc.setOrder(i);
daoMgr.getXXPolicyItemAccess().create(xPolItemAcc);
}
List<String> users = policyItem.getUsers();
for (int i = 0; i < users.size(); i++) {
String user = users.get(i);
if (StringUtils.isBlank(user)) {
continue;
}
XXUser xUser = daoMgr.getXXUser().findByUserName(user);
if (xUser == null) {
throw new Exception(user + ": user does not exist. policy='" + policy.getName() + "' service='" + policy.getService() + "' user='" + user + "'");
}
XXPolicyItemUserPerm xUserPerm = new XXPolicyItemUserPerm();
xUserPerm = rangerAuditFields.populateAuditFields(xUserPerm, xPolicyItem);
xUserPerm.setUserId(xUser.getId());
xUserPerm.setPolicyItemId(xPolicyItem.getId());
xUserPerm.setOrder(i);
xUserPerm = daoMgr.getXXPolicyItemUserPerm().create(xUserPerm);
}
List<String> groups = policyItem.getGroups();
for (int i = 0; i < groups.size(); i++) {
String group = groups.get(i);
if (StringUtils.isBlank(group)) {
continue;
}
XXGroup xGrp = daoMgr.getXXGroup().findByGroupName(group);
if (xGrp == null) {
throw new Exception(group + ": group does not exist. policy='" + policy.getName() + "' service='" + policy.getService() + "' group='" + group + "'");
}
XXPolicyItemGroupPerm xGrpPerm = new XXPolicyItemGroupPerm();
xGrpPerm = rangerAuditFields.populateAuditFields(xGrpPerm, xPolicyItem);
xGrpPerm.setGroupId(xGrp.getId());
xGrpPerm.setPolicyItemId(xPolicyItem.getId());
xGrpPerm.setOrder(i);
xGrpPerm = daoMgr.getXXPolicyItemGroupPerm().create(xGrpPerm);
}
List<RangerPolicyItemCondition> conditions = policyItem.getConditions();
for (RangerPolicyItemCondition condition : conditions) {
XXPolicyConditionDef xPolCond = daoMgr.getXXPolicyConditionDef().findByServiceDefIdAndName(xServiceDef.getId(), condition.getType());
if (xPolCond == null) {
throw new Exception(condition.getType() + ": is not a valid condition-type. policy='" + xPolicy.getName() + "' service='" + xPolicy.getService() + "'");
}
for (int i = 0; i < condition.getValues().size(); i++) {
String value = condition.getValues().get(i);
XXPolicyItemCondition xPolItemCond = new XXPolicyItemCondition();
xPolItemCond = rangerAuditFields.populateAuditFields(xPolItemCond, xPolicyItem);
xPolItemCond.setPolicyItemId(xPolicyItem.getId());
xPolItemCond.setType(xPolCond.getId());
xPolItemCond.setValue(value);
xPolItemCond.setOrder(i);
daoMgr.getXXPolicyItemCondition().create(xPolItemCond);
}
}
return xPolicyItem;
}
use of org.apache.ranger.entity.XXUser in project ranger by apache.
the class XAuditMapService method getTransactionLog.
public List<XXTrxLog> getTransactionLog(VXAuditMap vObj, VXAuditMap mObj, String action) {
if (vObj == null || action == null || ("update".equalsIgnoreCase(action) && mObj == null)) {
return null;
}
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Field[] fields = vObj.getClass().getDeclaredFields();
try {
for (Field field : fields) {
field.setAccessible(true);
String fieldName = field.getName();
if (!trxLogAttrs.containsKey(fieldName)) {
continue;
}
VTrxLogAttr vTrxLogAttr = trxLogAttrs.get(fieldName);
XXTrxLog xTrxLog = new XXTrxLog();
xTrxLog.setAttributeName(vTrxLogAttr.getAttribUserFriendlyName());
String value = null;
boolean isEnum = vTrxLogAttr.isEnum();
if (isEnum) {
String enumName = XXAuditMap.getEnumName(fieldName);
int enumValue = field.get(vObj) == null ? 0 : Integer.parseInt("" + field.get(vObj));
value = xaEnumUtil.getLabel(enumName, enumValue);
} else {
value = "" + field.get(vObj);
XXUser xUser = daoManager.getXXUser().getById(Long.parseLong(value));
value = xUser.getName();
}
if ("create".equalsIgnoreCase(action)) {
xTrxLog.setNewValue(value);
} else if ("delete".equalsIgnoreCase(action)) {
xTrxLog.setPreviousValue(value);
} else if ("update".equalsIgnoreCase(action)) {
// Not Changed.
xTrxLog.setNewValue(value);
xTrxLog.setPreviousValue(value);
}
xTrxLog.setAction(action);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_AUDIT_MAP);
xTrxLog.setObjectId(vObj.getId());
xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_RESOURCE);
xTrxLog.setParentObjectId(vObj.getResourceId());
// xTrxLog.setParentObjectName(vObj.get);
// xTrxLog.setObjectName(objectName);
trxLogList.add(xTrxLog);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
return trxLogList;
}
Aggregations