| | |
| | | package com.ruoyi.auth.controller;
|
| | |
|
| | | import java.util.Map;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.http.HttpHeaders;
|
| | | import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestHeader;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.core.constant.Constants;
|
| | | import com.ruoyi.common.core.constant.SecurityConstants;
|
| | | import com.ruoyi.common.core.domain.R;
|
| | | import com.ruoyi.common.core.utils.StringUtils;
|
| | | import com.ruoyi.system.api.RemoteLogService;
|
| | |
|
| | | /**
|
| | | * token 控制
|
| | |
| | | {
|
| | | @Autowired
|
| | | private TokenStore tokenStore;
|
| | |
|
| | | @Autowired
|
| | | private RemoteLogService remoteLogService;
|
| | |
|
| | | @DeleteMapping("/logout")
|
| | | public R<?> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader)
|
| | |
| | | // 清空 refresh token
|
| | | OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
|
| | | tokenStore.removeRefreshToken(refreshToken);
|
| | | Map<String, ?> map = accessToken.getAdditionalInformation();
|
| | | if (map.containsKey(SecurityConstants.DETAILS_USERNAME))
|
| | | {
|
| | | String username = (String) map.get(SecurityConstants.DETAILS_USERNAME);
|
| | | // 记录用户退出日志
|
| | | remoteLogService.saveLogininfor(username, Constants.LOGOUT, "退出成功");
|
| | | }
|
| | | return R.ok();
|
| | | }
|
| | | }
|