Search in sources :

Example 6 with User

use of com.hb0730.boot.admin.security.model.User 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 7 with User

use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.

the class BaseServiceImpl method update.

@Override
public boolean update(Wrapper<ENTITY> updateWrapper) {
    if (updateWrapper instanceof UpdateWrapper) {
        UpdateWrapper<ENTITY> update = (UpdateWrapper<ENTITY>) updateWrapper;
        update.set(BusinessDomain.UPDATE_TIME, LocalDateTime.now());
        // 设置用户
        User currentUser = SecurityUtils.getCurrentUser();
        if (null != currentUser) {
            update.set(BusinessDomain.UPDATE_USER_ID, currentUser.getId());
        }
    }
    return super.update(updateWrapper);
}
Also used : User(com.hb0730.boot.admin.security.model.User) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)

Example 8 with User

use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.

the class UserAccountControllerTest method pageTest.

@Override
@Test
@WithMockUser("user")
public void pageTest() {
    try {
        MvcResult result = mvc.perform(MockMvcRequestBuilders.post("/system/user/account/list/page").accept(MediaType.APPLICATION_JSON_UTF8).contentType(MediaType.APPLICATION_JSON_UTF8).content(JsonUtils.objectToJson(new UserAccountParams()))).andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print()).andReturn();
        Assert.assertNotNull(result);
        String resultContent = result.getResponse().getContentAsString();
        log.info(resultContent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserAccountParams(com.hb0730.boot.admin.project.system.user.model.query.UserAccountParams) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProjectTest(com.hb0730.boot.admin.project.ProjectTest)

Example 9 with User

use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.

the class LogoutSuccessHandlerImpl method onLogoutSuccess.

@SneakyThrows
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    LOGGER.debug("logout success <<<<<");
    User loginUser = tokenService.getLoginUser(request);
    if (null != loginUser) {
        tokenService.delLoginUser(request);
        AsyncManager.me().execute(AsyncFactory.recordLoginLog(loginUser.getUsername(), StatusEnum.SUCCESS, "登出成功"));
    }
    Result<String> result = R.success("注销成功");
    response.setStatus(200);
    response.setContentType("application/json");
    response.setCharacterEncoding("utf-8");
    response.getWriter().print(JsonUtils.objectToJson(result));
}
Also used : User(com.hb0730.boot.admin.security.model.User) SneakyThrows(lombok.SneakyThrows)

Example 10 with User

use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.

the class RedisTokenServiceImpl method getOnline.

@Override
public Map<String, UserDetails> getOnline() {
    Map<String, UserDetails> maps = Maps.newHashMap();
    try {
        Set<String> keys = stringRedisTemplate.keys(getAccessTokenKey("*"));
        if (CollectionUtils.isEmpty(keys)) {
            return maps;
        }
        for (String key : keys) {
            String accessToken = org.apache.commons.lang3.StringUtils.remove(key, LOGIN_TOKEN_KEY_PREFIX);
            String tokenKey = stringRedisTemplate.opsForValue().get(getAccessTokenKey(accessToken));
            if (StrUtil.isNotBlank(tokenKey)) {
                User cacheUser = redisTemplate.opsForValue().get(getUserTokenKey(tokenKey));
                maps.put(accessToken, cacheUser);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return maps;
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) User(com.hb0730.boot.admin.security.model.User)

Aggregations

User (com.hb0730.boot.admin.security.model.User)13 List (java.util.List)4 MenuEvent (com.hb0730.boot.admin.event.menu.MenuEvent)3 LoginException (com.hb0730.boot.admin.exceptions.LoginException)3 TreeMenuDTO (com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO)3 UserDTO (com.hb0730.boot.admin.project.system.user.model.dto.UserDTO)3 UserDetails (org.springframework.security.core.userdetails.UserDetails)3 PermissionEntity (com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity)2 LoginUser (com.hb0730.boot.admin.security.model.LoginUser)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SneakyThrows (lombok.SneakyThrows)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 RequestAttributes (org.springframework.web.context.request.RequestAttributes)2 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)2 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)1 ClassDescribe (com.hb0730.boot.admin.annotation.ClassDescribe)1 Log (com.hb0730.boot.admin.annotation.Log)1