Showing
10 changed files
with
82 additions
and
1 deletions
| ... | @@ -9,6 +9,7 @@ import com.fedex.connect.manager.config.PropertiesConfig; | ... | @@ -9,6 +9,7 @@ import com.fedex.connect.manager.config.PropertiesConfig; |
| 9 | import com.fedex.connect.manager.service.bi.IDicEntriesService; | 9 | import com.fedex.connect.manager.service.bi.IDicEntriesService; |
| 10 | import com.fedex.connect.manager.service.log.ILogLoginService; | 10 | import com.fedex.connect.manager.service.log.ILogLoginService; |
| 11 | import com.fedex.connect.manager.service.sys.IPrivilegeService; | 11 | import com.fedex.connect.manager.service.sys.IPrivilegeService; |
| 12 | +import com.fedex.connect.manager.service.sys.IRedisUtilService; | ||
| 12 | import com.fedex.connect.manager.service.sys.ISysAuthService; | 13 | import com.fedex.connect.manager.service.sys.ISysAuthService; |
| 13 | import com.fedex.connect.manager.service.sys.ISysUserService; | 14 | import com.fedex.connect.manager.service.sys.ISysUserService; |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | @@ -35,6 +36,8 @@ public class BaseController extends BasicController { | ... | @@ -35,6 +36,8 @@ public class BaseController extends BasicController { |
| 35 | protected IDicEntriesService dicEntriesService; | 36 | protected IDicEntriesService dicEntriesService; |
| 36 | @Autowired | 37 | @Autowired |
| 37 | protected IPrivilegeService privilegeService; | 38 | protected IPrivilegeService privilegeService; |
| 39 | + @Autowired | ||
| 40 | + protected IRedisUtilService redisUtilService; | ||
| 38 | 41 | ||
| 39 | public User getCurrentUserInfo(){ | 42 | public User getCurrentUserInfo(){ |
| 40 | User user = this.getUserInfo(localeMessageUtil); | 43 | User user = this.getUserInfo(localeMessageUtil); | ... | ... |
| 1 | package com.fedex.connect.manager.controller.sys.impl; | 1 | package com.fedex.connect.manager.controller.sys.impl; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import com.fedex.connect.common.dependencies.authentication.SecurityConstants; | ||
| 4 | import com.fedex.connect.common.dependencies.cache.CacheSystem; | 5 | import com.fedex.connect.common.dependencies.cache.CacheSystem; |
| 6 | +import com.fedex.connect.common.dependencies.contants.RedisConstants; | ||
| 5 | import com.fedex.connect.common.dependencies.date.vo.ResponseVo; | 7 | import com.fedex.connect.common.dependencies.date.vo.ResponseVo; |
| 6 | import com.fedex.connect.common.dependencies.enums.sys.ParamConfigEnum; | 8 | import com.fedex.connect.common.dependencies.enums.sys.ParamConfigEnum; |
| 7 | import com.fedex.connect.common.dependencies.enums.sys.UserLoginTypeEnum; | 9 | import com.fedex.connect.common.dependencies.enums.sys.UserLoginTypeEnum; |
| 8 | import com.fedex.connect.common.dependencies.util.GsonUtils; | 10 | import com.fedex.connect.common.dependencies.util.GsonUtils; |
| 11 | +import com.fedex.connect.common.dependencies.util.JwtTokenUtils; | ||
| 9 | import com.fedex.connect.common.dependencies.util.StringExtUtil; | 12 | import com.fedex.connect.common.dependencies.util.StringExtUtil; |
| 10 | import com.fedex.connect.common.model.bi.DictionaryEntries; | 13 | import com.fedex.connect.common.model.bi.DictionaryEntries; |
| 11 | import com.fedex.connect.common.model.sys.User; | 14 | import com.fedex.connect.common.model.sys.User; |
| ... | @@ -17,12 +20,18 @@ import com.fedex.connect.manager.data.dto.LoginRequest; | ... | @@ -17,12 +20,18 @@ import com.fedex.connect.manager.data.dto.LoginRequest; |
| 17 | import com.fedex.connect.manager.data.dto.SysUserDto; | 20 | import com.fedex.connect.manager.data.dto.SysUserDto; |
| 18 | import com.fedex.connect.manager.util.ParamConfigUtil; | 21 | import com.fedex.connect.manager.util.ParamConfigUtil; |
| 19 | import com.google.gson.JsonObject; | 22 | import com.google.gson.JsonObject; |
| 23 | +import io.jsonwebtoken.Claims; | ||
| 24 | +import io.jsonwebtoken.ExpiredJwtException; | ||
| 25 | +import io.jsonwebtoken.JwtException; | ||
| 20 | import io.swagger.annotations.Api; | 26 | import io.swagger.annotations.Api; |
| 21 | import io.swagger.annotations.ApiOperation; | 27 | import io.swagger.annotations.ApiOperation; |
| 22 | import lombok.extern.slf4j.Slf4j; | 28 | import lombok.extern.slf4j.Slf4j; |
| 23 | import org.apache.commons.lang3.StringUtils; | 29 | import org.apache.commons.lang3.StringUtils; |
| 24 | import org.springframework.beans.factory.annotation.Autowired; | 30 | import org.springframework.beans.factory.annotation.Autowired; |
| 25 | import org.springframework.beans.factory.annotation.Value; | 31 | import org.springframework.beans.factory.annotation.Value; |
| 32 | +import org.springframework.security.core.Authentication; | ||
| 33 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
| 34 | +import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; | ||
| 26 | import org.springframework.web.bind.annotation.GetMapping; | 35 | import org.springframework.web.bind.annotation.GetMapping; |
| 27 | import org.springframework.web.bind.annotation.PostMapping; | 36 | import org.springframework.web.bind.annotation.PostMapping; |
| 28 | import org.springframework.web.bind.annotation.RequestMapping; | 37 | import org.springframework.web.bind.annotation.RequestMapping; |
| ... | @@ -220,4 +229,54 @@ public class SysAuthController extends BaseController implements ISysAuthControl | ... | @@ -220,4 +229,54 @@ public class SysAuthController extends BaseController implements ISysAuthControl |
| 220 | log.info(s+":"+parameter); | 229 | log.info(s+":"+parameter); |
| 221 | } | 230 | } |
| 222 | } | 231 | } |
| 232 | + | ||
| 233 | + @PostMapping(value = "/logout") | ||
| 234 | + @ApiOperation(value = "登出") | ||
| 235 | + public ResponseVo logOut(HttpServletRequest request, HttpServletResponse response) throws Exception{ | ||
| 236 | + log.info("user logout"); | ||
| 237 | + | ||
| 238 | + ResponseVo resultRS = new ResponseVo(); | ||
| 239 | + String id = ""; | ||
| 240 | + try { | ||
| 241 | + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
| 242 | + if (auth != null) { | ||
| 243 | + new SecurityContextLogoutHandler().logout(request, response, auth); | ||
| 244 | + } | ||
| 245 | + resultRS.setCode(HttpServletResponse.SC_OK); | ||
| 246 | + resultRS.setMsg(localeMessageUtil.getMessage("system_exception_40007")); | ||
| 247 | + //清理redis中token | ||
| 248 | + String token = request.getHeader(SecurityConstants.TOKEN_HEADER); | ||
| 249 | + | ||
| 250 | + if(!org.springframework.util.StringUtils.isEmpty(token)){ | ||
| 251 | + id = JwtTokenUtils.getId(token.replace(SecurityConstants.TOKEN_PREFIX, "")); | ||
| 252 | + redisUtilService.del(RedisConstants.REDIS_KEY_TOKEN + id); | ||
| 253 | + } | ||
| 254 | + } catch (ExpiredJwtException ee) { | ||
| 255 | + log.error("登出1失败!",ee); | ||
| 256 | + | ||
| 257 | + Claims claims = ee.getClaims(); | ||
| 258 | + id = claims.getId(); | ||
| 259 | + redisUtilService.del(RedisConstants.REDIS_KEY_TOKEN + id); | ||
| 260 | + return resultRS; | ||
| 261 | + } catch (JwtException je){ | ||
| 262 | + log.error("登出2失败!",je); | ||
| 263 | + | ||
| 264 | + return resultRS; | ||
| 265 | + } catch (Exception e) { | ||
| 266 | + log.error("登出3失败",e); | ||
| 267 | + resultRS.setMsg(localeMessageUtil.getMessage("system_exception_40008")); | ||
| 268 | + resultRS.setCode(HttpServletResponse.SC_BAD_REQUEST); | ||
| 269 | + } finally { | ||
| 270 | + if (!org.springframework.util.StringUtils.isEmpty(id)){ | ||
| 271 | + log.info("redis token get userid:"+id); | ||
| 272 | + //插入日志 | ||
| 273 | + User sysUser = sysUserService.findById(Long.parseLong(id)); | ||
| 274 | + DictionaryEntries dicUserLoginType = cacheSystem.getDicUserLoginType(UserLoginTypeEnum.EXIT.getCode()); | ||
| 275 | + LogLoginDto dto = new LogLoginDto(sysUser.getId(), dicUserLoginType.getId(), | ||
| 276 | + UserLoginTypeEnum.EXIT.getMsg()); | ||
| 277 | + logLoginService.saveLoginLog(dto); | ||
| 278 | + } | ||
| 279 | + } | ||
| 280 | + return resultRS; | ||
| 281 | + } | ||
| 223 | } | 282 | } | ... | ... |
| ... | @@ -13,6 +13,7 @@ public enum ResponseCode { | ... | @@ -13,6 +13,7 @@ public enum ResponseCode { |
| 13 | MESSAGE_CODE_40004(40004,"system_exception_40004"), | 13 | MESSAGE_CODE_40004(40004,"system_exception_40004"), |
| 14 | MESSAGE_CODE_40005(40005,"system_exception_40005"), | 14 | MESSAGE_CODE_40005(40005,"system_exception_40005"), |
| 15 | MESSAGE_CODE_40006(40006,"system_exception_40006"), | 15 | MESSAGE_CODE_40006(40006,"system_exception_40006"), |
| 16 | + MESSAGE_CODE_40007(40007,"system_exception_40007"), | ||
| 16 | ; | 17 | ; |
| 17 | private Integer code; | 18 | private Integer code; |
| 18 | private String msg; | 19 | private String msg; | ... | ... |
| ... | @@ -11,4 +11,6 @@ public interface IUserRepository { | ... | @@ -11,4 +11,6 @@ public interface IUserRepository { |
| 11 | int insert(User record); | 11 | int insert(User record); |
| 12 | 12 | ||
| 13 | int updateByPrimaryKeySelective(User record); | 13 | int updateByPrimaryKeySelective(User record); |
| 14 | + | ||
| 15 | + User findById(Long id); | ||
| 14 | } | 16 | } | ... | ... |
| ... | @@ -25,4 +25,9 @@ public class UserExtRepositoryImpl extends BaseDao implements IUserRepository { | ... | @@ -25,4 +25,9 @@ public class UserExtRepositoryImpl extends BaseDao implements IUserRepository { |
| 25 | public int updateByPrimaryKeySelective(User record) { | 25 | public int updateByPrimaryKeySelective(User record) { |
| 26 | return userMapper.updateByPrimaryKeySelective(record); | 26 | return userMapper.updateByPrimaryKeySelective(record); |
| 27 | } | 27 | } |
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public User findById(Long id) { | ||
| 31 | + return userMapper.selectByPrimaryKey(id); | ||
| 32 | + } | ||
| 28 | } | 33 | } | ... | ... |
| ... | @@ -14,4 +14,6 @@ public interface ISysUserService { | ... | @@ -14,4 +14,6 @@ public interface ISysUserService { |
| 14 | int update(User dao); | 14 | int update(User dao); |
| 15 | 15 | ||
| 16 | void getFclData(HttpServletRequest request,List<String> cookiesList,List<String> saveKeyList); | 16 | void getFclData(HttpServletRequest request,List<String> cookiesList,List<String> saveKeyList); |
| 17 | + | ||
| 18 | + User findById(Long id); | ||
| 17 | } | 19 | } | ... | ... |
| ... | @@ -190,5 +190,10 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService { | ... | @@ -190,5 +190,10 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService { |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | + @Override | ||
| 194 | + public User findById(Long id) { | ||
| 195 | + return userRepository.findById(id); | ||
| 196 | + } | ||
| 197 | + | ||
| 193 | 198 | ||
| 194 | } | 199 | } | ... | ... |
| ... | @@ -50,7 +50,7 @@ url: | ... | @@ -50,7 +50,7 @@ url: |
| 50 | fcl: | 50 | fcl: |
| 51 | login: | 51 | login: |
| 52 | url: http://exportdeclarationuat-tw.dmz.apac.fedex.com/icleartw/auth/wlgnLogin | 52 | url: http://exportdeclarationuat-tw.dmz.apac.fedex.com/icleartw/auth/wlgnLogin |
| 53 | - redjrectLogin: https://exportdeclarationuat-tw.dmz.apac.fedex.com/IcTw/#/redjrectLogin | 53 | + redjrectLogin: http://localhost:8080/ImpPer/#/redjrectLogin |
| 54 | twidx: | 54 | twidx: |
| 55 | url: http://exportdeclarationuat-tw.apac.fedex.com | 55 | url: http://exportdeclarationuat-tw.apac.fedex.com |
| 56 | interface: | 56 | interface: | ... | ... |
| ... | @@ -15,3 +15,5 @@ system_exception_40003=系统异常,请联系清关部门 | ... | @@ -15,3 +15,5 @@ system_exception_40003=系统异常,请联系清关部门 |
| 15 | system_exception_40004=登录已过期,请重新登录 | 15 | system_exception_40004=登录已过期,请重新登录 |
| 16 | system_exception_40005=用戶不存在 | 16 | system_exception_40005=用戶不存在 |
| 17 | system_exception_40006=登录已过期 | 17 | system_exception_40006=登录已过期 |
| 18 | +system_exception_40007=退出成功 | ||
| 19 | +system_exception_40008=退出失败 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -15,3 +15,5 @@ system_exception_40003=系统异常,请联系清关部门 | ... | @@ -15,3 +15,5 @@ system_exception_40003=系统异常,请联系清关部门 |
| 15 | system_exception_40004=登录已过期,请重新登录 | 15 | system_exception_40004=登录已过期,请重新登录 |
| 16 | system_exception_40005=用戶不存在 | 16 | system_exception_40005=用戶不存在 |
| 17 | system_exception_40006=登录已过期 | 17 | system_exception_40006=登录已过期 |
| 18 | +system_exception_40007=退出成功 | ||
| 19 | +system_exception_40008=退出失败 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment