Search in sources :

Example 16 with XXPortalUserRole

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

the class TestUserMgr method test21CreateUser.

@Test
public void test21CreateUser() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXPortalUser user = new XXPortalUser();
    VXPortalUser userProfile = userProfile();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.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(userDao);
    Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    VXPortalUser dbVXPortalUser = userMgr.createUser(userProfile);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
    Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(user.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(user.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(user.getEmailAddress(), dbVXPortalUser.getEmailAddress());
    Assert.assertEquals(user.getPassword(), dbVXPortalUser.getPassword());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(daoManager).getXXUserPermission();
    Mockito.verify(daoManager).getXXGroupPermission();
}
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) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 17 with XXPortalUserRole

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

the class TestUserMgr method test22CreateDefaultAccountUser.

@Test
public void test22CreateDefaultAccountUser() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    VXPortalUser dbVXPortalUser = userMgr.createDefaultAccountUser(userProfile);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
    Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(user.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(user.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(user.getEmailAddress(), dbVXPortalUser.getEmailAddress());
    Assert.assertEquals(user.getPassword(), dbVXPortalUser.getPassword());
    Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
    Mockito.verify(daoManager, Mockito.atLeast(1)).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) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 18 with XXPortalUserRole

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

the class TestUserMgr method test28DeleteUserRole.

@Test
public void test28DeleteUserRole() {
    setup();
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    String userRole = "ROLE_USER";
    XXPortalUser user = new XXPortalUser();
    XXPortalUserRole.setId(user.getId());
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(roleDao.findByUserId(userId)).thenReturn(list);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    boolean deleteValue = userMgr.deleteUserRole(userId, userRole);
    Assert.assertTrue(deleteValue);
}
Also used : XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) ArrayList(java.util.ArrayList) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 19 with XXPortalUserRole

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

the class UserService method gjUserToUserProfile.

// TODO: Need to remove this ASAP
public void gjUserToUserProfile(XXPortalUser user, VXPortalUser userProfile) {
    userProfile.setId(user.getId());
    userProfile.setLoginId(user.getLoginId());
    userProfile.setFirstName(user.getFirstName());
    userProfile.setLastName(user.getLastName());
    userProfile.setPublicScreenName(user.getPublicScreenName());
    userProfile.setStatus(user.getStatus());
    userProfile.setUserRoleList(new ArrayList<String>());
    UserSessionBase sess = ContextUtil.getCurrentUserSession();
    String emailAddress = user.getEmailAddress();
    if (emailAddress != null && stringUtil.validateEmail(emailAddress)) {
        userProfile.setEmailAddress(user.getEmailAddress());
    }
    if (sess != null) {
        userProfile.setUserSource(sess.getAuthProvider());
    }
    List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
    for (XXPortalUserRole gjUserRole : gjUserRoleList) {
        userProfile.getUserRoleList().add(gjUserRole.getUserRole());
    }
}
Also used : XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 20 with XXPortalUserRole

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

the class UserMgr method addUserRole.

public XXPortalUserRole addUserRole(Long userId, String userRole) {
    rangerBizUtil.blockAuditorRoleUser();
    List<XXPortalUserRole> roleList = daoManager.getXXPortalUserRole().findByUserId(userId);
    boolean publicRole = false;
    for (String publicRoleStr : publicRoles) {
        if (publicRoleStr.equalsIgnoreCase(userRole)) {
            publicRole = true;
            break;
        }
    }
    if (!publicRole) {
        UserSessionBase sess = ContextUtil.getCurrentUserSession();
        if (sess == null) {
            return null;
        }
        // Admin
        if (!sess.isUserAdmin() && !sess.isKeyAdmin()) {
            logger.error("SECURITY WARNING: User trying to add non public role. userId=" + userId + ", role=" + userRole + ", session=" + sess.toString(), new Throwable());
            return null;
        }
    }
    for (XXPortalUserRole gjUserRole : roleList) {
        if (userRole.equalsIgnoreCase(gjUserRole.getUserRole())) {
            return gjUserRole;
        }
    }
    XXPortalUserRole userRoleObj = new XXPortalUserRole();
    if (!VALID_ROLE_LIST.contains(userRole.toUpperCase())) {
        throw restErrorUtil.createRESTException("Invalid user role, please provide valid user role.", MessageEnums.INVALID_INPUT_DATA);
    }
    userRoleObj.setUserRole(userRole.toUpperCase());
    userRoleObj.setUserId(userId);
    userRoleObj.setStatus(RangerConstants.STATUS_ENABLED);
    daoManager.getXXPortalUserRole().create(userRoleObj);
    // If role is not OTHER, then remove OTHER
    if (!RangerConstants.ROLE_OTHER.equalsIgnoreCase(userRole)) {
        deleteUserRole(userId, RangerConstants.ROLE_OTHER);
    }
    sessionMgr.resetUserSessionForProfiles(ContextUtil.getCurrentUserSession());
    return null;
}
Also used : XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXString(org.apache.ranger.view.VXString) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Aggregations

XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)34 ArrayList (java.util.ArrayList)28 XXPortalUser (org.apache.ranger.entity.XXPortalUser)21 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)20 VXString (org.apache.ranger.view.VXString)20 Test (org.junit.Test)19 VXPortalUser (org.apache.ranger.view.VXPortalUser)18 XXUserPermission (org.apache.ranger.entity.XXUserPermission)14 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)12 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)12 Date (java.util.Date)11 XXModuleDef (org.apache.ranger.entity.XXModuleDef)10 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)10 VXUserPermission (org.apache.ranger.view.VXUserPermission)10 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)9 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)7 UserSessionBase (org.apache.ranger.common.UserSessionBase)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)5 VXStringList (org.apache.ranger.view.VXStringList)4 VXPasswordChange (org.apache.ranger.view.VXPasswordChange)3