JWTToken_参考代码

JWTToken_参考代码

参考代码如下

import com.auth0.jwt.JWT;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
@EqualsAndHashCode(of = "token")
public class JWTToken implements AuthenticationToken {

	@Getter
	private String token;

	@Getter
	private DecodedJWT decodedToken;

	public JWTToken(String token) {
		this.token = token;
		try {
			this.decodedToken = JWT.decode(token);
		} catch (JWTDecodeException e) {
			throw new AuthenticationException(e);
		}
	}
	@Override
	public DecodedJWT getPrincipal() {
		return decodedToken;
	}

	@Override
	public String getCredentials() {
		return token;
	}
}