Search in sources :

Example 56 with XXPortalUser

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

the class TestUserMgr method setupKeyAdmin.

public void setupKeyAdmin() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    XXPortalUser userKeyAdmin = new XXPortalUser();
    userKeyAdmin.setId(userProfile().getId());
    userKeyAdmin.setLoginId(userProfile().getLoginId());
    currentUserSession.setXXPortalUser(userKeyAdmin);
    currentUserSession.setKeyAdmin(true);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 57 with XXPortalUser

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

the class TestUserMgr method test36UpdateUser.

@Test
public void test36UpdateUser() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile.getId());
    user.setLoginId(userProfile.getLoginId());
    userProfile.setFirstName("User");
    userProfile.setLastName("User");
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
    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.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    Mockito.when(stringUtil.toCamelCaseAllWords(Mockito.anyString())).thenReturn(userProfile.getFirstName());
    XXPortalUser dbXXPortalUser = userMgr.updateUser(userProfile);
    Assert.assertNotNull(dbXXPortalUser);
    Mockito.when(stringUtil.isEmpty(Mockito.anyString())).thenReturn(true);
    userProfile.setFirstName("null");
    userProfile.setLastName("null");
    userProfile.setEmailAddress("");
    dbXXPortalUser = userMgr.updateUser(userProfile);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 58 with XXPortalUser

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

the class TestUserMgr method test25updatePasswordInSHA256.

@Test
public void test25updatePasswordInSHA256() {
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    VXPortalUser userProfile = userProfile();
    String userName = userProfile.getFirstName();
    String userPassword = userProfile.getPassword();
    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(RangerCommonEnums.USER_APP);
    user.setPublicScreenName(userProfile.getPublicScreenName());
    user.setId(userProfile.getId());
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.update(user)).thenReturn(user);
    XXPortalUser dbXXPortalUser = userMgr.updatePasswordInSHA256(null, userPassword, false);
    Assert.assertNull(dbXXPortalUser);
    Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(null);
    dbXXPortalUser = userMgr.updatePasswordInSHA256(userName, userPassword, false);
    Assert.assertNull(dbXXPortalUser);
    Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
    dbXXPortalUser = userMgr.updatePasswordInSHA256(userName, userPassword, true);
    Assert.assertNotNull(dbXXPortalUser);
    dbXXPortalUser = userMgr.updatePasswordInSHA256(userName, "Secret", true);
    Assert.assertNotNull(dbXXPortalUser);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 59 with XXPortalUser

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

the class TestUserMgr method test49CreateDefaultAccountUser.

@Test
public void test49CreateDefaultAccountUser() {
    destroySession();
    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 user = new XXPortalUser();
    user.setEmailAddress(userProfile.getEmailAddress());
    user.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(null, user);
    Mockito.when(userDao.findByEmailAddress(Mockito.anyString())).thenReturn(null);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    userProfile.setEmailAddress(null);
    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();
    Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(null);
    Mockito.when(userDao.findByEmailAddress(Mockito.anyString())).thenReturn(user);
    Mockito.when(restErrorUtil.createRESTException("The email address " + user.getEmailAddress() + " you've provided already exists. Please try again with different email address.", MessageEnums.OPER_NOT_ALLOWED_FOR_STATE)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userProfile.setEmailAddress(user.getEmailAddress());
    userMgr.createDefaultAccountUser(userProfile);
}
Also used : XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) 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 60 with XXPortalUser

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

the class TestUserMgr method test20checkAccess.

@Test
public void test20checkAccess() {
    setup();
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUser xPortalUser = Mockito.mock(XXPortalUser.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
    Mockito.when(xPortalUserDao.getById(userId)).thenReturn(xPortalUser);
    userMgr.checkAccess(userId);
    Mockito.when(xPortalUserDao.getById(userId)).thenReturn(null);
    Mockito.when(restErrorUtil.create403RESTException("serverMsg.userMgrWrongUser: " + userId)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userMgr.checkAccess(userId);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) 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