Bootstrap

JAVA语言(JwtToken校验、过滤器)

JwtToken校验:

import org.apache.shiro.authc.AuthenticationToken

public class JwtToken implements AuthenticationToken{
   
	private String token;
	public JwtToken (String token){
   
		this.token=token;
	}
	
	@Override
	public Object getPrincipal(){
   
		return token;
	}
	
	@Override
	public Object getCredentials(){
   
		return token;
	}
}
//------------------------调用JWTUtils.sign方法加盐加密账号密码--------------------------------------------
import cn.hutool.core.util.StrUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.UUID;
/**
 * @ClassName: JWTUtils
 * @Description:
 * @Authour:yrc
 * @Data:2021/10/28 15:30
 * @Version:1.0
 **/
public class JWTUtils {
   
    private static final long EXPIRE_TIME = 60 * 60 * 1000 * 24;

    /**
     * 生成签名
     * @param username 用户名
     * @param secret   用户的密码
     * @return 加密的token
     */
    public static String sign(String username, String secret) {
   
        Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
        Algorithm algorithm &#
;