Search in sources :

Example 46 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser 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 47 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser 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 48 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser 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 49 with XXPortalUser

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

the class TestUserMgr method test01CreateUser.

@Test
public void test01CreateUser() {
    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());
    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, 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(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)

Example 50 with XXPortalUser

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

the class TestUserMgr method test12CreateDefaultAccountUser.

@Test
public void test12CreateDefaultAccountUser() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXPortalUser userProfile = userProfile();
    userProfile.setStatus(RangerCommonEnums.USER_EXTERNAL);
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add("ROLE_USER");
    userProfile.setUserRoleList(userRoleList);
    XXPortalUser xxPortalUser = new XXPortalUser();
    xxPortalUser.setEmailAddress(userProfile.getEmailAddress());
    xxPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    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(xxPortalUser);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    userProfile.setPassword("");
    userProfile.setEmailAddress(null);
    VXPortalUser dbVXPortalUser = userMgr.createDefaultAccountUser(userProfile);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(xxPortalUser.getId(), dbVXPortalUser.getId());
    Assert.assertEquals(xxPortalUser.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(xxPortalUser.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(xxPortalUser.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(xxPortalUser.getEmailAddress(), dbVXPortalUser.getEmailAddress());
    Assert.assertEquals(xxPortalUser.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)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)192 Test (org.junit.Test)113 ArrayList (java.util.ArrayList)93 VXPortalUser (org.apache.ranger.view.VXPortalUser)86 VXString (org.apache.ranger.view.VXString)82 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)74 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)46 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)44 XXUserPermission (org.apache.ranger.entity.XXUserPermission)36 UserSessionBase (org.apache.ranger.common.UserSessionBase)34 VXUser (org.apache.ranger.view.VXUser)34 WebApplicationException (javax.ws.rs.WebApplicationException)33 Date (java.util.Date)30 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)29 XXUser (org.apache.ranger.entity.XXUser)27 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)25 XXModuleDef (org.apache.ranger.entity.XXModuleDef)25 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 VXUserPermission (org.apache.ranger.view.VXUserPermission)19