Search in sources :

Example 16 with VXResponse

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

the class TestUserMgr method test15ChangePasswordAsUser.

@Test
public void test15ChangePasswordAsUser() {
    setupUser();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    VXPortalUser userProfile = userProfile();
    VXPasswordChange pwdChange = new VXPasswordChange();
    pwdChange.setId(userProfile.getId());
    pwdChange.setLoginId(userProfile.getLoginId());
    pwdChange.setOldPassword(userProfile.getPassword());
    pwdChange.setEmailAddress(userProfile.getEmailAddress());
    pwdChange.setUpdPassword(userProfile.getPassword());
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile.getId());
    user.setLoginId(userProfile.getLoginId());
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
    Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
    VXResponse dbVXResponse = userMgr.changePassword(pwdChange);
    Assert.assertNotNull(dbVXResponse);
    Assert.assertEquals(userProfile.getStatus(), dbVXResponse.getStatusCode());
    Mockito.verify(stringUtil).equals(Mockito.anyString(), Mockito.nullable(String.class));
    Mockito.verify(stringUtil).validatePassword(Mockito.anyString(), Mockito.any(String[].class));
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 17 with VXResponse

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

the class TestUserMgr method test14ChangePasswordAsKeyAdmin.

@Test
public void test14ChangePasswordAsKeyAdmin() {
    setupKeyAdmin();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    VXPortalUser userProfile = userProfile();
    VXPasswordChange pwdChange = new VXPasswordChange();
    pwdChange.setId(userProfile.getId());
    pwdChange.setLoginId(userProfile.getLoginId());
    pwdChange.setOldPassword(userProfile.getPassword());
    pwdChange.setEmailAddress(userProfile.getEmailAddress());
    pwdChange.setUpdPassword(userProfile.getPassword());
    XXPortalUser userKeyAdmin = new XXPortalUser();
    userKeyAdmin.setId(userProfile.getId());
    userKeyAdmin.setLoginId(userProfile.getLoginId());
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(userKeyAdmin);
    Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
    VXResponse dbVXResponse = userMgr.changePassword(pwdChange);
    Assert.assertNotNull(dbVXResponse);
    Assert.assertEquals(userProfile.getStatus(), dbVXResponse.getStatusCode());
    Mockito.verify(stringUtil).equals(Mockito.anyString(), Mockito.nullable(String.class));
    Mockito.verify(stringUtil).validatePassword(Mockito.anyString(), Mockito.any(String[].class));
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 18 with VXResponse

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

the class UserService method validateForUpdate.

@Override
protected void validateForUpdate(VXPortalUser userProfile, XXPortalUser xXPortalUser) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    if (userProfile.getEmailAddress() != null && !userProfile.getEmailAddress().equalsIgnoreCase(xXPortalUser.getEmailAddress())) {
        throw restErrorUtil.createRESTException("serverMsg.userEmail", MessageEnums.DATA_NOT_UPDATABLE, null, "emailAddress", userProfile.getEmailAddress());
    }
    // Login Id can't be changed
    if (userProfile.getLoginId() != null && !xXPortalUser.getLoginId().equalsIgnoreCase(userProfile.getLoginId())) {
        throw restErrorUtil.createRESTException("serverMsg.userUserName", MessageEnums.DATA_NOT_UPDATABLE, null, "loginId", userProfile.getLoginId());
    }
    // }
    userProfile.setFirstName(restErrorUtil.validateStringForUpdate(userProfile.getFirstName(), xXPortalUser.getFirstName(), StringUtil.VALIDATION_NAME, "serverMsg.userFirstName", MessageEnums.INVALID_INPUT_DATA, null, "firstName"));
    userProfile.setFirstName(restErrorUtil.validateStringForUpdate(userProfile.getFirstName(), xXPortalUser.getFirstName(), StringUtil.VALIDATION_NAME, "serverMsg.userFirstName", MessageEnums.INVALID_INPUT_DATA, null, "firstName"));
    userProfile.setLastName(restErrorUtil.validateStringForUpdate(userProfile.getLastName(), xXPortalUser.getLastName(), StringUtil.VALIDATION_NAME, "serverMsg.userLastName", MessageEnums.INVALID_INPUT_DATA, null, "lastName"));
    // firstName
    if (!stringUtil.isValidName(userProfile.getFirstName())) {
        logger.info("Invalid first name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
    }
    // lastName
    if (!stringUtil.isValidName(userProfile.getLastName())) {
        logger.info("Invalid last name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
    }
    userProfile.setNotes(restErrorUtil.validateStringForUpdate(userProfile.getNotes(), xXPortalUser.getNotes(), StringUtil.VALIDATION_NAME, "serverMsg.userNotes", MessageEnums.INVALID_INPUT_DATA, null, "notes"));
    // validate status
    restErrorUtil.validateMinMax(userProfile.getStatus(), 0, RangerConstants.ActivationStatus_MAX, "Invalid status", null, "status");
    // 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(), "serverMsg.userRole", 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 19 with VXResponse

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

the class RESTErrorUtil method createRESTException.

public WebApplicationException createRESTException(String errorMessage, MessageEnums messageEnum, Long objectId, String fieldName, String logMessage, int statusCode) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    messageList.add(messageEnum.getMessage(objectId, fieldName));
    VXResponse vResponse = new VXResponse();
    vResponse.setStatusCode(vResponse.STATUS_ERROR);
    vResponse.setMsgDesc(errorMessage);
    vResponse.setMessageList(messageList);
    Response errorResponse = Response.status(statusCode).entity(vResponse).build();
    WebApplicationException restException = new WebApplicationException(errorResponse);
    restException.fillInStackTrace();
    UserSessionBase userSession = ContextUtil.getCurrentUserSession();
    String loginId = null;
    if (userSession != null) {
        loginId = userSession.getLoginId();
    }
    logger.info("Request failed. loginId=" + loginId + ", logMessage=" + vResponse.getMsgDesc(), restException);
    return restException;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) Response(javax.ws.rs.core.Response) RESTResponse(org.apache.ranger.admin.client.datatype.RESTResponse) VXResponse(org.apache.ranger.view.VXResponse) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXMessage(org.apache.ranger.view.VXMessage)

Example 20 with VXResponse

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

the class RESTErrorUtil method createRESTException.

public WebApplicationException createRESTException(String errorMessage) {
    VXResponse gjResponse = new VXResponse();
    gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
    gjResponse.setMsgDesc(errorMessage);
    WebApplicationException webAppEx = createRESTException(gjResponse);
    logger.info("Operation error. response=" + gjResponse, webAppEx);
    return webAppEx;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) WebApplicationException(javax.ws.rs.WebApplicationException)

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