Search in sources :

Example 1 with MenuEvent

use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.

the class MenuServiceImpl method updateCurrentMenu.

@Override
public boolean updateCurrentMenu() {
    User currentUser = SecurityUtils.getCurrentUser();
    if (null == currentUser) {
        throw new LoginException(ResponseStatusEnum.USE_LOGIN_ERROR, "当前用户未登录,请登录后重试");
    }
    eventPublisher.publishEvent(new MenuEvent(this, currentUser.getId()));
    return true;
}
Also used : User(com.hb0730.boot.admin.security.model.User) LoginException(com.hb0730.boot.admin.exceptions.LoginException) MenuEvent(com.hb0730.boot.admin.event.menu.MenuEvent)

Example 2 with MenuEvent

use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.

the class MenuServiceImpl method getCurrentMenu.

@SneakyThrows
@Override
public List<TreeMenuDTO> getCurrentMenu() {
    User currentUser = SecurityUtils.getCurrentUser();
    if (null == currentUser) {
        throw new LoginException(ResponseStatusEnum.USE_LOGIN_ERROR, "当前用户未登录,请登录后重试");
    }
    HashOperations<String, Long, List<TreeMenuDTO>> hash = redisTemplate.opsForHash();
    List<TreeMenuDTO> treeMenu = hash.get(RedisConstant.MENU_KEY_PREFIX, currentUser.getId());
    if (CollectionUtil.isEmpty(treeMenu)) {
        eventPublisher.publishEvent(new MenuEvent(this, currentUser.getId()));
    }
    treeMenu = hash.get(RedisConstant.MENU_KEY_PREFIX, currentUser.getId());
    if (CollectionUtil.isEmpty(treeMenu)) {
        return Lists.newArrayList();
    }
    return treeMenu;
}
Also used : TreeMenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO) User(com.hb0730.boot.admin.security.model.User) LoginException(com.hb0730.boot.admin.exceptions.LoginException) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MenuEvent(com.hb0730.boot.admin.event.menu.MenuEvent) SneakyThrows(lombok.SneakyThrows)

Example 3 with MenuEvent

use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.

the class MenuEventListener method onApplicationEvent.

@Override
public void onApplicationEvent(@Nonnull MenuEvent event) {
    Long userId = event.getUserId();
    if (null == userId) {
        return;
    }
    UserDTO user = findUserById(userId);
    if (null == user) {
        return;
    }
    // 
    List<TreeMenuDTO> menu = findMenuByUser(user);
    if (CollectionUtils.isEmpty(menu)) {
        return;
    }
    HashOperations<String, Long, List<TreeMenuDTO>> hash = redisTemplate.opsForHash();
    hash.put(RedisConstant.MENU_KEY_PREFIX, userId, menu);
}
Also used : TreeMenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO) UserDTO(com.hb0730.boot.admin.project.system.user.model.dto.UserDTO) List(java.util.List)

Example 4 with MenuEvent

use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.

the class RolePermissionListener method onApplicationEvent.

@Override
@Async("threadPoolTaskExecutor")
public void onApplicationEvent(@Nonnull RolePermissionEvent event) {
    Long roleId = event.getRoleId();
    Set<UserDetails> onlineUser = getOnlineUserByRoleId(roleId);
    if (CollectionUtils.isEmpty(onlineUser)) {
        return;
    }
    Set<String> usernameList = onlineUser.stream().map(UserDetails::getUsername).collect(Collectors.toSet());
    Map<String, UserDetails> onlineUserMap = onlineUser.stream().collect(Collectors.toMap(UserDetails::getUsername, Function.identity()));
    // 用户
    for (String username : usernameList) {
        UserDTO userDTO = userInfoService.loadUserByUsername(username);
        UserDetails details = onlineUserMap.get(username);
        BeanUtil.copyProperties(userDTO, details);
        // 刷新token
        tokenService.refreshAccessToken((User) details);
        eventPublisher.publishEvent(new MenuEvent(this, userDTO.getId()));
    }
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserDTO(com.hb0730.boot.admin.project.system.user.model.dto.UserDTO) MenuEvent(com.hb0730.boot.admin.event.menu.MenuEvent) Async(org.springframework.scheduling.annotation.Async)

Aggregations

MenuEvent (com.hb0730.boot.admin.event.menu.MenuEvent)3 LoginException (com.hb0730.boot.admin.exceptions.LoginException)2 TreeMenuDTO (com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO)2 UserDTO (com.hb0730.boot.admin.project.system.user.model.dto.UserDTO)2 User (com.hb0730.boot.admin.security.model.User)2 List (java.util.List)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 SneakyThrows (lombok.SneakyThrows)1 Async (org.springframework.scheduling.annotation.Async)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1