zelong.shao

manager|登出

......@@ -9,6 +9,7 @@ import com.fedex.connect.manager.config.PropertiesConfig;
import com.fedex.connect.manager.service.bi.IDicEntriesService;
import com.fedex.connect.manager.service.log.ILogLoginService;
import com.fedex.connect.manager.service.sys.IPrivilegeService;
import com.fedex.connect.manager.service.sys.IRedisUtilService;
import com.fedex.connect.manager.service.sys.ISysAuthService;
import com.fedex.connect.manager.service.sys.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -35,6 +36,8 @@ public class BaseController extends BasicController {
protected IDicEntriesService dicEntriesService;
@Autowired
protected IPrivilegeService privilegeService;
@Autowired
protected IRedisUtilService redisUtilService;
public User getCurrentUserInfo(){
User user = this.getUserInfo(localeMessageUtil);
......
package com.fedex.connect.manager.controller.sys.impl;
import com.fedex.connect.common.dependencies.authentication.SecurityConstants;
import com.fedex.connect.common.dependencies.cache.CacheSystem;
import com.fedex.connect.common.dependencies.contants.RedisConstants;
import com.fedex.connect.common.dependencies.date.vo.ResponseVo;
import com.fedex.connect.common.dependencies.enums.sys.ParamConfigEnum;
import com.fedex.connect.common.dependencies.enums.sys.UserLoginTypeEnum;
import com.fedex.connect.common.dependencies.util.GsonUtils;
import com.fedex.connect.common.dependencies.util.JwtTokenUtils;
import com.fedex.connect.common.dependencies.util.StringExtUtil;
import com.fedex.connect.common.model.bi.DictionaryEntries;
import com.fedex.connect.common.model.sys.User;
......@@ -17,12 +20,18 @@ import com.fedex.connect.manager.data.dto.LoginRequest;
import com.fedex.connect.manager.data.dto.SysUserDto;
import com.fedex.connect.manager.util.ParamConfigUtil;
import com.google.gson.JsonObject;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.JwtException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -220,4 +229,54 @@ public class SysAuthController extends BaseController implements ISysAuthControl
log.info(s+":"+parameter);
}
}
@PostMapping(value = "/logout")
@ApiOperation(value = "登出")
public ResponseVo logOut(HttpServletRequest request, HttpServletResponse response) throws Exception{
log.info("user logout");
ResponseVo resultRS = new ResponseVo();
String id = "";
try {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
new SecurityContextLogoutHandler().logout(request, response, auth);
}
resultRS.setCode(HttpServletResponse.SC_OK);
resultRS.setMsg(localeMessageUtil.getMessage("system_exception_40007"));
//清理redis中token
String token = request.getHeader(SecurityConstants.TOKEN_HEADER);
if(!org.springframework.util.StringUtils.isEmpty(token)){
id = JwtTokenUtils.getId(token.replace(SecurityConstants.TOKEN_PREFIX, ""));
redisUtilService.del(RedisConstants.REDIS_KEY_TOKEN + id);
}
} catch (ExpiredJwtException ee) {
log.error("登出1失败!",ee);
Claims claims = ee.getClaims();
id = claims.getId();
redisUtilService.del(RedisConstants.REDIS_KEY_TOKEN + id);
return resultRS;
} catch (JwtException je){
log.error("登出2失败!",je);
return resultRS;
} catch (Exception e) {
log.error("登出3失败",e);
resultRS.setMsg(localeMessageUtil.getMessage("system_exception_40008"));
resultRS.setCode(HttpServletResponse.SC_BAD_REQUEST);
} finally {
if (!org.springframework.util.StringUtils.isEmpty(id)){
log.info("redis token get userid:"+id);
//插入日志
User sysUser = sysUserService.findById(Long.parseLong(id));
DictionaryEntries dicUserLoginType = cacheSystem.getDicUserLoginType(UserLoginTypeEnum.EXIT.getCode());
LogLoginDto dto = new LogLoginDto(sysUser.getId(), dicUserLoginType.getId(),
UserLoginTypeEnum.EXIT.getMsg());
logLoginService.saveLoginLog(dto);
}
}
return resultRS;
}
}
......
......@@ -13,6 +13,7 @@ public enum ResponseCode {
MESSAGE_CODE_40004(40004,"system_exception_40004"),
MESSAGE_CODE_40005(40005,"system_exception_40005"),
MESSAGE_CODE_40006(40006,"system_exception_40006"),
MESSAGE_CODE_40007(40007,"system_exception_40007"),
;
private Integer code;
private String msg;
......
......@@ -11,4 +11,6 @@ public interface IUserRepository {
int insert(User record);
int updateByPrimaryKeySelective(User record);
User findById(Long id);
}
......
......@@ -25,4 +25,9 @@ public class UserExtRepositoryImpl extends BaseDao implements IUserRepository {
public int updateByPrimaryKeySelective(User record) {
return userMapper.updateByPrimaryKeySelective(record);
}
@Override
public User findById(Long id) {
return userMapper.selectByPrimaryKey(id);
}
}
......
......@@ -14,4 +14,6 @@ public interface ISysUserService {
int update(User dao);
void getFclData(HttpServletRequest request,List<String> cookiesList,List<String> saveKeyList);
User findById(Long id);
}
......
......@@ -190,5 +190,10 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService {
}
}
@Override
public User findById(Long id) {
return userRepository.findById(id);
}
}
......
......@@ -50,7 +50,7 @@ url:
fcl:
login:
url: http://exportdeclarationuat-tw.dmz.apac.fedex.com/icleartw/auth/wlgnLogin
redjrectLogin: https://exportdeclarationuat-tw.dmz.apac.fedex.com/IcTw/#/redjrectLogin
redjrectLogin: http://localhost:8080/ImpPer/#/redjrectLogin
twidx:
url: http://exportdeclarationuat-tw.apac.fedex.com
interface:
......
......@@ -14,4 +14,6 @@ business_log_40002=用户登录
system_exception_40003=系统异常,请联系清关部门
system_exception_40004=登录已过期,请重新登录
system_exception_40005=用戶不存在
system_exception_40006=登录已过期
\ No newline at end of file
system_exception_40006=登录已过期
system_exception_40007=退出成功
system_exception_40008=退出失败
\ No newline at end of file
......
......@@ -14,4 +14,6 @@ business_log_40002=用户登录
system_exception_40003=系统异常,请联系清关部门
system_exception_40004=登录已过期,请重新登录
system_exception_40005=用戶不存在
system_exception_40006=登录已过期
\ No newline at end of file
system_exception_40006=登录已过期
system_exception_40007=退出成功
system_exception_40008=退出失败
\ No newline at end of file
......