master
parent
46da4c00a3
commit
29e015aa8b
|
|
@ -15,7 +15,6 @@ import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||||
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import com.boot.security.server.dto.LoginUser;
|
import com.boot.security.server.dto.LoginUser;
|
||||||
import com.boot.security.server.dto.ResponseInfo;
|
import com.boot.security.server.dto.ResponseInfo;
|
||||||
|
|
@ -42,15 +41,8 @@ public class SecurityHandlerConfig {
|
||||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
||||||
Authentication authentication) throws IOException, ServletException {
|
Authentication authentication) throws IOException, ServletException {
|
||||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||||
Token token = null;
|
|
||||||
String _token = tokenService.getTokenByUserId(loginUser.getId());
|
|
||||||
if (!StringUtils.isEmpty(_token)) {
|
|
||||||
token = Token.builder().token(_token).build();
|
|
||||||
tokenService.addExpireTime(loginUser);
|
|
||||||
} else {
|
|
||||||
token = tokenService.saveToken(loginUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Token token = tokenService.saveToken(loginUser);
|
||||||
ResponseUtil.responseJson(response, HttpStatus.OK.value(), token);
|
ResponseUtil.responseJson(response, HttpStatus.OK.value(), token);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.boot.security.server.dto.LoginUser;
|
import com.boot.security.server.dto.LoginUser;
|
||||||
import com.boot.security.server.dto.Token;
|
import com.boot.security.server.dto.Token;
|
||||||
|
|
@ -28,6 +29,11 @@ public class TokenServiceImpl implements TokenService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token saveToken(LoginUser loginUser) {
|
public Token saveToken(LoginUser loginUser) {
|
||||||
|
String oldToken = idTokenRedisTemplate.opsForValue().get(loginUser.getId());
|
||||||
|
if (!StringUtils.isEmpty(oldToken)) {
|
||||||
|
deleteToken(oldToken);
|
||||||
|
}
|
||||||
|
|
||||||
String token = UUID.randomUUID().toString();
|
String token = UUID.randomUUID().toString();
|
||||||
loginUser.setToken(token);
|
loginUser.setToken(token);
|
||||||
updateLoginUser(loginUser);
|
updateLoginUser(loginUser);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue