请告诉我如何正确解析JWT令牌。 我需要得到角色......
static Authentication getAuthentication(HttpServletRequest request) {
String token = request.getHeader(HEADER_STRING);
if (token != null) {
// parse the token.
String user = Jwts.parser()
.setSigningKey(SECRET)
.parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
.getBody()
.getSubject();
Claims claims = Jwts.parser()
.setSigningKey(SECRET)
.parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
.getBody();
List<String> roles = (ArrayList<String>)claims.get("roles");
System.out.println("ROLE IS: " + roles);
return user != null ?
new UsernamePasswordAuthenticationToken(user, null, Collections.emptyList()) :
null;
}
return null;
}
输出ROLE IS:[{authority = ROLE_ADMIN},{authority = ROLE_USER} 如何正确地将其转换为Collection以用作UsernamePasswordAuthenticationToken中的参数。 谢谢。
答案 0 :(得分:0)
f1(df, matchval, matchfield, qfields...) = isempty(qfields)