use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test46setUserRolesByName.
@Test
public void test46setUserRolesByName() {
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
user.setPassword(userProfile.getPassword());
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = new XXUserPermission();
xUserPermissionObj.setAddedByUserId(userId);
xUserPermissionObj.setCreateTime(new Date());
xUserPermissionObj.setId(userId);
xUserPermissionObj.setIsAllowed(1);
xUserPermissionObj.setModuleId(1L);
xUserPermissionObj.setUpdatedByUserId(userId);
xUserPermissionObj.setUpdateTime(new Date());
xUserPermissionObj.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
groupPermList.add(groupPermission);
XXModuleDef xModuleDef = new XXModuleDef();
xModuleDef.setUpdatedByUserId(userId);
xModuleDef.setAddedByUserId(userId);
xModuleDef.setCreateTime(new Date());
xModuleDef.setId(userId);
xModuleDef.setModule("Policy manager");
xModuleDef.setUpdateTime(new Date());
xModuleDef.setUrl("/policy manager");
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(userMgr.getUserProfileByLoginId(userProfile.getLoginId())).thenReturn(userProfile);
VXStringList vXStringList = xUserMgr.setUserRolesByName(userProfile.getLoginId(), vStringRolesList);
Assert.assertNotNull(vXStringList);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test48getUserRolesByName.
@Test
public void test48getUserRolesByName() {
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_USER");
userProfile.setUserRoleList(userRoleList);
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
user.setPassword(userProfile.getPassword());
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = new XXUserPermission();
xUserPermissionObj.setAddedByUserId(userId);
xUserPermissionObj.setCreateTime(new Date());
xUserPermissionObj.setId(userId);
xUserPermissionObj.setIsAllowed(1);
xUserPermissionObj.setModuleId(1L);
xUserPermissionObj.setUpdatedByUserId(userId);
xUserPermissionObj.setUpdateTime(new Date());
xUserPermissionObj.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
groupPermList.add(groupPermission);
XXModuleDef xModuleDef = new XXModuleDef();
xModuleDef.setUpdatedByUserId(userId);
xModuleDef.setAddedByUserId(userId);
xModuleDef.setCreateTime(new Date());
xModuleDef.setId(userId);
xModuleDef.setModule("Policy manager");
xModuleDef.setUpdateTime(new Date());
xModuleDef.setUrl("/policy manager");
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(userMgr.getUserProfileByLoginId(userProfile.getLoginId())).thenReturn(userProfile);
VXStringList vXStringList = xUserMgr.getUserRolesByName(userProfile.getLoginId());
Assert.assertNotNull(vXStringList);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test45setUserRolesByExternalID.
@Test
public void test45setUserRolesByExternalID() {
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXUser vXUser = vxUser();
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
user.setPassword(userProfile.getPassword());
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = new XXUserPermission();
xUserPermissionObj.setAddedByUserId(userId);
xUserPermissionObj.setCreateTime(new Date());
xUserPermissionObj.setId(userId);
xUserPermissionObj.setIsAllowed(1);
xUserPermissionObj.setModuleId(1L);
xUserPermissionObj.setUpdatedByUserId(userId);
xUserPermissionObj.setUpdateTime(new Date());
xUserPermissionObj.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
groupPermList.add(groupPermission);
XXModuleDef xModuleDef = new XXModuleDef();
xModuleDef.setUpdatedByUserId(userId);
xModuleDef.setAddedByUserId(userId);
xModuleDef.setCreateTime(new Date());
xModuleDef.setId(userId);
xModuleDef.setModule("Policy manager");
xModuleDef.setUpdateTime(new Date());
xModuleDef.setUrl("/policy manager");
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
VXStringList vXStringList = xUserMgr.setUserRolesByExternalID(userId, vStringRolesList);
Assert.assertNotNull(vXStringList);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test47getUserRolesByExternalID.
@Test
public void test47getUserRolesByExternalID() {
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXUser vXUser = vxUser();
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
user.setPassword(userProfile.getPassword());
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = new XXUserPermission();
xUserPermissionObj.setAddedByUserId(userId);
xUserPermissionObj.setCreateTime(new Date());
xUserPermissionObj.setId(userId);
xUserPermissionObj.setIsAllowed(1);
xUserPermissionObj.setModuleId(1L);
xUserPermissionObj.setUpdatedByUserId(userId);
xUserPermissionObj.setUpdateTime(new Date());
xUserPermissionObj.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
groupPermList.add(groupPermission);
XXModuleDef xModuleDef = new XXModuleDef();
xModuleDef.setUpdatedByUserId(userId);
xModuleDef.setAddedByUserId(userId);
xModuleDef.setCreateTime(new Date());
xModuleDef.setId(userId);
xModuleDef.setModule("Policy manager");
xModuleDef.setUpdateTime(new Date());
xModuleDef.setUrl("/policy manager");
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
VXStringList vXStringList = xUserMgr.getUserRolesByExternalID(userId);
Assert.assertNotNull(vXStringList);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class PatchPersmissionModel_J10003 method assignPermissionToExistingUsers.
public void assignPermissionToExistingUsers() {
int countUserPermissionUpdated = 0;
Long userCount = daoManager.getXXPortalUser().getAllCount();
List<XXPortalUser> xXPortalUsers = null;
Long patchModeMaxLimit = Long.valueOf(500L);
try {
if (userCount != null && userCount > 0) {
List<String> loginIdList = readUserNamesFromFile(usersListFileName);
if (!CollectionUtils.isEmpty(loginIdList)) {
xXPortalUsers = new ArrayList<XXPortalUser>();
XXPortalUser xXPortalUser = null;
for (String loginId : loginIdList) {
try {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(loginId);
if (xXPortalUser != null) {
xXPortalUsers.add(xXPortalUser);
} else {
logger.info("User " + loginId + " doesn't exist!");
}
} catch (Exception ex) {
}
}
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to " + countUserPermissionUpdated + " of " + loginIdList.size());
} else if (userCount.compareTo(Long.valueOf(patchModeMaxLimit)) < 0 || grantAllUsers) {
xXPortalUsers = daoManager.getXXPortalUser().findAllXPortalUser();
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to " + countUserPermissionUpdated + " of " + xXPortalUsers.size());
}
} else {
// if total no. of users are more than 500 then process ADMIN and KEY_ADMIN users only to avoid timeout
xXPortalUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_SYS_ADMIN);
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to users having role:" + RangerConstants.ROLE_SYS_ADMIN + ". Processed:" + countUserPermissionUpdated + " of total " + xXPortalUsers.size());
}
xXPortalUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_KEY_ADMIN);
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Permissions assigned to users having role:" + RangerConstants.ROLE_KEY_ADMIN + ". Processed:" + countUserPermissionUpdated + " of total " + xXPortalUsers.size());
}
logger.info("Please execute this patch separately with argument 'ALL' to assign permission to remaining users ");
System.out.println("Please execute this patch separately with argument 'ALL' to assign module permissions to remaining users!!");
}
}
} catch (Exception ex) {
}
}
Aggregations