Search in sources :

Example 16 with XXPortalUser

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

the class TestUserREST method test12DeactivateUser.

@Test
public void test12DeactivateUser() {
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp = null;
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUserExp);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.nullable(Long.class), Mockito.nullable(String.class), Mockito.anyString())).thenReturn(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userREST.deactivateUser(userId);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 17 with XXPortalUser

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

the class TestUserREST method test16ChangePassword.

@Test
public void test16ChangePassword() {
    XXPortalUser xxPUser = new XXPortalUser();
    VXResponse vxResponseExp = new VXResponse();
    vxResponseExp.setStatusCode(10);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    VXResponse vxResponseAct = userREST.changePassword(userId, changePassword);
    Assert.assertNotNull(vxResponseAct);
    Assert.assertEquals(vxResponseExp, vxResponseAct);
    Assert.assertEquals(vxResponseExp.getStatusCode(), vxResponseAct.getStatusCode());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(userManager).checkAccessForUpdate(xxPUser);
    Mockito.verify(changePassword).setId(userId);
    Mockito.verify(userManager).changePassword(changePassword);
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 18 with XXPortalUser

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

the class TestUserREST method test8Update.

@Test
public void test8Update() {
    VXPortalUser vxPUserExp = CreateVXPortalUser();
    vxPUserExp.setLoginId(loginId);
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp.setLoginId(loginId);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPUserExp);
    Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
    Mockito.doNothing().when(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
    Mockito.when(userManager.updateUser(vxPUserExp)).thenReturn(xxPUserExp);
    Mockito.when(userManager.mapXXPortalUserVXPortalUser(xxPUserExp)).thenReturn(vxPUserExp);
    VXPortalUser vxPUserAct = userREST.update(vxPUserExp, request);
    Assert.assertNotNull(vxPUserAct);
    Assert.assertEquals(xxPUserExp.getLoginId(), vxPUserAct.getLoginId());
    Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
    Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(userManager).checkAccess(xxPUserExp);
    Mockito.verify(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
    Mockito.verify(userManager).updateUser(vxPUserExp);
    Mockito.verify(userManager).mapXXPortalUserVXPortalUser(xxPUserExp);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 19 with XXPortalUser

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

the class TestUserREST method test9Update.

@Test
public void test9Update() {
    VXPortalUser vxPUserExp = new VXPortalUser();
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp = null;
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.nullable(Long.class), Mockito.nullable(String.class), Mockito.anyString())).thenReturn(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userREST.update(vxPUserExp, request);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(userManager).checkAccess(xxPUserExp);
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 20 with XXPortalUser

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

the class UserREST method update.

@PUT
@Consumes({ "application/json", "application/xml" })
@Produces({ "application/xml", "application/json" })
@RangerAnnotationRestAPI(updates_classes = "VUserProfile")
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.UPDATE + "\")")
public VXPortalUser update(VXPortalUser userProfile, @Context HttpServletRequest servletRequest) {
    logger.info("update:" + userProfile.getEmailAddress());
    XXPortalUser gjUser = daoManager.getXXPortalUser().getById(userProfile.getId());
    userManager.checkAccess(gjUser);
    if (gjUser != null) {
        msRestUtil.validateVUserProfileForUpdate(gjUser, userProfile);
        gjUser = userManager.updateUser(userProfile);
        return userManager.mapXXPortalUserVXPortalUser(gjUser);
    } else {
        logger.info("update(): Invalid userId provided: userId=" + userProfile.getId());
        throw restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, userProfile.toString());
    }
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) RangerAnnotationRestAPI(org.apache.ranger.common.annotation.RangerAnnotationRestAPI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) PUT(javax.ws.rs.PUT)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)98 ArrayList (java.util.ArrayList)40 Test (org.junit.Test)39 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)32 VXPortalUser (org.apache.ranger.view.VXPortalUser)30 VXString (org.apache.ranger.view.VXString)26 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)21 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)19 Date (java.util.Date)15 XXUserPermission (org.apache.ranger.entity.XXUserPermission)14 XXModuleDef (org.apache.ranger.entity.XXModuleDef)12 XXUser (org.apache.ranger.entity.XXUser)12 UserSessionBase (org.apache.ranger.common.UserSessionBase)11 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)11 VXUserPermission (org.apache.ranger.view.VXUserPermission)10 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)9 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)9 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)8 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)7 XXTrxLog (org.apache.ranger.entity.XXTrxLog)7