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;
	}
}

 

相关文章:

  • 2022-12-23
  • 2021-11-18
  • 2021-09-04
  • 2021-08-17
  • 2021-11-12
  • 2021-08-13
  • 2021-08-11
猜你喜欢
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2022-01-27
  • 2022-12-23
相关资源
相似解决方案