| | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.ruoyi.common.config.SsoBean; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| | | import com.alibaba.fastjson2.JSON; |
| | |
| | | |
| | | /** |
| | | * 自定义退出处理类 返回成功 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Configuration |
| | |
| | | { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | @Autowired |
| | | private SsoBean ssoBean; |
| | | |
| | | /** |
| | | * 退出处理 |
| | | * |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | throws IOException, ServletException |
| | | { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | String loginOutUrl = null; |
| | | if (StringUtils.isNotNull(loginUser)) |
| | | { |
| | | String userName = loginUser.getUsername(); |
| | | // 删除用户缓存记录 |
| | | tokenService.delLoginUser(loginUser.getToken()); |
| | | // 记录用户退出日志 |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); |
| | | // 清除单点登录信息 |
| | | Object idToken = redisTemplate.opsForValue().get("ssoOauthToken:idToken:" + userName); |
| | | if (idToken != null) { |
| | | loginOutUrl = ssoBean.getUrl() + "/oauth2/sessions/logout?id_token_hint=" + idToken; |
| | | redisTemplate.delete("ssoOauthToken:idToken:" + SecurityUtils.getUsername()); |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, MessageUtils.message("user.sso.logout.success"))); |
| | | } else { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); |
| | | } |
| | | |
| | | } |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success(MessageUtils.message("user.logout.success")))); |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success(MessageUtils.message("user.logout.success"), loginOutUrl))); |
| | | } |
| | | } |