Search in sources :

Example 26 with VXPortalUser

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

the class TestUserMgr method test27UpdateUser.

@Test
public void test27UpdateUser() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile.getId());
    user.setLoginId(userProfile.getLoginId());
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setLoginId(userProfile.getLoginId());
    String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
    user.setPassword(encryptedPwd);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(userProfile.getId())).thenReturn(user);
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    XXPortalUser dbXXPortalUser = userMgr.updateUser(userProfile);
    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(encryptedPwd, dbXXPortalUser.getPassword());
    Mockito.when(restErrorUtil.createRESTException("Please provide valid email address.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(false);
    userMgr.updateUser(userProfile);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 27 with VXPortalUser

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

the class TestUserMgr method test51UpdateUserWithPass.

@Test
public void test51UpdateUserWithPass() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    VXPortalUser userProfile = userProfile();
    userProfile.setPassword("password1234");
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile.getId());
    user.setLoginId(userProfile.getLoginId());
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setLoginId(userProfile.getLoginId());
    String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
    user.setPassword(encryptedPwd);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(userProfile.getId())).thenReturn(user);
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(false);
    Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrNewPassword", MessageEnums.INVALID_PASSWORD, null, null, user.getId().toString())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userMgr.updateUserWithPass(userProfile);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 28 with VXPortalUser

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

the class TestUserMgr method test26CreateUser.

@Test
public void test26CreateUser() {
    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");
    XXPortalUser user = new XXPortalUser();
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setFirstName(userProfile.getFirstName());
    user.setLastName(userProfile.getLastName());
    user.setLoginId(userProfile.getLoginId());
    String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
    user.setPassword(encryptedPwd);
    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.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
    XXPortalUser dbxxPortalUser = userMgr.createUser(userProfile, 1, userRoleList);
    Assert.assertNotNull(dbxxPortalUser);
    userId = dbxxPortalUser.getId();
    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(encryptedPwd, 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)

Example 29 with VXPortalUser

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

the class TestUserMgr method test10CreateDefaultAccountUser.

@Test
public void test10CreateDefaultAccountUser() {
    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());
    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();
    userProfile.setOtherAttributes("other1");
    VXPortalUser dbVXPortalUser = userMgr.createDefaultAccountUser(userProfile);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
    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) VXString(org.apache.ranger.view.VXString) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 30 with VXPortalUser

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

the class TestUserMgr method test44IsPasswordValid.

@Test
public void test44IsPasswordValid() {
    VXPortalUser vXPortalUser = userProfile();
    boolean isValid = userMgr.isPasswordValid(vXPortalUser.getLoginId(), "ceb4f32325eda6142bd65215f4c0f371", vXPortalUser.getPassword());
    Assert.assertFalse(isValid);
}
Also used : VXPortalUser(org.apache.ranger.view.VXPortalUser) 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