use of org.apache.ranger.view.VXPermMap in project ranger by apache.
the class TestXUserREST method test42createXPermMapNull.
@Test
public void test42createXPermMapNull() {
Mockito.when(xUserMgr.createXPermMap(null)).thenReturn(null);
VXPermMap retVxGroup = xUserRest.createXPermMap(null);
Mockito.verify(xUserMgr).createXPermMap(null);
assertNull(retVxGroup);
}
use of org.apache.ranger.view.VXPermMap in project ranger by apache.
the class TestXUserREST method testcreateXPermMap.
private VXPermMap testcreateXPermMap() {
VXPermMap testVXPermMap = new VXPermMap();
testVXPermMap.setCreateDate(new Date());
testVXPermMap.setGroupId(id);
testVXPermMap.setGroupName("testGroup");
testVXPermMap.setId(id);
testVXPermMap.setOwner("Admin");
testVXPermMap.setPermGroup("testPermGroup");
testVXPermMap.setPermType(1);
testVXPermMap.setResourceId(id);
testVXPermMap.setUpdateDate(new Date());
testVXPermMap.setUpdatedBy("Admin");
testVXPermMap.setUserId(id);
testVXPermMap.setUserName("testUser");
testVXPermMap.setPermFor(1);
return testVXPermMap;
}
use of org.apache.ranger.view.VXPermMap in project ranger by apache.
the class XPolicyService method mapPermMapToPermObj.
public List<VXPermObj> mapPermMapToPermObj(List<VXPermMap> permMapList) {
List<VXPermObj> permObjList = new ArrayList<VXPermObj>();
HashMap<String, List<VXPermMap>> sortedPemMap = new HashMap<String, List<VXPermMap>>();
if (permMapList != null) {
for (VXPermMap vXPermMap : permMapList) {
String permGrp = vXPermMap.getPermGroup();
List<VXPermMap> sortedList = sortedPemMap.get(permGrp);
if (sortedList == null) {
sortedList = new ArrayList<VXPermMap>();
sortedPemMap.put(permGrp, sortedList);
}
sortedList.add(vXPermMap);
}
}
for (Entry<String, List<VXPermMap>> entry : sortedPemMap.entrySet()) {
VXPermObj vXPermObj = new VXPermObj();
List<String> userList = new ArrayList<String>();
List<String> groupList = new ArrayList<String>();
List<String> permList = new ArrayList<String>();
String ipAddress = "";
List<VXPermMap> permListForGrp = entry.getValue();
for (VXPermMap permMap : permListForGrp) {
if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_USER) {
if (!userList.contains(permMap.getUserName())) {
userList.add(permMap.getUserName());
}
} else if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_GROUP) {
if (!groupList.contains(permMap.getGroupName())) {
groupList.add(permMap.getGroupName());
}
}
String perm = AppConstants.getLabelFor_XAPermType(permMap.getPermType());
if (!permList.contains(perm)) {
permList.add(perm);
}
ipAddress = permMap.getIpAddress();
}
if (!userList.isEmpty()) {
vXPermObj.setUserList(userList);
}
if (!groupList.isEmpty()) {
vXPermObj.setGroupList(groupList);
}
vXPermObj.setPermList(permList);
vXPermObj.setIpAddress(ipAddress);
permObjList.add(vXPermObj);
}
return permObjList;
}
use of org.apache.ranger.view.VXPermMap 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;
}
use of org.apache.ranger.view.VXPermMap in project ranger by apache.
the class XPolicyService method mapPermObjToPermList.
private List<VXPermMap> mapPermObjToPermList(List<VXPermObj> permObjList) {
List<VXPermMap> permMapList = new ArrayList<VXPermMap>();
Random rand = new Random();
for (VXPermObj permObj : permObjList) {
String ipAddress = permObj.getIpAddress();
if (!stringUtil.isEmpty(permObj.getUserList())) {
String permGrp = new Date() + " : " + rand.nextInt(9999);
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);
}
for (String permission : permObj.getPermList()) {
VXPermMap vXPermMap = new VXPermMap();
int permType = AppConstants.getEnumFor_XAPermType(permission);
vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER);
vXPermMap.setPermGroup(permGrp);
vXPermMap.setPermType(permType);
vXPermMap.setUserId(xxUser.getId());
vXPermMap.setIpAddress(ipAddress);
permMapList.add(vXPermMap);
}
}
}
if (!stringUtil.isEmpty(permObj.getGroupList())) {
String permGrp = new Date() + " : " + rand.nextInt(9999);
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 User found with name : " + group, MessageEnums.DATA_NOT_FOUND);
}
for (String permission : permObj.getPermList()) {
VXPermMap vXPermMap = new VXPermMap();
int permType = AppConstants.getEnumFor_XAPermType(permission);
vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_GROUP);
vXPermMap.setPermGroup(permGrp);
vXPermMap.setPermType(permType);
vXPermMap.setGroupId(xxGroup.getId());
vXPermMap.setIpAddress(ipAddress);
permMapList.add(vXPermMap);
}
}
}
}
return permMapList;
}
Aggregations