Search in sources :

Example 11 with VXResponse

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

the class RangerRestUtil method validateVUserProfileForUpdate.

/**
 * This method cleans up the data provided by the user for update
 *
 * @param userProfile
 * @return
 */
public void validateVUserProfileForUpdate(XXPortalUser gjUser, VXPortalUser userProfile) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    // Login Id can't be changed
    if (userProfile.getLoginId() != null && !gjUser.getLoginId().equalsIgnoreCase(userProfile.getLoginId())) {
        throw restErrorUtil.createRESTException("Username can't be updated", MessageEnums.DATA_NOT_UPDATABLE, null, "loginId", userProfile.getLoginId());
    }
    // }
    userProfile.setFirstName(restErrorUtil.validateStringForUpdate(userProfile.getFirstName(), gjUser.getFirstName(), StringUtil.VALIDATION_NAME, "Invalid first name", MessageEnums.INVALID_INPUT_DATA, null, "firstName"));
    userProfile.setFirstName(restErrorUtil.validateStringForUpdate(userProfile.getFirstName(), gjUser.getFirstName(), StringUtil.VALIDATION_NAME, "Invalid first name", MessageEnums.INVALID_INPUT_DATA, null, "firstName"));
    // firstName
    if (!stringUtil.isValidName(userProfile.getFirstName())) {
        logger.info("Invalid first name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
    }
    // create the public screen name
    userProfile.setPublicScreenName(userProfile.getFirstName() + " " + userProfile.getLastName());
    userProfile.setNotes(restErrorUtil.validateStringForUpdate(userProfile.getNotes(), gjUser.getNotes(), StringUtil.VALIDATION_NAME, "Invalid notes", MessageEnums.INVALID_INPUT_DATA, null, "notes"));
    // validate user roles
    if (userProfile.getUserRoleList() != null) {
        // First let's normalize it
        splitUserRoleList(userProfile.getUserRoleList());
        for (String userRole : userProfile.getUserRoleList()) {
            restErrorUtil.validateStringList(userRole, configUtil.getRoles(), "Invalid role", null, "userRoleList");
        }
    }
    if (!messageList.isEmpty()) {
        VXResponse gjResponse = new VXResponse();
        gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
        gjResponse.setMsgDesc("Validation failure");
        gjResponse.setMessageList(messageList);
        logger.info("Validation Error in updateUser() userProfile=" + userProfile + ", error=" + gjResponse);
        throw restErrorUtil.createRESTException(gjResponse);
    }
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) ArrayList(java.util.ArrayList) VXMessage(org.apache.ranger.view.VXMessage)

Example 12 with VXResponse

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

the class TestRangerBizUtil method testHasPermission_isAdmin.

@Test
public void testHasPermission_isAdmin() {
    VXResource vXResource = new VXResource();
    vXResource.setName(resourceName);
    vXResource.setAssetId(id);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    currentUserSession.setUserAdmin(true);
    VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Assert.assertNotNull(resp);
    Assert.assertEquals(VXResponse.STATUS_SUCCESS, resp.getStatusCode());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) VXResource(org.apache.ranger.view.VXResource) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Example 13 with VXResponse

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

the class TestRangerBizUtil method testMatchHdfsPolicy_NoPremission.

@Test
public void testMatchHdfsPolicy_NoPremission() {
    VXResponse vXResponse = new VXResponse();
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(id);
    xXResource.setName(resourceName);
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    Mockito.when(stringUtil.split(Mockito.anyString(), Mockito.anyString())).thenReturn(new String[0]);
    boolean bnlChk = rangerBizUtil.matchHbasePolicy("/*/*/*", xResourceList, vXResponse, id, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Mockito.verify(stringUtil).split(Mockito.anyString(), Mockito.anyString());
    Assert.assertFalse(bnlChk);
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with VXResponse

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

the class TestRangerBizUtil method testMatchHdfsPolicy_NoUserId.

@Test
public void testMatchHdfsPolicy_NoUserId() {
    VXResponse vXResponse = new VXResponse();
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(id);
    xXResource.setName(resourceName);
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    boolean bnlChk = rangerBizUtil.matchHbasePolicy(resourceName, xResourceList, vXResponse, null, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Assert.assertFalse(bnlChk);
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with VXResponse

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

the class TestRangerBizUtil method testHasPermission_emptyResourceName.

@Test
public void testHasPermission_emptyResourceName() {
    VXResource vXResource = new VXResource();
    vXResource.setAssetId(12345L);
    XXPortalUser portalUser = new XXPortalUser();
    portalUser.setId(id);
    portalUser.setLoginId("12121");
    RangerContextHolder.getSecurityContext().getUserSession().setXXPortalUser(portalUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXUser xxUser = new XXUser();
    XXAsset xxAsset = new XXAsset();
    List<XXResource> lst = new ArrayList<XXResource>();
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    XXAssetDao xxAssetDao = Mockito.mock(XXAssetDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(Mockito.anyLong())).thenReturn(portalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.findByAssetIdAndResourceStatus(Mockito.anyLong(), Mockito.anyInt())).thenReturn(lst);
    Mockito.when(daoManager.getXXAsset()).thenReturn(xxAssetDao);
    Mockito.when(xxAssetDao.getById(Mockito.anyLong())).thenReturn(xxAsset);
    VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(userDao).getById(Mockito.anyLong());
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
    Assert.assertNotNull(resp);
    Assert.assertEquals(VXResponse.STATUS_ERROR, resp.getStatusCode());
    Assert.assertEquals("Permission Denied !", resp.getMsgDesc());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) XXAssetDao(org.apache.ranger.db.XXAssetDao) XXResource(org.apache.ranger.entity.XXResource) XXUserDao(org.apache.ranger.db.XXUserDao) VXResource(org.apache.ranger.view.VXResource) XXAsset(org.apache.ranger.entity.XXAsset) ArrayList(java.util.ArrayList) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) Test(org.junit.Test)

Aggregations

VXResponse (org.apache.ranger.view.VXResponse)40 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 WebApplicationException (javax.ws.rs.WebApplicationException)10 XXPortalUser (org.apache.ranger.entity.XXPortalUser)7 VXMessage (org.apache.ranger.view.VXMessage)7 VXString (org.apache.ranger.view.VXString)7 IOException (java.io.IOException)6 VXResource (org.apache.ranger.view.VXResource)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)5 UserSessionBase (org.apache.ranger.common.UserSessionBase)5 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)5 XXResource (org.apache.ranger.entity.XXResource)5 POST (javax.ws.rs.POST)4 Response (javax.ws.rs.core.Response)3 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)3 VXPasswordChange (org.apache.ranger.view.VXPasswordChange)3 VXPortalUser (org.apache.ranger.view.VXPortalUser)3