Search in sources :

Example 21 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class UserMgr method mapXXPortalUserToVXPortalUser.

/**
 * @param user
 * @return
 */
public VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user, Collection<String> userRoleList) {
    if (user == null) {
        return null;
    }
    UserSessionBase sess = ContextUtil.getCurrentUserSession();
    if (sess == null) {
        return null;
    }
    VXPortalUser userProfile = new VXPortalUser();
    gjUserToUserProfile(user, userProfile);
    if (sess.isUserAdmin() || sess.isKeyAdmin() || sess.getXXPortalUser().getId().equals(user.getId())) {
        if (userRoleList == null) {
            userRoleList = new ArrayList<String>();
            List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
            for (XXPortalUserRole userRole : gjUserRoleList) {
                userRoleList.add(userRole.getUserRole());
            }
        }
        userProfile.setUserRoleList(userRoleList);
    }
    userProfile.setUserSource(user.getUserSource());
    return userProfile;
}
Also used : VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 22 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class TestRangerBizUtil method testGeneratePublicName_withPortalUser.

@Test
public void testGeneratePublicName_withPortalUser() {
    VXPortalUser vXPortalUser = new VXPortalUser();
    vXPortalUser.setFirstName("Test");
    vXPortalUser.setLastName(null);
    String publicNameChk = rangerBizUtil.generatePublicName(vXPortalUser, null);
    Assert.assertNull(publicNameChk);
}
Also used : VXPortalUser(org.apache.ranger.view.VXPortalUser) Test(org.junit.Test)

Example 23 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class TestUserMgr method test15searchUsers.

@Test
public void test15searchUsers() {
    Query query = Mockito.mock(Query.class);
    EntityManager entityManager = Mockito.mock(EntityManager.class);
    SearchCriteria searchCriteria = new SearchCriteria();
    searchCriteria.setDistinct(true);
    searchCriteria.setGetChildren(true);
    searchCriteria.setGetCount(true);
    searchCriteria.setMaxRows(12);
    searchCriteria.setOwnerId(userId);
    searchCriteria.setStartIndex(1);
    searchCriteria.setSortBy("userId");
    searchCriteria.setSortType("asc");
    Long count = 1l;
    Mockito.when(daoManager.getEntityManager()).thenReturn(entityManager);
    Mockito.when(entityManager.createQuery(Mockito.anyString())).thenReturn(query);
    Mockito.when(query.getSingleResult()).thenReturn(count);
    VXPortalUserList dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    searchCriteria.setSortBy("loginId");
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    searchCriteria.setSortBy("emailAddress");
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    searchCriteria.setSortBy("firstName");
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    searchCriteria.setSortBy("lastName");
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    searchCriteria.setSortBy("source");
    searchCriteria.setSortType("");
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    searchCriteria.setSortBy("");
    searchCriteria.setSortType("desc");
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile.getId());
    user.setLoginId(userProfile.getLoginId());
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setLoginId(userProfile.getLoginId());
    List<XXPortalUser> resultList = new ArrayList<XXPortalUser>();
    resultList.add(user);
    Mockito.when(query.getResultList()).thenReturn(resultList);
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    count = 0l;
    Mockito.when(query.getSingleResult()).thenReturn(count);
    dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) VXPortalUserList(org.apache.ranger.view.VXPortalUserList) ArrayList(java.util.ArrayList) VXPortalUser(org.apache.ranger.view.VXPortalUser) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 24 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class TestUserMgr method test21getUserProfile.

@Test
public void test21getUserProfile() {
    setup();
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUser xPortalUser = Mockito.mock(XXPortalUser.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(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);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
    Mockito.when(xPortalUserDao.getById(userId)).thenReturn(null);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    VXPortalUser dbVXPortalUser = userMgr.getUserProfile(userId);
    Mockito.when(xPortalUserDao.getById(userId)).thenReturn(xPortalUser);
    dbVXPortalUser = userMgr.getUserProfile(userId);
    Assert.assertNotNull(dbVXPortalUser);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 25 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class TestUserMgr method test02CreateUser.

@Test
public void test02CreateUser() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = 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());
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(user.getId());
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(roleDao.findByUserId(userId)).thenReturn(list);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
    XXPortalUser dbxxPortalUser = userMgr.createUser(userProfile, 1);
    userId = dbxxPortalUser.getId();
    Assert.assertNotNull(dbxxPortalUser);
    Assert.assertEquals(userId, dbxxPortalUser.getId());
    Assert.assertEquals(userProfile.getFirstName(), dbxxPortalUser.getFirstName());
    Assert.assertEquals(userProfile.getFirstName(), dbxxPortalUser.getFirstName());
    Assert.assertEquals(userProfile.getLastName(), dbxxPortalUser.getLastName());
    Assert.assertEquals(userProfile.getLoginId(), dbxxPortalUser.getLoginId());
    Assert.assertEquals(userProfile.getEmailAddress(), dbxxPortalUser.getEmailAddress());
    Assert.assertEquals(userProfile.getPassword(), dbxxPortalUser.getPassword());
    Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
    Mockito.verify(daoManager).getXXPortalUserRole();
}
Also used : XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) ArrayList(java.util.ArrayList) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Aggregations

VXPortalUser (org.apache.ranger.view.VXPortalUser)129 Test (org.junit.Test)110 XXPortalUser (org.apache.ranger.entity.XXPortalUser)86 VXString (org.apache.ranger.view.VXString)80 ArrayList (java.util.ArrayList)74 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)61 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)49 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)47 XXUserPermission (org.apache.ranger.entity.XXUserPermission)47 VXUser (org.apache.ranger.view.VXUser)33 Date (java.util.Date)29 WebApplicationException (javax.ws.rs.WebApplicationException)29 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)29 XXModuleDef (org.apache.ranger.entity.XXModuleDef)28 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)26 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)24 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)21 XXUserDao (org.apache.ranger.db.XXUserDao)20 XXUser (org.apache.ranger.entity.XXUser)19