mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-03 02:56:09 +00:00
若依 2.0
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -9,8 +10,11 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
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 控制
|
||||
@@ -24,6 +28,9 @@ public class TokenController
|
||||
@Autowired
|
||||
private TokenStore tokenStore;
|
||||
|
||||
@Autowired
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
@DeleteMapping("/logout")
|
||||
public R<?> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader)
|
||||
{
|
||||
@@ -45,6 +52,13 @@ public class TokenController
|
||||
// 清空 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();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.auth.handler;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.security.domain.LoginUser;
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
|
||||
/**
|
||||
* 认证成功处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class AuthenticationSuccessEventHandler implements ApplicationListener<AuthenticationSuccessEvent>
|
||||
{
|
||||
@Autowired
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(AuthenticationSuccessEvent event)
|
||||
{
|
||||
Authentication authentication = (Authentication) event.getSource();
|
||||
if (StringUtils.isNotEmpty(authentication.getAuthorities())
|
||||
&& authentication.getPrincipal() instanceof LoginUser)
|
||||
{
|
||||
LoginUser user = (LoginUser) authentication.getPrincipal();
|
||||
|
||||
String username = user.getUsername();
|
||||
|
||||
// 记录用户登录日志
|
||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user