Search in sources :

Example 1 with VXMessage

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

the class RESTErrorUtil method createRESTException.

public WebApplicationException createRESTException(String errorMessage, MessageEnums messageEnum, Long objectId, String fieldName, String logMessage) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    messageList.add(messageEnum.getMessage(objectId, fieldName));
    VXResponse gjResponse = new VXResponse();
    gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
    gjResponse.setMsgDesc(errorMessage);
    gjResponse.setMessageList(messageList);
    WebApplicationException webAppEx = createRESTException(gjResponse);
    logger.info("Validation error:logMessage=" + logMessage + ", response=" + gjResponse, webAppEx);
    return webAppEx;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXMessage(org.apache.ranger.view.VXMessage)

Example 2 with VXMessage

use of org.apache.ranger.view.VXMessage 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 3 with VXMessage

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

the class ServiceMgr method generateResponseForTestConn.

private VXResponse generateResponseForTestConn(Map<String, Object> responseData, String msg) {
    VXResponse vXResponse = new VXResponse();
    Long objId = null;
    boolean connectivityStatus = false;
    int statusCode = VXResponse.STATUS_ERROR;
    String message = msg;
    String description = msg;
    String fieldName = null;
    if (responseData != null) {
        if (responseData.get("objectId") != null) {
            objId = Long.parseLong(responseData.get("objectId").toString());
        }
        if (responseData.get("connectivityStatus") != null) {
            connectivityStatus = Boolean.parseBoolean(responseData.get("connectivityStatus").toString());
        }
        if (connectivityStatus) {
            statusCode = VXResponse.STATUS_SUCCESS;
        }
        if (responseData.get("message") != null) {
            message = responseData.get("message").toString();
        }
        if (responseData.get("description") != null) {
            description = responseData.get("description").toString();
        }
        if (responseData.get("fieldName") != null) {
            fieldName = responseData.get("fieldName").toString();
        }
    }
    VXMessage vXMsg = new VXMessage();
    List<VXMessage> vXMsgList = new ArrayList<VXMessage>();
    vXMsg.setFieldName(fieldName);
    vXMsg.setMessage(message);
    vXMsg.setObjectId(objId);
    vXMsgList.add(vXMsg);
    vXResponse.setMessageList(vXMsgList);
    vXResponse.setMsgDesc(description);
    vXResponse.setStatusCode(statusCode);
    return vXResponse;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) ArrayList(java.util.ArrayList) VXMessage(org.apache.ranger.view.VXMessage)

Example 4 with VXMessage

use of org.apache.ranger.view.VXMessage 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 5 with VXMessage

use of org.apache.ranger.view.VXMessage 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)

Aggregations

ArrayList (java.util.ArrayList)7 VXMessage (org.apache.ranger.view.VXMessage)7 VXResponse (org.apache.ranger.view.VXResponse)7 WebApplicationException (javax.ws.rs.WebApplicationException)3 Response (javax.ws.rs.core.Response)1 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)1