Search in sources :

Example 6 with XXGroupUser

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);
            }
        }
    }
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 7 with 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;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXGroup(org.apache.ranger.entity.XXGroup)

Example 8 with XXGroupUser

use of org.apache.ranger.entity.XXGroupUser in project ranger by apache.

the class TestXUserMgr method test17UpdateXGroup.

@Test
public void test17UpdateXGroup() {
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
    setup();
    VXGroup vXGroup = new VXGroup();
    vXGroup.setId(userId);
    vXGroup.setDescription("group test");
    vXGroup.setName("grouptest");
    XXGroup xxGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
    Mockito.when(xxGroupDao.getById(vXGroup.getId())).thenReturn(xxGroup);
    Mockito.when(xGroupService.updateResource(vXGroup)).thenReturn(vXGroup);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
    Mockito.when(xxGroupUserDao.findByGroupId(vXGroup.getId())).thenReturn(grpUsers);
    VXGroup dbvxGroup = xUserMgr.updateXGroup(vXGroup);
    Assert.assertNotNull(dbvxGroup);
    userId = dbvxGroup.getId();
    Assert.assertEquals(userId, dbvxGroup.getId());
    Assert.assertEquals(vXGroup.getDescription(), dbvxGroup.getDescription());
    Assert.assertEquals(vXGroup.getName(), dbvxGroup.getName());
    Mockito.verify(daoManager).getXXGroup();
    Mockito.verify(daoManager).getXXGroupUser();
    Mockito.verify(xGroupService).updateResource(vXGroup);
    Mockito.verify(xxGroupUserDao).findByGroupId(vXGroup.getId());
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXGroup(org.apache.ranger.entity.XXGroup) ArrayList(java.util.ArrayList) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Aggregations

XXGroupUser (org.apache.ranger.entity.XXGroupUser)8 UserSessionBase (org.apache.ranger.common.UserSessionBase)3 ArrayList (java.util.ArrayList)2 XXGroup (org.apache.ranger.entity.XXGroup)2 LinkedHashSet (java.util.LinkedHashSet)1 XXGroupDao (org.apache.ranger.db.XXGroupDao)1 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)1 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)1 XXPortalUser (org.apache.ranger.entity.XXPortalUser)1 VXGroup (org.apache.ranger.view.VXGroup)1 VXGroupUser (org.apache.ranger.view.VXGroupUser)1 Test (org.junit.Test)1