use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class XUserMgr method deleteXGroupPermission.
public void deleteXGroupPermission(Long id, boolean force) {
XXGroupPermission xGrpPerm = daoManager.getXXGroupPermission().getById(id);
if (xGrpPerm == null) {
throw restErrorUtil.createRESTException("No GroupPermission object with ID: [" + id + "found.", MessageEnums.DATA_NOT_FOUND);
}
xGroupPermissionService.deleteResource(id);
List<XXGroupUser> grpUsers = daoManager.getXXGroupUser().findByGroupId(xGrpPerm.getGroupId());
for (XXGroupUser xGrpUser : grpUsers) {
Set<UserSessionBase> userSessions = sessionMgr.getActiveUserSessionsForXUserId(xGrpUser.getUserId());
if (!CollectionUtils.isEmpty(userSessions)) {
for (UserSessionBase userSession : userSessions) {
logger.info("deleting permission of the group whose one of the user found logged in into system, so updating permission in session of that user");
sessionMgr.resetUserModulePermission(userSession);
}
}
}
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class TestXGroupUserService method createXXGroupUser.
private XXGroupUser createXXGroupUser() {
XXGroupUser xXGroupUser = new XXGroupUser();
xXGroupUser.setAddedByUserId(1L);
Date date = new Date();
xXGroupUser.setCreateTime(date);
xXGroupUser.setId(1L);
xXGroupUser.setName("testGroupUser");
xXGroupUser.setParentGroupId(1L);
xXGroupUser.setUpdatedByUserId(1L);
xXGroupUser.setUpdateTime(date);
xXGroupUser.setUserId(1L);
return xXGroupUser;
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class XGroupUserService method createXGroupUserWithOutLogin.
public VXGroupUser createXGroupUserWithOutLogin(VXGroupUser vxGroupUser) {
boolean groupUserMappingExists = true;
XXGroupUser xxGroupUser = daoManager.getXXGroupUser().findByGroupNameAndUserId(vxGroupUser.getName(), vxGroupUser.getUserId());
if (xxGroupUser == null) {
xxGroupUser = new XXGroupUser();
groupUserMappingExists = false;
}
XXGroup xGroup = daoManager.getXXGroup().findByGroupName(vxGroupUser.getName());
vxGroupUser.setParentGroupId(xGroup.getId());
xxGroupUser = mapViewToEntityBean(vxGroupUser, xxGroupUser, 0);
XXPortalUser xXPortalUser = daoManager.getXXPortalUser().getById(createdByUserId);
if (xXPortalUser != null) {
xxGroupUser.setAddedByUserId(createdByUserId);
xxGroupUser.setUpdatedByUserId(createdByUserId);
}
if (groupUserMappingExists) {
xxGroupUser = getDao().update(xxGroupUser);
} else {
xxGroupUser = getDao().create(xxGroupUser);
}
vxGroupUser = postCreate(xxGroupUser);
return vxGroupUser;
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class XGroupUserService method createOrUpdateXGroupUsers.
public void createOrUpdateXGroupUsers(String groupName, Set<String> users, Map<String, Long> usersFromDB) {
XXGroup xxGroup = daoManager.getXXGroup().findByGroupName(groupName);
if (logger.isDebugEnabled()) {
logger.debug("createOrUpdateXGroupUsers(): groupname = " + groupName + " users = " + users);
}
if (xxGroup == null) {
if (logger.isDebugEnabled()) {
logger.debug("createOrUpdateXGroupUsers(): groupname = " + groupName + " doesn't exist in database. Hence ignoring group membership updates");
}
return;
}
Map<String, XXGroupUser> groupUsers = daoManager.getXXGroupUser().findUsersByGroupName(groupName);
for (String username : users) {
if (usersFromDB.containsKey(username)) {
// Add or update group user mapping only if the user exists in x_user table.
TransactionTemplate txTemplate = new TransactionTemplate(txManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
try {
txTemplate.execute(new TransactionCallback<Object>() {
@Override
public Object doInTransaction(TransactionStatus status) {
XXGroupUser xxGroupUser = groupUsers.get(username);
boolean groupUserMappingExists = true;
if (xxGroupUser == null) {
xxGroupUser = new XXGroupUser();
groupUserMappingExists = false;
}
xxGroupUser.setAddedByUserId(createdByUserId);
xxGroupUser.setUpdatedByUserId(createdByUserId);
if (groupUserMappingExists) {
xxGroupUser = getDao().update(xxGroupUser);
} else {
VXGroupUser vXGroupUser = new VXGroupUser();
vXGroupUser.setUserId(usersFromDB.get(username));
vXGroupUser.setName(groupName);
vXGroupUser.setParentGroupId(xxGroup.getId());
xxGroupUser = mapViewToEntityBean(vXGroupUser, xxGroupUser, 0);
xxGroupUser = getDao().create(xxGroupUser);
}
VXGroupUser vXGroupUser = postCreate(xxGroupUser);
if (logger.isDebugEnabled()) {
logger.debug(String.format("createOrUpdateXGroupUsers(): Create or update group user mapping with groupname = " + vXGroupUser.getName() + " username = %s userId = %d", username, vXGroupUser.getUserId()));
}
return null;
}
});
} catch (Throwable ex) {
logger.error("XGroupUserService.createOrUpdateXGroupUsers: Failed to update DB for group users: ", ex);
throw restErrorUtil.createRESTException("Failed to create or update group users ", MessageEnums.ERROR_CREATING_OBJECT);
}
}
}
}
use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.
the class TestXUserMgr method test34updateXGroupPermission.
@Test
public void test34updateXGroupPermission() {
setup();
VXGroupPermission vXGroupPermission = vxGroupPermission();
XXGroupUserDao xGrpUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGrpUserDao);
Mockito.when(xGroupPermissionService.updateResource(vXGroupPermission)).thenReturn(vXGroupPermission);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
Mockito.when(sessionMgr.getActiveUserSessionsForXUserId(userId)).thenReturn(userSessions);
List<XXGroupUser> xXGroupUserList = new ArrayList<XXGroupUser>();
VXGroupUser vxGroupUser = vxGroupUser();
XXGroupUser xXGroupUser = new XXGroupUser();
xXGroupUser.setId(vxGroupUser.getId());
xXGroupUser.setName(vxGroupUser.getName());
xXGroupUser.setParentGroupId(vxGroupUser.getParentGroupId());
xXGroupUser.setUserId(vxGroupUser.getUserId());
xXGroupUserList.add(xXGroupUser);
Mockito.when(xGrpUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(xXGroupUserList);
VXGroupPermission dbGroupPermission = xUserMgr.updateXGroupPermission(vXGroupPermission);
Assert.assertNotNull(dbGroupPermission);
Assert.assertEquals(dbGroupPermission, vXGroupPermission);
Assert.assertEquals(dbGroupPermission.getId(), vXGroupPermission.getId());
Assert.assertEquals(dbGroupPermission.getGroupName(), vXGroupPermission.getGroupName());
Assert.assertEquals(dbGroupPermission.getOwner(), vXGroupPermission.getOwner());
Assert.assertEquals(dbGroupPermission.getUpdatedBy(), vXGroupPermission.getUpdatedBy());
Assert.assertEquals(dbGroupPermission.getCreateDate(), vXGroupPermission.getCreateDate());
Assert.assertEquals(dbGroupPermission.getGroupId(), vXGroupPermission.getGroupId());
Assert.assertEquals(dbGroupPermission.getIsAllowed(), vXGroupPermission.getIsAllowed());
Assert.assertEquals(dbGroupPermission.getModuleId(), vXGroupPermission.getModuleId());
Assert.assertEquals(dbGroupPermission.getUpdateDate(), vXGroupPermission.getUpdateDate());
Mockito.verify(xGroupPermissionService).updateResource(vXGroupPermission);
}
Aggregations