Search in sources :

Example 31 with VXResponse

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

the class UserREST method changePassword.

/**
 * @param userId
 * @param changePassword
 * @return
 */
@POST
@Path("{userId}/passwordchange")
@Produces({ "application/xml", "application/json" })
public VXResponse changePassword(@PathParam("userId") Long userId, VXPasswordChange changePassword) {
    if (changePassword == null || stringUtil.isEmpty(changePassword.getLoginId())) {
        logger.warn("SECURITY:changePassword(): Invalid loginId provided. loginId was empty or null");
        throw restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, "");
    }
    logger.info("changePassword:" + changePassword.getLoginId());
    XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(changePassword.getLoginId());
    if (gjUser == null) {
        logger.warn("SECURITY:changePassword(): Invalid loginId provided: loginId=" + changePassword.getLoginId());
        throw restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId());
    }
    userManager.checkAccessForUpdate(gjUser);
    changePassword.setId(gjUser.getId());
    VXResponse ret = userManager.changePassword(changePassword);
    return ret;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 32 with VXResponse

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

the class CustomLogoutSuccessHandler method onLogoutSuccess.

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    request.getServletContext().removeAttribute(request.getRequestedSessionId());
    response.setContentType("application/json;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("X-Frame-Options", "DENY");
    String jsonStr = "";
    try {
        VXResponse vXResponse = new VXResponse();
        vXResponse.setStatusCode(HttpServletResponse.SC_OK);
        vXResponse.setMsgDesc("Logout Successful");
        jsonStr = jsonUtil.writeObjectAsString(vXResponse);
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().write(jsonStr);
        if (logger.isDebugEnabled()) {
            logger.debug("Log-out Successfully done. Returning Json : " + jsonStr);
        }
    } catch (IOException e) {
        logger.info("Error while writing JSON in HttpServletResponse");
    }
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) IOException(java.io.IOException)

Example 33 with VXResponse

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

the class RangerAuthFailureHandler method onAuthenticationFailure.

/*
     * (non-Javadoc)
     *
     * @see org.springframework.security.web.authentication.
     * ExceptionMappingAuthenticationFailureHandler
     * #onAuthenticationFailure(javax.servlet.http.HttpServletRequest,
     * javax.servlet.http.HttpServletResponse,
     * org.springframework.security.core.AuthenticationException)
     */
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
    String ajaxRequestHeader = request.getHeader("X-Requested-With");
    if (logger.isDebugEnabled()) {
        logger.debug("commence() X-Requested-With=" + ajaxRequestHeader);
    }
    response.setContentType("application/json;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("X-Frame-Options", "DENY");
    String jsonResp = "";
    try {
        String msg = exception.getMessage();
        VXResponse vXResponse = new VXResponse();
        if (msg != null && !msg.isEmpty()) {
            if (CLIUtil.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", request).equalsIgnoreCase(msg)) {
                vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
                vXResponse.setMsgDesc("The username or password you entered is incorrect...");
                logger.info("Error Message : " + msg);
            } else if (msg.contains("Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!")) {
                vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
                vXResponse.setMsgDesc("Unable to connect to DB...");
            } else if (msg.contains("Communications link failure")) {
                vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
                vXResponse.setMsgDesc("Unable to connect to DB...");
            } else if (CLIUtil.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", request).equalsIgnoreCase(msg)) {
                vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
                vXResponse.setMsgDesc("The username or password you entered is disable...");
            }
        }
        jsonResp = jsonUtil.writeObjectAsString(vXResponse);
        response.getWriter().write(jsonResp);
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    } catch (IOException e) {
        logger.info("Error while writing JSON in HttpServletResponse");
    }
    if (ajaxRequestHeader != null && "XMLHttpRequest".equalsIgnoreCase(ajaxRequestHeader)) {
        // response);
        if (logger.isDebugEnabled()) {
            logger.debug("Sending login failed response : " + jsonResp);
        }
    }
// else {
// super.onAuthenticationFailure(request, response, exception);
// }
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) IOException(java.io.IOException)

