Compare commits
No commits in common. "dd9cff155e0b33bfe86e6f6892b1d1babf5fde09" and "458cedb42f3f752fcfeaeff79639e9e739a41fe4" have entirely different histories.
dd9cff155e
...
458cedb42f
@ -7,7 +7,6 @@ package com.cnbm.admin.base;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.cnbm.admin.dto.LoginUserDTO;
|
||||
import com.cnbm.admin.entity.LoginUser;
|
||||
import com.cnbm.admin.enums.WhetherEnum;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -33,18 +32,18 @@ import java.time.LocalDateTime;
|
||||
@Service
|
||||
public class BaseSupport {
|
||||
|
||||
protected LoginUser getLoginUser() {
|
||||
protected LoginUserDTO getLoginUser() {
|
||||
// 后续完善拦截器再使用该方式
|
||||
// LoginUser loginUser = loginUserHolder.get();
|
||||
// if (loginUser != null) {
|
||||
// return loginUser;
|
||||
// }
|
||||
HttpSession session = getHttpServletRequest().getSession(false);
|
||||
LoginUser loginUser = null;
|
||||
LoginUserDTO loginUser = null;
|
||||
if (session != null) {
|
||||
String loginUserJson = (String) session.getAttribute(LoginUser.HTTP_HEADER_NAME);
|
||||
String loginUserJson = (String) session.getAttribute(LoginUserDTO.HTTP_HEADER_NAME);
|
||||
if (StringUtils.isNotBlank(loginUserJson)) {
|
||||
loginUser = JSON.parseObject(loginUserJson, LoginUser.class);
|
||||
loginUser = JSON.parseObject(loginUserJson, LoginUserDTO.class);
|
||||
return loginUser;
|
||||
}
|
||||
}
|
||||
@ -94,11 +93,11 @@ public class BaseSupport {
|
||||
.enabled(WhetherEnum.YES.getValue())
|
||||
.valid(WhetherEnum.YES.getValue())
|
||||
.createTime(LocalDateTime.now())
|
||||
.creatorId(getLoginUser().getSysUserEntity().getId())
|
||||
.creatorName(getLoginUser().getUsername())
|
||||
.creatorId(getLoginUser().getUserId())
|
||||
.creatorName(getLoginUser().getUserName())
|
||||
.updateTime(LocalDateTime.now())
|
||||
.updaterId(getLoginUser().getSysUserEntity().getId())
|
||||
.updaterName(getLoginUser().getUsername())
|
||||
.updaterId(getLoginUser().getUserId())
|
||||
.updaterName(getLoginUser().getUserName())
|
||||
.build();
|
||||
BeanUtils.copyProperties(commonField, t, ignoreProperties);
|
||||
return t;
|
||||
@ -118,8 +117,8 @@ public class BaseSupport {
|
||||
*/
|
||||
public <T extends Serializable> T setUpdateCommonField(T t) {
|
||||
CommonField commonField = CommonField.builder()
|
||||
.updaterId(getLoginUser().getSysUserEntity().getId())
|
||||
.updaterName(getLoginUser().getUsername())
|
||||
.updaterId(getLoginUser().getUserId())
|
||||
.updaterName(getLoginUser().getUserName())
|
||||
.updateTime(LocalDateTime.now())
|
||||
.build();
|
||||
BeanUtils.copyProperties(commonField, t, "enabled", "valid");
|
||||
|
@ -24,8 +24,6 @@ public class LoginUser implements UserDetails{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String HTTP_HEADER_NAME = "loginUser";
|
||||
|
||||
private SysUserEntity sysUserEntity;
|
||||
|
||||
private List<String> permissions;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.cnbm.admin.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.cnbm.admin.dto.LoginUserDTO;
|
||||
import com.cnbm.admin.entity.LoginUser;
|
||||
import com.cnbm.admin.entity.SysLogLoginEntity;
|
||||
import com.cnbm.admin.enums.LoginOperationEnum;
|
||||
@ -24,11 +22,8 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -86,11 +81,6 @@ public class LoginServiceImpl implements LoginService {
|
||||
map.put("token",jwt);
|
||||
//把完整的用户信息存入redis userid作为key
|
||||
redisTemplate.opsForValue().set("login:"+userid,loginUser,1, TimeUnit.DAYS);
|
||||
|
||||
//当前登录用户信息存入session中
|
||||
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
|
||||
session.setAttribute(loginUser.HTTP_HEADER_NAME, JSON.toJSONString(loginUser));
|
||||
|
||||
//登录成功
|
||||
log.setStatus(LoginStatusEnum.SUCCESS.value());
|
||||
log.setCreator(loginUser.getSysUserEntity().getId());
|
||||
|
Loading…
Reference in New Issue
Block a user