fix:补全sso单点登录方法
This commit is contained in:
parent
24c5b1077e
commit
ccf975f02d
@ -2,10 +2,12 @@ package com.infinova.sso;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@RestController
|
@RestController
|
||||||
|
@EnableScheduling
|
||||||
public class SsoApplication {
|
public class SsoApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -37,6 +37,11 @@ public class JwtController {
|
|||||||
return ReturnEntity.successResult(service.checkJwt(token));
|
return ReturnEntity.successResult(service.checkJwt(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/refreshJwt")
|
||||||
|
public ReturnEntity refreshJwt(String token){
|
||||||
|
return ReturnEntity.successResult(service.refreshJwt(token));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/inValid")
|
@GetMapping("/inValid")
|
||||||
public ReturnEntity inValid(String token) {
|
public ReturnEntity inValid(String token) {
|
||||||
service.inValid(token);
|
service.inValid(token);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.infinova.sso.service;
|
package com.infinova.sso.service;
|
||||||
|
|
||||||
|
import com.auth0.jwt.interfaces.Claim;
|
||||||
import com.infinova.sso.entity.User;
|
import com.infinova.sso.entity.User;
|
||||||
import com.infinova.sso.exception.CustomException;
|
import com.infinova.sso.exception.CustomException;
|
||||||
import com.infinova.sso.util.JwtUtil;
|
import com.infinova.sso.util.JwtUtil;
|
||||||
@ -20,7 +21,6 @@ import java.util.*;
|
|||||||
* @date 2019/3/4 18:17
|
* @date 2019/3/4 18:17
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EnableScheduling
|
|
||||||
public class JwtService {
|
public class JwtService {
|
||||||
|
|
||||||
public static final String JWT_KEY = "jwt_token";
|
public static final String JWT_KEY = "jwt_token";
|
||||||
@ -60,6 +60,21 @@ public class JwtService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过期时间小于半小时,返回新的jwt,否则返回原jwt
|
||||||
|
* @param jwt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String refreshJwt(String jwt){
|
||||||
|
String secret = RedisUtil.redisTemplate.opsForValue().get(jwt);
|
||||||
|
Map<String, Claim> map = JwtUtil.decode(jwt,secret);
|
||||||
|
if(map.get("exp").asLong()*1000 - System.currentTimeMillis()/1000<30*60*1000){
|
||||||
|
return this.generateNewJwt(map.get("name").asString());
|
||||||
|
}else{
|
||||||
|
return jwt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: 生成新的jwt,并放入jwtMap中
|
* Description: 生成新的jwt,并放入jwtMap中
|
||||||
|
Loading…
x
Reference in New Issue
Block a user