use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class ServiceMgr method isZoneAdmin.
public boolean isZoneAdmin(String zoneName) {
boolean isZoneAdmin = false;
RangerSecurityZone securityZone = null;
try {
securityZone = zoneStore.getSecurityZoneByName(zoneName);
} catch (Exception e) {
LOG.error("Unexpected error when fetching security zone with name:[" + zoneName + "] from database", e);
}
if (securityZone != null) {
String userId = rangerBizUtil.getCurrentUserLoginId();
List<XXGroupUser> groupUsers = groupUserDao.findByUserId(rangerBizUtil.getXUserId());
List<String> loggedInUsersGroups = new ArrayList<>();
for (XXGroupUser groupUser : groupUsers) {
loggedInUsersGroups.add(groupUser.getName());
}
for (String loggedInUsersGroup : loggedInUsersGroups) {
if (securityZone != null && securityZone.getAdminUserGroups() != null && securityZone.getAdminUserGroups().contains(loggedInUsersGroup)) {
isZoneAdmin = true;
break;
}
}
if ((securityZone != null && securityZone.getAdminUsers() != null && securityZone.getAdminUsers().contains(userId))) {
isZoneAdmin = true;
}
}
return isZoneAdmin;
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class ServiceMgr method isZoneAuditor.
public boolean isZoneAuditor(String zoneName) {
boolean isZoneAuditor = false;
RangerSecurityZone securityZone = null;
try {
securityZone = zoneStore.getSecurityZoneByName(zoneName);
} catch (Exception e) {
LOG.error("Unexpected error when fetching security zone with name:[" + zoneName + "] from database", e);
}
if (securityZone != null) {
String userId = rangerBizUtil.getCurrentUserLoginId();
List<XXGroupUser> groupUsers = groupUserDao.findByUserId(rangerBizUtil.getXUserId());
List<String> loggedInUsersGroups = new ArrayList<>();
for (XXGroupUser groupUser : groupUsers) {
loggedInUsersGroups.add(groupUser.getName());
}
for (String loggedInUsersGroup : loggedInUsersGroups) {
if (securityZone != null && securityZone.getAuditUserGroups() != null && securityZone.getAuditUserGroups().contains(loggedInUsersGroup)) {
isZoneAuditor = true;
break;
}
}
if ((securityZone != null && securityZone.getAuditUsers() != null && securityZone.getAuditUsers().contains(userId))) {
isZoneAuditor = true;
}
}
return isZoneAuditor;
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class TestXUserMgr method test97updateXModuleDefPermission.
@Test
public void test97updateXModuleDefPermission() {
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXModuleDef xModuleDef = xxModuleDef();
VXModuleDef vXModuleDef = vxModuleDef();
Mockito.when(xModuleDefService.updateResource(vXModuleDef)).thenReturn(vXModuleDef);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.getById(userId)).thenReturn(xModuleDef);
Map<Long, String> xXGroupNameMap = new HashMap<Long, String>();
xXGroupNameMap.put(userId, groupName);
Mockito.when(xGroupService.getXXGroupIdNameMap()).thenReturn(xXGroupNameMap);
Object[] objArr = new Object[] { userId, userId, userLoginID };
Map<Long, Object[]> xXUserMap = new HashMap<Long, Object[]>();
xXUserMap.put(userId, objArr);
Mockito.when(xUserService.getXXPortalUserIdXXUserNameMap()).thenReturn(xXUserMap);
Mockito.when(xModuleDefService.populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true)).thenReturn(vXModuleDef);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
VXGroupPermission vXGroupPermission = vxGroupPermission();
vXGroupPermission.setIsAllowed(0);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
xXUserPermissions.add(xUserPermissionObj);
VXUserPermission vxUserPermission = vxUserPermission();
vxUserPermission.setIsAllowed(0);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
Mockito.when(xxGroupUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(grpUsers);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(vxUserPermission.getUserId())).thenReturn(userSessions);
Mockito.when(xGroupPermissionService.createResource((VXGroupPermission) Mockito.any())).thenReturn(vXGroupPermission);
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vxUserPermission);
VXModuleDef dbMuduleDef = xUserMgr.updateXModuleDefPermission(vXModuleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertNotNull(dbMuduleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
Mockito.verify(daoManager).getXXModuleDef();
Mockito.verify(xModuleDefService).populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true);
Mockito.verify(xGroupService).getXXGroupIdNameMap();
Mockito.verify(xUserService).getXXPortalUserIdXXUserNameMap();
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class TestXUserMgr method test96updateXModuleDefPermission.
@Test
public void test96updateXModuleDefPermission() {
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXModuleDef xModuleDef = xxModuleDef();
VXModuleDef vXModuleDef = vxModuleDef();
Mockito.when(xModuleDefService.updateResource(vXModuleDef)).thenReturn(vXModuleDef);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.getById(userId)).thenReturn(xModuleDef);
Map<Long, String> xXGroupNameMap = new HashMap<Long, String>();
xXGroupNameMap.put(userId, groupName);
Mockito.when(xGroupService.getXXGroupIdNameMap()).thenReturn(xXGroupNameMap);
Object[] objArr = new Object[] { userId, userId, userLoginID };
Map<Long, Object[]> xXUserMap = new HashMap<Long, Object[]>();
xXUserMap.put(userId, objArr);
Mockito.when(xUserService.getXXPortalUserIdXXUserNameMap()).thenReturn(xXUserMap);
Mockito.when(xModuleDefService.populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true)).thenReturn(vXModuleDef);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
List<VXGroupPermission> vXGroupPermissions = new ArrayList<VXGroupPermission>();
VXGroupPermission vXGroupPermission = vxGroupPermission();
vXGroupPermission.setIsAllowed(0);
vXGroupPermissions.add(vXGroupPermission);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
xXUserPermissions.add(xUserPermissionObj);
VXUserPermission vxUserPermission = vxUserPermission();
vxUserPermission.setIsAllowed(0);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
Map<Long, VXGroupPermission> groupPermMapOld = new HashMap<Long, VXGroupPermission>();
groupPermMapOld.put(vXGroupPermission.getGroupId(), vXGroupPermission);
Mockito.when(xGroupPermissionService.convertVListToVMap((List<VXGroupPermission>) Mockito.any())).thenReturn(groupPermMapOld);
Mockito.when(xGroupPermissionService.updateResource(vXGroupPermission)).thenReturn(vXGroupPermission);
XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
Mockito.when(xxGroupUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(grpUsers);
List<VXUserPermission> userPermListOld = new ArrayList<VXUserPermission>();
userPermListOld.add(vxUserPermission);
Map<Long, VXUserPermission> userPermMapOld = new HashMap<Long, VXUserPermission>();
userPermMapOld.put(vxUserPermission.getUserId(), vxUserPermission);
Mockito.when(xUserPermissionService.convertVListToVMap((List<VXUserPermission>) Mockito.any())).thenReturn(userPermMapOld);
Mockito.when(xUserPermissionService.updateResource(vxUserPermission)).thenReturn(vxUserPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(vxUserPermission.getUserId())).thenReturn(userSessions);
VXModuleDef dbMuduleDef = xUserMgr.updateXModuleDefPermission(vXModuleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertNotNull(dbMuduleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
Mockito.verify(xModuleDefService).populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true);
Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
Mockito.verify(daoManager).getXXModuleDef();
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class XGroupUserService method readResourceWithOutLogin.
public VXGroupUser readResourceWithOutLogin(Long id) {
XXGroupUser resource = getDao().getById(id);
if (resource == null) {
// Returns code 400 with DATA_NOT_FOUND as the error message
throw restErrorUtil.createRESTException(getResourceName() + " not found", MessageEnums.DATA_NOT_FOUND, id, null, "preRead: " + id + " not found.");
}
VXGroupUser view = populateViewBean(resource);
return view;
}
Aggregations