gpt4 book ai didi

java - Spring - 未找到 JWTParser(String)

转载 作者:行者123 更新时间:2023-11-30 08:19:00 24 4
gpt4 key购买 nike

我在 Spring 中有一个基于 token 的身份验证方案。但 JWTParser 似乎很麻烦。下面代码中的 JWTParser 类到底做了什么?另外,我无法导入这个类。

public class JWTAuthenticationToken extends AbstractAuthenticationToken {
private static final long serialVersionUID = 1L;
private final Object principal;
private Object details;

Collection authorities;

public JWTAuthenticationToken( String jwtToken ) {
super( null );
super.setAuthenticated( true ); // must use super, as we override
JWTParser parser = new JWTParser( jwtToken );

this.principal = parser.getSub();

this.setDetailsAuthorities();

}

@Override
public Object getCredentials() {
return "";
}

@Override
public Object getPrincipal() {
return principal;
}

private void setDetailsAuthorities() {
String username = principal.toString();
SpringUserDetailsAdapter adapter = new SpringUserDetailsAdapter( username );
details = adapter;
authorities = ( Collection ) adapter.getAuthorities();

}

@Override
public Collection getAuthorities() {
return authorities;
}
}

有什么解决办法吗?

最佳答案

JwtParser parser =new  DefaultJwtParser();
parser.parse(jwtToken);

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>

关于java - Spring - 未找到 JWTParser(String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29232360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com