use of org.apache.ranger.entity.XXRole in project ranger by apache.
the class TestXUserMgr method test125DeleteXUser.
@Test
public void test125DeleteXUser() {
destroySession();
setup();
boolean force = true;
VXUser vXUser = vxUser();
XXUser xXUser = new XXUser();
XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
VXPortalUser vXPortalUser = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
XXAuthSession xXAuthSession = new XXAuthSession();
xXAuthSession.setId(userId);
xXAuthSession.setLoginId(vXPortalUser.getLoginId());
xXAuthSessions.add(xXAuthSession);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
xXUserPermissions.add(xxUserPermission());
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
xXPortalUserRoles.add(XXPortalUserRole);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
XXSecurityZoneRefUser xZoneAdminUser = new XXSecurityZoneRefUser();
xZoneAdminUser.setZoneId(2L);
xZoneAdminUser.setUserId(userId);
xZoneAdminUser.setUserName(vXUser.getName());
xZoneAdminUser.setUserType(1);
List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
zoneSecRefUser.add(xZoneAdminUser);
XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.getById(xZoneAdminUser.getZoneId())).thenReturn(xxSecurityZone);
List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
XXRoleRefUser xRoleRefUser = new XXRoleRefUser();
xRoleRefUser.setRoleId(userId);
xRoleRefUser.setUserId(userId);
xRoleRefUser.setUserName(vXUser.getName().trim());
xRoleRefUser.setUserType(0);
roleRefUser.add(xRoleRefUser);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete User '" + vXUser.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXUser(vXUser.getId(), force);
force = false;
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.entity.XXRole in project ranger by apache.
the class TestXUserMgr method test127DeleteXUser.
@Test
public void test127DeleteXUser() {
destroySession();
setup();
boolean force = true;
VXUser vXUser = vxUser();
XXUser xXUser = new XXUser();
XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
VXPortalUser vXPortalUser = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
XXAuthSession xXAuthSession = new XXAuthSession();
xXAuthSession.setId(userId);
xXAuthSession.setLoginId(vXPortalUser.getLoginId());
xXAuthSessions.add(xXAuthSession);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
xXUserPermissions.add(xxUserPermission());
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
xXPortalUserRoles.add(XXPortalUserRole);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
XXRoleRefUser xRoleRefUser = new XXRoleRefUser();
xRoleRefUser.setRoleId(userId);
xRoleRefUser.setUserId(userId);
xRoleRefUser.setUserName(vXUser.getName().trim());
xRoleRefUser.setUserType(0);
roleRefUser.add(xRoleRefUser);
XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
XXRoleDao roleDao = Mockito.mock(XXRoleDao.class);
Mockito.when(daoManager.getXXRole()).thenReturn(roleDao);
Mockito.when(roleDao.getById(xRoleRefUser.getRoleId())).thenReturn(xRole);
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete User '" + vXUser.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXUser(vXUser.getId(), force);
force = false;
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.entity.XXRole in project ranger by apache.
the class TestXUserMgr method test126DeleteXGroup.
@Test
public void test126DeleteXGroup() {
destroySession();
setup();
boolean force = true;
VXGroup vXGroup = vxGroup();
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
XXGroupGroup xXGroupGroup = xxGroupGroup();
xXGroupGroups.add(xXGroupGroup);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
List<XXResource> xResourceList = new ArrayList<XXResource>();
XXResource xXResource = new XXResource();
xXResource.setId(userId);
xXResource.setName("hadoopdev");
xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
xResourceList.add(xXResource);
XXSecurityZoneRefGroup xZoneAdminGroup = new XXSecurityZoneRefGroup();
xZoneAdminGroup.setZoneId(2L);
xZoneAdminGroup.setGroupId(vXGroup.getId());
xZoneAdminGroup.setGroupName(vXGroup.getName());
xZoneAdminGroup.setGroupType(1);
List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
zoneSecRefGroup.add(xZoneAdminGroup);
XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.getById(xZoneAdminGroup.getZoneId())).thenReturn(xxSecurityZone);
List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
XXRoleRefGroup xRoleRefGroup = new XXRoleRefGroup();
xRoleRefGroup.setRoleId(userId);
xRoleRefGroup.setGroupId(userId);
xRoleRefGroup.setGroupName(groupName);
xRoleRefGroup.setGroupType(0);
roleRefGroup.add(xRoleRefGroup);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete Group '" + vXGroup.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
use of org.apache.ranger.entity.XXRole in project ranger by apache.
the class XUserMgr method blockIfRoleGroup.
private void blockIfRoleGroup(Long id) {
List<XXRoleRefGroup> roleRefGroups = this.daoManager.getXXRoleRefGroup().findByGroupId(id);
if (CollectionUtils.isNotEmpty(roleRefGroups)) {
StringBuilder roles = new StringBuilder();
for (XXRoleRefGroup roleRefGroup : roleRefGroups) {
XXRole xxRole = this.daoManager.getXXRole().getById(roleRefGroup.getRoleId());
final String roleName = xxRole.getName();
if (roles.indexOf(roleName) < 0)
roles.append(roleName + ",");
}
final String roleRefGroupName = roleRefGroups.get(0).getGroupName();
this.prepareAndThrow(roleRefGroupName, RangerConstants.ROLE_FIELD, roles, GROUP);
}
}
use of org.apache.ranger.entity.XXRole in project ranger by apache.
the class XUserMgr method blockIfRoleUser.
private void blockIfRoleUser(Long id) {
List<XXRoleRefUser> roleRefUsers = this.daoManager.getXXRoleRefUser().findByUserId(id);
if (CollectionUtils.isNotEmpty(roleRefUsers)) {
StringBuilder roles = new StringBuilder();
for (XXRoleRefUser roleRefUser : roleRefUsers) {
XXRole xxRole = this.daoManager.getXXRole().getById(roleRefUser.getRoleId());
final String roleName = xxRole.getName();
if (roles.indexOf(roleName) < 0)
roles.append(roleName + ",");
}
final String roleRefUserName = roleRefUsers.get(0).getUserName();
this.prepareAndThrow(roleRefUserName, RangerConstants.ROLE_FIELD, roles, USER);
}
}
Aggregations