Search in sources :

Example 1 with AppToUser

use of com.sohu.cache.entity.AppToUser in project cachecloud by sohutv.

the class UserServiceImpl method getByAppId.

@Override
public List<AppUser> getByAppId(Long appId) {
    if (appId == null || appId < 0) {
        return Collections.emptyList();
    }
    List<AppUser> resultList = new ArrayList<AppUser>();
    List<AppToUser> appToUsers = appToUserDao.getByAppId(appId);
    if (appToUsers != null && appToUsers.size() > 0) {
        for (AppToUser appToUser : appToUsers) {
            Long userId = appToUser.getUserId();
            if (userId == null) {
                continue;
            }
            AppUser user = appUserDao.get(userId);
            if (user == null) {
                continue;
            }
            resultList.add(user);
        }
    }
    return resultList;
}
Also used : AppUser(com.sohu.cache.entity.AppUser) AppToUser(com.sohu.cache.entity.AppToUser)

Example 2 with AppToUser

use of com.sohu.cache.entity.AppToUser in project cachecloud by sohutv.

the class BaseController method checkAppUserProvilege.

/**
     * 查看用户对于app操作的权限
     * @param request
     * @param appId
     * @return
     */
protected boolean checkAppUserProvilege(HttpServletRequest request, long appId) {
    // 当前用户
    AppUser currentUser = getUserInfo(request);
    if (currentUser == null) {
        logger.error("currentUser is empty");
        return false;
    }
    if (AppUserTypeEnum.ADMIN_USER.value().equals(currentUser.getType())) {
        return true;
    }
    // 应用用户列表
    List<AppToUser> appToUsers = appService.getAppToUserList(appId);
    if (CollectionUtils.isEmpty(appToUsers)) {
        logger.error("appId {} userList is empty", appId);
        return false;
    }
    // 应用下用户id集合
    Set<Long> appUserIdSet = new HashSet<Long>();
    for (AppToUser appToUser : appToUsers) {
        appUserIdSet.add(appToUser.getUserId());
    }
    //最终判断
    if (!appUserIdSet.contains(currentUser.getId())) {
        logger.error("currentUser {} hasn't previlege in appId {}", currentUser.getId(), appId);
        return false;
    }
    return true;
}
Also used : AppUser(com.sohu.cache.entity.AppUser) AppToUser(com.sohu.cache.entity.AppToUser) HashSet(java.util.HashSet)

Aggregations

AppToUser (com.sohu.cache.entity.AppToUser)2 AppUser (com.sohu.cache.entity.AppUser)2 HashSet (java.util.HashSet)1