Search in sources :

Example 16 with VXPortalUser

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

the class PatchPermissionModel_J10003 method assignPermissions.

private int assignPermissions(List<XXPortalUser> xXPortalUsers) {
    int countUserPermissionUpdated = 0;
    if (!CollectionUtils.isEmpty(xXPortalUsers)) {
        for (XXPortalUser xPortalUser : xXPortalUsers) {
            try {
                if (xPortalUser != null) {
                    VXPortalUser vPortalUser = xPortalUserService.populateViewBean(xPortalUser);
                    if (vPortalUser != null) {
                        vPortalUser.setUserRoleList(daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(vPortalUser.getId()));
                        xUserMgr.assignPermissionToUser(vPortalUser, false);
                        countUserPermissionUpdated += 1;
                        logger.info("Permissions assigned/updated on base of User's Role, UserId [" + xPortalUser.getId() + "]");
                    }
                }
            } catch (Exception ex) {
            }
        }
    }
    return countUserPermissionUpdated;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) IOException(java.io.IOException)

Example 17 with VXPortalUser

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

the class PatchGrantAuditPermissionToKeyRoleUser_J10014 method assignAuditAndUserGroupPermissionToKeyAdminRoleUser.

private void assignAuditAndUserGroupPermissionToKeyAdminRoleUser() {
    try {
        int countUserPermissionUpdated = 0;
        XXModuleDef xAuditModDef = daoManager.getXXModuleDef().findByModuleName(RangerConstants.MODULE_AUDIT);
        XXModuleDef xUserGrpModDef = daoManager.getXXModuleDef().findByModuleName(RangerConstants.MODULE_USER_GROUPS);
        logger.warn("Audit Module Object : " + xAuditModDef);
        logger.warn("USer Group Module Object : " + xUserGrpModDef);
        if (xAuditModDef == null && xUserGrpModDef == null) {
            logger.warn("Audit Module and User Group module not found");
            return;
        }
        List<XXPortalUser> allKeyAdminUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_KEY_ADMIN);
        if (!CollectionUtils.isEmpty(allKeyAdminUsers)) {
            for (XXPortalUser xPortalUser : allKeyAdminUsers) {
                boolean isUserUpdated = false;
                VXPortalUser vPortalUser = xPortalUserService.populateViewBean(xPortalUser);
                if (vPortalUser != null) {
                    vPortalUser.setUserRoleList(daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(vPortalUser.getId()));
                    if (xAuditModDef != null) {
                        xUserMgr.createOrUpdateUserPermisson(vPortalUser, xAuditModDef.getId(), true);
                        isUserUpdated = true;
                        logger.info("Added '" + xAuditModDef.getModule() + "' permission to user '" + xPortalUser.getLoginId() + "'");
                    }
                    if (xUserGrpModDef != null) {
                        xUserMgr.createOrUpdateUserPermisson(vPortalUser, xUserGrpModDef.getId(), true);
                        isUserUpdated = true;
                        logger.info("Added '" + xUserGrpModDef.getModule() + "' permission to user '" + xPortalUser.getLoginId() + "'");
                    }
                    if (isUserUpdated) {
                        countUserPermissionUpdated += 1;
                    }
                }
            }
            logger.info(countUserPermissionUpdated + " permissions were assigned");
        } else {
            logger.info("There are no user with Key Admin role");
        }
    } catch (Exception ex) {
        logger.error("Error while granting Audit and User group permission ", ex);
    }
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser)

Example 18 with VXPortalUser

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

the class ServiceDBStore method validateUserAndProvideTabTagBasedPolicyPermission.

private void validateUserAndProvideTabTagBasedPolicyPermission(String username) {
    XXPortalUser xxPortalUser = daoMgr.getXXPortalUser().findByLoginId(username);
    if (xxPortalUser == null) {
        throw restErrorUtil.createRESTException("Username : " + username + " does not exist. Please provide valid user as service admin for tag service .", MessageEnums.ERROR_CREATING_OBJECT);
    } else {
        VXPortalUser vXPortalUser = userMgr.mapXXPortalUserToVXPortalUserForDefaultAccount(xxPortalUser);
        if (CollectionUtils.isNotEmpty(vXPortalUser.getUserRoleList()) && vXPortalUser.getUserRoleList().size() == 1) {
            for (String userRole : vXPortalUser.getUserRoleList()) {
                if (userRole.equals(RangerConstants.ROLE_USER)) {
                    HashMap<String, Long> moduleNameId = xUserMgr.getAllModuleNameAndIdMap();
                    xUserMgr.createOrUpdateUserPermisson(vXPortalUser, moduleNameId.get(RangerConstants.MODULE_TAG_BASED_POLICIES), true);
                }
            }
        }
    }
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString)

Example 19 with VXPortalUser

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

the class UserMgr method mapXXPortalUserToVXPortalUserForDefaultAccount.

