Search in sources :

Example 11 with XXGroupUser

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

the class TestXUserMgr method test82updateXgroupUserForGroupUpdate.

@Test
public void test82updateXgroupUserForGroupUpdate() {
    setup();
    XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    VXGroup vXGroup = vxGroup();
    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(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
    Mockito.when(xxGroupUserDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupUserList);
    Mockito.when(xGroupUserService.populateViewBean(xXGroupUser)).thenReturn(vxGroupUser);
    xUserMgr.updateXgroupUserForGroupUpdate(vXGroup);
    Mockito.verify(daoManager).getXXGroupUser();
    Mockito.verify(xxGroupUserDao).findByGroupId(vXGroup.getId());
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 12 with XXGroupUser

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

the class TestXUserMgr method test10UpdateXGroup.

@Test
public void test10UpdateXGroup() {
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
    setup();
    VXGroup vXGroup = vxGroup();
    XXGroup xxGroup = new XXGroup();
    xxGroup.setName(groupName);
    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());
    Mockito.when(restErrorUtil.createRESTException("group name updates are not allowed.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    vXGroup.setName("UnknownGroup");
    xUserMgr.updateXGroup(vXGroup);
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXGroup(org.apache.ranger.entity.XXGroup) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Example 13 with XXGroupUser

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

the class XUserMgr method createXGroupPermission.

// Group permission
public VXGroupPermission createXGroupPermission(VXGroupPermission vXGroupPermission) {
    vXGroupPermission = xGroupPermissionService.createResource(vXGroupPermission);
    List<XXGroupUser> grpUsers = daoManager.getXXGroupUser().findByGroupId(vXGroupPermission.getGroupId());
    for (XXGroupUser xGrpUser : grpUsers) {
        Set<UserSessionBase> userSessions = sessionMgr.getActiveUserSessionsForXUserId(xGrpUser.getUserId());
        if (!CollectionUtils.isEmpty(userSessions)) {
            for (UserSessionBase userSession : userSessions) {
                logger.info("Assigning permission to group, one of the user belongs to that group found logged in into system, so updating permission in session of that user");
                sessionMgr.resetUserModulePermission(userSession);
            }
        }
    }
    return vXGroupPermission;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser)

Example 14 with XXGroupUser

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

the class XUserMgr method updateXgroupUserForGroupUpdate.

protected void updateXgroupUserForGroupUpdate(VXGroup vXGroup) {
    List<XXGroupUser> grpUsers = daoManager.getXXGroupUser().findByGroupId(vXGroup.getId());
    if (CollectionUtils.isNotEmpty(grpUsers)) {
        for (XXGroupUser grpUser : grpUsers) {
            VXGroupUser vXGroupUser = xGroupUserService.populateViewBean(grpUser);
            vXGroupUser.setName(vXGroup.getName());
            updateXGroupUser(vXGroupUser);
        }
    }
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser)

Example 15 with XXGroupUser

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

the class XUserMgr method updateXGroupPermission.

public VXGroupPermission updateXGroupPermission(VXGroupPermission vXGroupPermission) {
    vXGroupPermission = xGroupPermissionService.updateResource(vXGroupPermission);
    List<XXGroupUser> grpUsers = daoManager.getXXGroupUser().findByGroupId(vXGroupPermission.getGroupId());
    for (XXGroupUser xGrpUser : grpUsers) {
        Set<UserSessionBase> userSessions = sessionMgr.getActiveUserSessionsForXUserId(xGrpUser.getUserId());
        if (!CollectionUtils.isEmpty(userSessions)) {
            for (UserSessionBase userSession : userSessions) {
                logger.info("Assigning permission to group whose one of the user found logged in into system, so updating permission in session of that user");
                sessionMgr.resetUserModulePermission(userSession);
            }
        }
    }
    return vXGroupPermission;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser)

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