use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XGroupService method createXGroupWithOutLogin.
public VXGroup createXGroupWithOutLogin(VXGroup vxGroup) {
XXGroup xxGroup = daoManager.getXXGroup().findByGroupName(vxGroup.getName());
boolean groupExists = true;
if (xxGroup == null) {
xxGroup = new XXGroup();
groupExists = false;
}
xxGroup = mapViewToEntityBean(vxGroup, xxGroup, 0);
XXPortalUser xXPortalUser = daoManager.getXXPortalUser().getById(createdByUserId);
if (xXPortalUser != null) {
xxGroup.setAddedByUserId(createdByUserId);
xxGroup.setUpdatedByUserId(createdByUserId);
}
if (groupExists) {
xxGroup = getDao().update(xxGroup);
} else {
xxGroup = getDao().create(xxGroup);
}
vxGroup = postCreate(xxGroup);
return vxGroup;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XGroupUserService method getTransactionLog.
public List<XXTrxLog> getTransactionLog(VXGroupUser vObj, XXGroupUser mObj, String action) {
// if(vObj == null && (action == null || !action.equalsIgnoreCase("update"))){
// return null;
// }
Long groupId = vObj.getParentGroupId();
XXGroup xGroup = daoManager.getXXGroup().getById(groupId);
String groupName = xGroup.getName();
Long userId = vObj.getUserId();
XXUser xUser = daoManager.getXXUser().getById(userId);
String userName = xUser.getName();
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 = XXAsset.getEnumName(fieldName);
int enumValue = field.get(vObj) == null ? 0 : Integer.parseInt("" + field.get(vObj));
value = xaEnumUtil.getLabel(enumName, enumValue);
} else {
value = "" + field.get(vObj);
XXGroup xXGroup = daoManager.getXXGroup().getById(Long.parseLong(value));
value = xXGroup.getName();
}
if ("create".equalsIgnoreCase(action)) {
xTrxLog.setNewValue(value);
} else if ("delete".equalsIgnoreCase(action)) {
xTrxLog.setPreviousValue(value);
} else if ("update".equalsIgnoreCase(action)) {
// No Change.
xTrxLog.setNewValue(value);
xTrxLog.setPreviousValue(value);
}
xTrxLog.setAction(action);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_GROUP_USER);
xTrxLog.setObjectId(vObj.getId());
xTrxLog.setObjectName(userName);
xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_GROUP);
xTrxLog.setParentObjectId(groupId);
xTrxLog.setParentObjectName(groupName);
trxLogList.add(xTrxLog);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
return trxLogList;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XModuleDefService method populateViewBean.
@Override
public VXModuleDef populateViewBean(XXModuleDef xObj) {
VXModuleDef vModuleDef = super.populateViewBean(xObj);
Map<Long, XXUser> xXPortalUserIdXXUserMap = xUserService.getXXPortalUserIdXXUserMap();
Map<Long, XXGroup> xXGroupMap = xGroupService.getXXGroupIdXXGroupMap();
List<VXUserPermission> vXUserPermissionList = new ArrayList<VXUserPermission>();
List<VXGroupPermission> vXGroupPermissionList = new ArrayList<VXGroupPermission>();
List<XXUserPermission> xuserPermissionList = daoManager.getXXUserPermission().findByModuleId(xObj.getId(), false);
List<XXGroupPermission> xgroupPermissionList = daoManager.getXXGroupPermission().findByModuleId(xObj.getId(), false);
if (CollectionUtils.isEmpty(xXPortalUserIdXXUserMap)) {
for (XXUserPermission xUserPerm : xuserPermissionList) {
VXUserPermission vXUserPerm = xUserPermService.populateViewBean(xUserPerm);
vXUserPermissionList.add(vXUserPerm);
}
} else {
vXUserPermissionList = xUserPermService.getPopulatedVXUserPermissionList(xuserPermissionList, xXPortalUserIdXXUserMap, vModuleDef);
}
if (CollectionUtils.isEmpty(xXGroupMap)) {
for (XXGroupPermission xGrpPerm : xgroupPermissionList) {
VXGroupPermission vXGrpPerm = xGrpPermService.populateViewBean(xGrpPerm);
vXGroupPermissionList.add(vXGrpPerm);
}
} else {
vXGroupPermissionList = xGrpPermService.getPopulatedVXGroupPermissionList(xgroupPermissionList, xXGroupMap, vModuleDef);
}
vModuleDef.setUserPermList(vXUserPermissionList);
vModuleDef.setGroupPermList(vXGroupPermissionList);
return vModuleDef;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XPermMapService method getTransactionLog.
public List<XXTrxLog> getTransactionLog(VXPermMap vObj, VXPermMap mObj, String action) {
if (vObj == null || action == null || ("update".equalsIgnoreCase(action) && mObj == null)) {
return null;
}
boolean isGroupPolicy = true;
if (vObj.getGroupId() == null) {
isGroupPolicy = false;
}
Long groupId = null;
Long userId = null;
String groupName = null;
String userName = null;
if (isGroupPolicy) {
groupId = vObj.getGroupId();
XXGroup xGroup = daoManager.getXXGroup().getById(groupId);
groupName = xGroup.getName();
} else {
userId = vObj.getUserId();
XXUser xUser = daoManager.getXXUser().getById(userId);
userName = xUser.getName();
}
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;
// int policyType = vObj.getIpAddress();
/*if(policyType == AppConstants.ASSET_HDFS){
String[] ignoredAttribs = {"ipAddress"};
if(ArrayUtils.contains(ignoredAttribs, fieldName)){
continue;
}
}*/
// } else {
// if(isGroupPolicy){
// if(fieldName.equalsIgnoreCase("userId")){
// continue;
// }
// } else {
// if (fieldName.equalsIgnoreCase("groupId")){
// continue;
// }
// }
}
Long assetId = daoManager.getXXResource().getById(vObj.getResourceId()).getAssetId();
int policyType = daoManager.getXXAsset().getById(assetId).getAssetType();
if (policyType != AppConstants.ASSET_KNOX) {
if ("ipAddress".equals(fieldName))
continue;
}
VTrxLogAttr vTrxLogAttr = trxLogAttrs.get(fieldName);
XXTrxLog xTrxLog = new XXTrxLog();
xTrxLog.setAttributeName(vTrxLogAttr.getAttribUserFriendlyName());
String value = null, prevValue = "";
boolean isEnum = vTrxLogAttr.isEnum();
if (isEnum) {
String enumName = XXPermMap.getEnumName(fieldName);
int enumValue = field.get(vObj) == null ? 0 : Integer.parseInt("" + field.get(vObj));
value = xaEnumUtil.getLabel(enumName, enumValue);
} else {
value = "" + field.get(vObj);
// value = xUser.getName();
if ("ipAddress".equals(fieldName) && "update".equalsIgnoreCase(action)) {
prevValue = "" + field.get(mObj);
value = "null".equalsIgnoreCase(value) ? "" : value;
} else if (value == null || "null".equalsIgnoreCase(value) || stringUtil.isEmpty(value)) {
continue;
}
}
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);
if ("ipAddress".equals(fieldName)) {
xTrxLog.setPreviousValue(prevValue);
}
}
xTrxLog.setAction(action);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_PERM_MAP);
xTrxLog.setObjectId(vObj.getId());
if (isGroupPolicy) {
xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_GROUP);
xTrxLog.setParentObjectId(groupId);
xTrxLog.setParentObjectName(groupName);
} else {
xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_USER);
xTrxLog.setParentObjectId(userId);
xTrxLog.setParentObjectName(userName);
}
// xTrxLog.setObjectName(objectName);
trxLogList.add(xTrxLog);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
return trxLogList;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XPolicyService method mapPermObjToPermList.
private List<VXPermMap> mapPermObjToPermList(List<VXPermObj> permObjList, VXPolicy vXPolicy) {
Long resId = vXPolicy.getId();
List<VXPermMap> permMapList = new ArrayList<VXPermMap>();
List<VXPermMap> updPermMapList = new ArrayList<VXPermMap>();
Map<String, VXPermMap> newPermMap = new LinkedHashMap<String, VXPermMap>();
Random rand = new Random();
Map<String, XXPermMap> prevPermMap = getPrevPermMap(resId);
if (permObjList == null) {
permObjList = new ArrayList<VXPermObj>();
}
for (VXPermObj permObj : permObjList) {
String permGrp = new Date() + " : " + rand.nextInt(9999);
String ipAddress = permObj.getIpAddress();
if (!stringUtil.isEmpty(permObj.getUserList())) {
int permFor = AppConstants.XA_PERM_FOR_USER;
for (String user : permObj.getUserList()) {
XXUser xxUser = xaDaoMgr.getXXUser().findByUserName(user);
if (xxUser == null) {
logger.error("No User found with this name : " + user);
throw restErrorUtil.createRESTException("No User found with name : " + user, MessageEnums.DATA_NOT_FOUND);
}
Long userId = xxUser.getId();
for (String permission : permObj.getPermList()) {
int permType = AppConstants.getEnumFor_XAPermType(permission);
VXPermMap vXPermMap = new VXPermMap();
vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER);
vXPermMap.setPermGroup(permGrp);
vXPermMap.setPermType(permType);
vXPermMap.setUserId(xxUser.getId());
vXPermMap.setResourceId(resId);
vXPermMap.setIpAddress(ipAddress);
permMapList.add(vXPermMap);
StringBuilder uniqueKey = new StringBuilder();
uniqueKey.append(resId + uniqueKeySeparator);
uniqueKey.append(permFor + uniqueKeySeparator);
uniqueKey.append(userId + uniqueKeySeparator);
uniqueKey.append(permType);
newPermMap.put(uniqueKey.toString(), vXPermMap);
}
}
}
if (!stringUtil.isEmpty(permObj.getGroupList())) {
int permFor = AppConstants.XA_PERM_FOR_GROUP;
for (String group : permObj.getGroupList()) {
XXGroup xxGroup = xaDaoMgr.getXXGroup().findByGroupName(group);
if (xxGroup == null) {
logger.error("No UserGroup found with this name : " + group);
throw restErrorUtil.createRESTException("No Group found with name : " + group, MessageEnums.DATA_NOT_FOUND);
}
Long grpId = xxGroup.getId();
for (String permission : permObj.getPermList()) {
int permType = AppConstants.getEnumFor_XAPermType(permission);
VXPermMap vXPermMap = new VXPermMap();
vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_GROUP);
vXPermMap.setPermGroup(permGrp);
vXPermMap.setPermType(permType);
vXPermMap.setGroupId(xxGroup.getId());
vXPermMap.setResourceId(resId);
vXPermMap.setIpAddress(ipAddress);
permMapList.add(vXPermMap);
StringBuilder uniqueKey = new StringBuilder();
uniqueKey.append(resId + uniqueKeySeparator);
uniqueKey.append(permFor + uniqueKeySeparator);
uniqueKey.append(grpId + uniqueKeySeparator);
uniqueKey.append(permType);
newPermMap.put(uniqueKey.toString(), vXPermMap);
}
}
}
}
// Create Newly added permissions and Remove deleted permissions from DB
if (prevPermMap.isEmpty()) {
updPermMapList.addAll(permMapList);
} else {
for (Entry<String, VXPermMap> entry : newPermMap.entrySet()) {
if (!prevPermMap.containsKey(entry.getKey())) {
updPermMapList.add(entry.getValue());
} else {
VXPermMap vPMap = xPermMapService.populateViewBean(prevPermMap.get(entry.getKey()));
VXPermMap vPMapNew = entry.getValue();
vPMap.setIpAddress(vPMapNew.getIpAddress());
updPermMapList.add(vPMap);
}
}
}
return updPermMapList;
}
Aggregations