protected VXPortalUser mapXXPortalUserToVXPortalUserForDefaultAccount(XXPortalUser user) {
    VXPortalUser userProfile = new VXPortalUser();
    userProfile.setLoginId(user.getLoginId());
    userProfile.setEmailAddress(user.getEmailAddress());
    userProfile.setStatus(user.getStatus());
    userProfile.setUserRoleList(new ArrayList<String>());
    userProfile.setId(user.getId());
    userProfile.setFirstName(user.getFirstName());
    userProfile.setLastName(user.getLastName());
    userProfile.setPublicScreenName(user.getPublicScreenName());
    userProfile.setOtherAttributes(user.getOtherAttributes());
    userProfile.setSyncSource(user.getSyncSource());
    List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
    for (XXPortalUserRole gjUserRole : gjUserRoleList) {
        userProfile.getUserRoleList().add(gjUserRole.getUserRole());
    }
    return userProfile;
}
Also used : VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole)

Example 20 with VXPortalUser

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

the class UserMgr method searchUsers.

/**
 * @param searchCriteria
 * @return
 */
public VXPortalUserList searchUsers(SearchCriteria searchCriteria) {
    VXPortalUserList returnList = new VXPortalUserList();
    ArrayList<VXPortalUser> objectList = new ArrayList<VXPortalUser>();
    String queryStr = "SELECT u FROM  XXPortalUser u ";
    String countQueryStr = "SELECT COUNT(u) FROM XXPortalUser u ";
    // Get total count first
    Query query = createUserSearchQuery(countQueryStr, null, searchCriteria);
    Long count = (Long) query.getSingleResult();
    int resultSize = count != null ? count.intValue() : 0;
    if (resultSize == 0) {
        return returnList;
    }
    // Get actual data
    // Add sort by
    String sortBy = searchCriteria.getSortBy();
    String querySortBy = "u.loginId";
    if (sortBy != null && !sortBy.trim().isEmpty()) {
        sortBy = sortBy.trim();
        if (sortBy.equalsIgnoreCase("userId")) {
            querySortBy = "u.id";
        } else if (sortBy.equalsIgnoreCase("loginId")) {
            querySortBy = "ua.loginId";
        } else if (sortBy.equalsIgnoreCase("emailAddress")) {
            querySortBy = "u.emailAddress";
        } else if (sortBy.equalsIgnoreCase("firstName")) {
            querySortBy = "u.firstName";
        } else if (sortBy.equalsIgnoreCase("lastName")) {
            querySortBy = "u.lastName";
        } else {
            sortBy = "loginId";
            logger.error("Invalid sortBy provided. sortBy=" + sortBy);
        }
    } else {
        sortBy = "loginId";
    }
    // Default sort field
    String sortClause = " order by " + querySortBy + " ";
    // Add sort type
    String sortType = searchCriteria.getSortType();
    String querySortType = "asc";
    if (sortType != null) {
        if (sortType.equalsIgnoreCase("asc") || sortType.equalsIgnoreCase("desc")) {
            querySortType = sortType;
        } else {
            logger.error("Invalid sortType. sortType=" + sortType);
        }
    }
    sortClause += querySortType;
    query = createUserSearchQuery(queryStr, sortClause, searchCriteria);
    // Set start index
    query.setFirstResult(searchCriteria.getStartIndex());
    searchUtil.updateQueryPageSize(query, searchCriteria);
    @SuppressWarnings("rawtypes") List resultList = query.getResultList();
    // Iterate over the result list and create the return list
    for (Object object : resultList) {
        XXPortalUser gjUser = (XXPortalUser) object;
        VXPortalUser userProfile = new VXPortalUser();
        gjUserToUserProfile(gjUser, userProfile);
        objectList.add(userProfile);
    }
    returnList.setResultSize(resultSize);
    returnList.setPageSize(query.getMaxResults());
    returnList.setSortBy(sortBy);
    returnList.setSortType(querySortType);
    returnList.setStartIndex(query.getFirstResult());
    returnList.setTotalCount(count.longValue());
    returnList.setVXPortalUsers(objectList);
    return returnList;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) Query(javax.persistence.Query) VXPortalUserList(org.apache.ranger.view.VXPortalUserList) ArrayList(java.util.ArrayList) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXPortalUserList(org.apache.ranger.view.VXPortalUserList) List(java.util.List) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString)

Aggregations

VXPortalUser (org.apache.ranger.view.VXPortalUser)129 Test (org.junit.Test)110 XXPortalUser (org.apache.ranger.entity.XXPortalUser)86 VXString (org.apache.ranger.view.VXString)80 ArrayList (java.util.ArrayList)74 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)61 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)49 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)47 XXUserPermission (org.apache.ranger.entity.XXUserPermission)47 VXUser (org.apache.ranger.view.VXUser)33 Date (java.util.Date)29 WebApplicationException (javax.ws.rs.WebApplicationException)29 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)29 XXModuleDef (org.apache.ranger.entity.XXModuleDef)28 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)26 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)24 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)21 XXUserDao (org.apache.ranger.db.XXUserDao)20 XXUser (org.apache.ranger.entity.XXUser)19