Search in sources :

Example 16 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)

Example 17 with XXGroupUser

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;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) Date(java.util.Date)

Example 18 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 19 with XXGroupUser

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);
            }
        }
    }
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroup(org.apache.ranger.entity.XXGroup) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) VXGroupUser(org.apache.ranger.view.VXGroupUser)

Example 20 with XXGroupUser

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);
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) UserSessionBase(org.apache.ranger.common.UserSessionBase) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

XXGroupUser (org.apache.ranger.entity.XXGroupUser)21 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)10 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)8 VXGroupUser (org.apache.ranger.view.VXGroupUser)8 XXGroup (org.apache.ranger.entity.XXGroup)6 HashSet (java.util.HashSet)5 UserSessionBase (org.apache.ranger.common.UserSessionBase)5 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)4 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)4 VXGroup (org.apache.ranger.view.VXGroup)3 HashMap (java.util.HashMap)2 XXGroupDao (org.apache.ranger.db.XXGroupDao)2 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)2 XXModuleDef (org.apache.ranger.entity.XXModuleDef)2 XXUserPermission (org.apache.ranger.entity.XXUserPermission)2 HadoopException (org.apache.ranger.plugin.client.HadoopException)2 RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)2 VXLong (org.apache.ranger.view.VXLong)2 VXModuleDef (org.apache.ranger.view.VXModuleDef)2