use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.
the class JwtAuthenticationTokenFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
LoginUser loginUser = tokenService.getLoginUser(request);
log.info("the current request URI : {}", request.getRequestURL());
if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) {
tokenService.verifyToken(loginUser);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
}
chain.doFilter(request, response);
}
use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.
the class UserOnlineController method list.
@PreAuthorize("@permissionService.hasPermission('monitor:online:list')")
@GetMapping("/list")
public TableDataInfo list(String ip, String userName) {
Collection<String> keys = redisCacheService.keys(Constants.LOGIN_TOKEN_KEY + "*");
List<UserOnline> userOnlineList = new ArrayList<>();
for (String key : keys) {
LoginUser user = redisCacheService.getCacheObject(key);
if (StringUtils.isNotEmpty(ip) && StringUtils.isNotEmpty(userName)) {
if (StringUtils.equals(ip, user.getIp()) && StringUtils.equals(userName, user.getUsername())) {
userOnlineList.add(userOnlineService.selectOnlineByInfo(ip, userName, user));
}
} else if (StringUtils.isNotEmpty(ip)) {
if (StringUtils.equals(ip, user.getIp())) {
userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ip, user));
}
} else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) {
if (StringUtils.equals(userName, user.getUsername())) {
userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
}
} else {
userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
}
}
Collections.reverse(userOnlineList);
userOnlineList.removeAll(Collections.singleton(null));
return getDataTable(userOnlineList);
}
use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.
the class LogAspect method handleLog.
/**
* for log record
*
* @param joinPoint join point
* @param e exception
* @param jsonResult result
* @param cost the time of this method cost
*/
protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult, long cost) {
try {
// get annotation
Log controllerLog = getAnnotationLog(joinPoint);
if (controllerLog == null) {
return;
}
// get current user from servlet
LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
OperateLog operateLog = new OperateLog();
operateLog.setStatus(Constants.SUCCESS);
// get the IP of this request
operateLog.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
// get result with JSON format
operateLog.setJsonResult(JSON.toJSONString(jsonResult));
operateLog.setCost(cost);
operateLog.setUrl(ServletUtils.getRequest().getRequestURI());
if (loginUser != null) {
operateLog.setOperateName(loginUser.getUsername());
}
if (e != null) {
operateLog.setStatus(Constants.FAILED);
operateLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
}
// get the class name
String className = joinPoint.getTarget().getClass().getName();
// get method name
String methodName = joinPoint.getSignature().getName();
operateLog.setMethod(StringUtils.format("{}.{}()", className, methodName));
// get request method
operateLog.setRequestMethod(ServletUtils.getRequest().getMethod());
// set method args
getControllerMethodDescription(joinPoint, controllerLog, operateLog);
// save log
AsyncManager.me().execute(AsyncFactory.recordOperateLog(operateLog));
} catch (Exception exception) {
log.error("get exception in handleLog,{} ", exception.getMessage(), exception);
}
}
use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.
the class UserServiceImpl method refreshTokenClaims.
/**
* 同步刷新Redis缓存
*
* @param id sys_user id
*/
private void refreshTokenClaims(Long id) {
// 更新redis缓存
LoginUser loginUser = SecurityUtils.getLoginUser();
loginUser.setUser(userMapper.selectUserById(id));
tokenService.refreshToken(loginUser);
}
use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.
the class LoginController method getRouters.
/**
* 获取路由信息
*
* @return 路由信息
*/
@GetMapping("getRouters")
public AjaxResult getRouters() {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
// 用户信息
SysUser user = loginUser.getUser();
List<Menu> menus = menuService.selectMenuTreeByUserId(user.getId());
return AjaxResult.success(menuService.buildMenus(menus));
}
Aggregations