整合jwt
依赖
配置
jwt:
配置参数
package com.cyz.swagger3.config.jwt;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import java.util.List;
@Data
@ConfigurationProperties(prefix = "jwt")
@EnableConfigurationProperties({JwtProperties.class})
public class JwtProperties {
private String secret;
自定义忽略注解
package com.cyz.swagger3.config.jwt;
import java.lang.annotation.*;
jwt工具
package com.cyz.swagger3.config.jwt;
import com.cyz.swagger3.exception.BusinessException;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.Date;
@Configuration
@EnableConfigurationProperties(JwtProperties.class)
@Slf4j
public class JwtTokenUtil {
@Autowired
private JwtProperties jwtProperties;
public JwtProperties getJwtProperties() {
return jwtProperties;
}
public String getSecretKey(){