Example 34 with VXResponse

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

the class UserService method validateForCreate.

@Override
protected void validateForCreate(VXPortalUser userProfile) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    if (stringUtil.isEmpty(userProfile.getEmailAddress())) {
        logger.info("Empty Email Address." + userProfile);
        messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "emailAddress"));
    }
    if (stringUtil.isEmpty(userProfile.getFirstName())) {
        logger.info("Empty firstName." + userProfile);
        messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "firstName"));
    }
    if (stringUtil.isEmpty(userProfile.getLastName())) {
        logger.info("Empty lastName." + userProfile);
        messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "lastName"));
    }
    // firstName
    if (!stringUtil.isValidName(userProfile.getFirstName())) {
        logger.info("Invalid first name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
    }
    userProfile.setFirstName(stringUtil.toCamelCaseAllWords(userProfile.getFirstName()));
    // lastName
    if (!stringUtil.isValidName(userProfile.getLastName())) {
        logger.info("Invalid last name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
    }
    userProfile.setLastName(stringUtil.toCamelCaseAllWords(userProfile.getLastName()));
    if (!stringUtil.validateEmail(userProfile.getEmailAddress())) {
        logger.info("Invalid email address." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "emailAddress"));
    }
    // Normalize email. Make it lower case
    userProfile.setEmailAddress(stringUtil.normalizeEmail(userProfile.getEmailAddress()));
    // loginId
    userProfile.setLoginId(userProfile.getEmailAddress());
    // password
    if (!stringUtil.validatePassword(userProfile.getPassword(), new String[] { userProfile.getFirstName(), userProfile.getLastName() })) {
        logger.info("Invalid password." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "password"));
    }
    // firstName
    if (!stringUtil.validateString(StringUtil.VALIDATION_NAME, userProfile.getFirstName())) {
        logger.info("Invalid first name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
    }
    // lastName
    if (!stringUtil.validateString(StringUtil.VALIDATION_NAME, userProfile.getLastName())) {
        logger.info("Invalid last name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
    }
    // create the public screen name
    userProfile.setPublicScreenName(userProfile.getFirstName() + " " + userProfile.getLastName());
    if (!messageList.isEmpty()) {
        VXResponse gjResponse = new VXResponse();
        gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
        gjResponse.setMsgDesc("Validation failure");
        gjResponse.setMessageList(messageList);
        logger.info("Validation Error in createUser() 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 35 with VXResponse

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

the class XResourceService method searchXResources.

@Override
public VXResourceList searchXResources(SearchCriteria searchCriteria) {
    VXResourceList returnList;
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    // If user is system admin
    if (currentUserSession.isUserAdmin()) {
        returnList = super.searchXResources(searchCriteria);
    } else {
        // need to be optimize
        returnList = new VXResourceList();
        int startIndex = searchCriteria.getStartIndex();
        int pageSize = searchCriteria.getMaxRows();
        searchCriteria.setStartIndex(0);
        searchCriteria.setMaxRows(Integer.MAX_VALUE);
        List<XXResource> resultList = (List<XXResource>) searchResources(searchCriteria, searchFields, sortFields, returnList);
        List<XXResource> adminPermResourceList = new ArrayList<XXResource>();
        for (XXResource xXResource : resultList) {
            VXResponse vXResponse = xaBizUtil.hasPermission(populateViewBean(xXResource), AppConstants.XA_PERM_TYPE_ADMIN);
            if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
                adminPermResourceList.add(xXResource);
            }
        }
        if (!adminPermResourceList.isEmpty()) {
            populatePageList(adminPermResourceList, startIndex, pageSize, returnList);
        }
    }
    if (returnList != null && returnList.getResultSize() > 0) {
        for (VXResource vXResource : returnList.getVXResources()) {
            populateAuditList(vXResource);
        }
    }
    return returnList;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) VXResourceList(org.apache.ranger.view.VXResourceList) XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) List(java.util.List) UserSessionBase(org.apache.ranger.common.UserSessionBase)

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