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;
}
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);
}
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();
}
}
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));
}
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;
}
Aggregations