| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.annotation.Resource; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import com.zhitan.system.domain.SysSocial; |
| | | import com.zhitan.system.service.ISysSocialService; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Value("${keycloak.server-url}") |
| | | private String keycloakServerUrl; |
| | | |
| | | @Value("${keycloak.realm}") |
| | | private String keycloakRealm; |
| | | |
| | | |
| | | @Resource |
| | | private ISysSocialService sysSocialService; |
| | | |
| | | /** |
| | | * 退出处理 |
| | | * |
| | |
| | | tokenService.delLoginUser(loginUser.getToken()); |
| | | // 记录用户退出日志 |
| | | AsyncManager.me().execute(AsyncFactory.recordLoginInfo(userName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); |
| | | SysSocial social = sysSocialService.selectByUserId(loginUser.getUserId()); |
| | | if (social == null) { |
| | | return; |
| | | } |
| | | |
| | | String logoutUrl = keycloakServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/logout"; |
| | | HttpRequest req = HttpRequest.get(logoutUrl) |
| | | .form("refresh_token", social.getRefreshToken()) |
| | | .form("id_token_hint", social.getIdToken()); |
| | | |
| | | |
| | | HttpResponse rep = req.execute(); |
| | | if (rep.isOk()) { |
| | | System.out.println("1234"); |
| | | } |
| | | } |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success(MessageUtils.message("user.logout.success")))); |
| | | } |