use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class TestXUserMgr method test27DeleteXGroup.
@Test
public void test27DeleteXGroup() {
setup();
boolean force = true;
VXGroup vXGroup = new VXGroup();
vXGroup.setId(userId);
vXGroup.setDescription("group test");
vXGroup.setName("grouptest");
// XXGroup
XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
XXGroup xXGroup = new XXGroup();
Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
// VXGroupUser
VXGroupUserList vxGroupUserList = new VXGroupUserList();
XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
VXGroupUser vxGroupUser = new VXGroupUser();
vxGroupUser.setId(userId);
vxGroupUser.setName("group user test");
vxGroupUser.setOwner("Admin");
vxGroupUser.setUserId(userId);
vxGroupUser.setUpdatedBy("User");
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
// VXPermMap
VXPermMapList vXPermMapList = new VXPermMapList();
XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
// VXAuditMap
VXAuditMapList vXAuditMapList = new VXAuditMapList();
XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
// XXGroupGroup
XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
// update XXGroupPermission
XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
// update XXPolicyItemUserPerm
XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
xUserMgr.deleteXGroup(vXGroup.getId(), force);
Mockito.verify(xGroupUserService).searchXGroupUsers((SearchCriteria) Mockito.any());
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class RangerBaseModelService method getGroupName.
protected String getGroupName(Long groupId) {
String ret = null;
XXGroup xGroup = groupId == null ? null : daoMgr.getXXGroup().getById(groupId);
if (xGroup != null) {
ret = xGroup.getName();
}
return ret;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class RangerBizUtil method checkUsrPermForPolicy.
/**
* returns true if given userID is having specified permission on specified
* resource
*
* @param xUserId
* @param permission
* @param resourceId
* @return
*/
private boolean checkUsrPermForPolicy(Long xUserId, int permission, Long resourceId) {
// this snippet load user groups and permission map list from DB
List<XXGroup> userGroups = new ArrayList<XXGroup>();
List<XXPermMap> permMapList = new ArrayList<XXPermMap>();
userGroups = daoManager.getXXGroup().findByUserId(xUserId);
permMapList = daoManager.getXXPermMap().findByResourceId(resourceId);
Long publicGroupId = getPublicGroupId();
boolean matchFound = false;
for (XXPermMap permMap : permMapList) {
if (permMap.getPermType() == permission) {
if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_GROUP) {
// check whether permission is enabled for public group or a
// group to which user belongs
matchFound = (publicGroupId != null && publicGroupId == permMap.getGroupId()) || isGroupInList(permMap.getGroupId(), userGroups);
} else if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_USER) {
// check whether permission is enabled to user
matchFound = permMap.getUserId().equals(xUserId);
}
}
if (matchFound) {
break;
}
}
return matchFound;
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class ServiceDBStore method createDefaultPolicyUsersAndGroups.
void createDefaultPolicyUsersAndGroups(List<RangerPolicy> defaultPolicies) {
Set<String> defaultPolicyUsers = new HashSet<String>();
Set<String> defaultPolicyGroups = new HashSet<String>();
for (RangerPolicy defaultPolicy : defaultPolicies) {
for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getPolicyItems()) {
defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
}
for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getAllowExceptions()) {
defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
}
for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDenyPolicyItems()) {
defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
}
for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDenyExceptions()) {
defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
}
for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDataMaskPolicyItems()) {
defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
}
for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getRowFilterPolicyItems()) {
defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
}
}
for (String policyUser : defaultPolicyUsers) {
if (LOG.isDebugEnabled()) {
LOG.debug("Checking policyUser:[" + policyUser + "] for existence");
}
if (StringUtils.isNotBlank(policyUser) && !StringUtils.equals(policyUser, RangerPolicyEngine.USER_CURRENT) && !StringUtils.equals(policyUser, RangerPolicyEngine.RESOURCE_OWNER)) {
XXUser xxUser = daoMgr.getXXUser().findByUserName(policyUser);
if (xxUser == null) {
UserSessionBase usb = ContextUtil.getCurrentUserSession();
if (usb != null && !usb.isKeyAdmin() && !usb.isUserAdmin() && !usb.isSpnegoEnabled()) {
throw restErrorUtil.createRESTException("User does not exist with given username: [" + policyUser + "] please use existing user", MessageEnums.OPER_NO_PERMISSION);
}
xUserMgr.createServiceConfigUser(policyUser);
}
}
}
for (String policyGroup : defaultPolicyGroups) {
if (LOG.isDebugEnabled()) {
LOG.debug("Checking policyGroup:[" + policyGroup + "] for existence");
}
if (StringUtils.isNotBlank(policyGroup)) {
XXGroup xxGroup = daoMgr.getXXGroup().findByGroupName(policyGroup);
if (xxGroup == null) {
UserSessionBase usb = ContextUtil.getCurrentUserSession();
if (usb != null && !usb.isKeyAdmin() && !usb.isUserAdmin() && !usb.isSpnegoEnabled()) {
throw restErrorUtil.createRESTException("Group does not exist with given groupname: [" + policyGroup + "] please use existing group", MessageEnums.OPER_NO_PERMISSION);
}
VXGroup vXGroup = new VXGroup();
vXGroup.setName(policyGroup);
vXGroup.setDescription(policyGroup);
vXGroup.setGroupSource(RangerCommonEnums.GROUP_INTERNAL);
vXGroup.setIsVisible(RangerCommonEnums.IS_VISIBLE);
xGroupService.createResource(vXGroup);
}
}
}
}
use of org.apache.ranger.entity.XXGroup in project ranger by apache.
the class XGroupPermissionService method getPopulatedVXGroupPermissionList.
public List<VXGroupPermission> getPopulatedVXGroupPermissionList(List<XXGroupPermission> xgroupPermissionList, Map<Long, XXGroup> xXGroupMap, VXModuleDef vModuleDef) {
List<VXGroupPermission> vXGroupPermissionList = new ArrayList<VXGroupPermission>();
XXGroup xXGroup = null;
for (XXGroupPermission xgroupPermission : xgroupPermissionList) {
if (xXGroupMap.containsKey(xgroupPermission.getGroupId())) {
xXGroup = xXGroupMap.get(xgroupPermission.getGroupId());
VXGroupPermission vXGrpPerm = new VXGroupPermission();
vXGrpPerm.setId(xgroupPermission.getId());
vXGrpPerm.setGroupId(xgroupPermission.getGroupId());
vXGrpPerm.setModuleId(xgroupPermission.getModuleId());
vXGrpPerm.setIsAllowed(xgroupPermission.getIsAllowed());
vXGrpPerm.setCreateDate(xgroupPermission.getCreateTime());
vXGrpPerm.setUpdateDate(xgroupPermission.getUpdateTime());
vXGrpPerm.setGroupName(xXGroup.getName());
vXGrpPerm.setModuleName(vModuleDef.getModule());
vXGroupPermissionList.add(vXGrpPerm);
}
}
return vXGroupPermissionList;
}
Aggregations