本文整理汇总了Java中io.jsonwebtoken.JwtBuilder.claim方法的典型用法代码示例。如果您正苦于以下问题:Java JwtBuilder.claim方法的具体用法?Java JwtBuilder.claim怎么用?Java JwtBuilder.claim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.jsonwebtoken.JwtBuilder
的用法示例。
在下文中一共展示了JwtBuilder.claim方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jwtBuilder
import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
protected JwtBuilder jwtBuilder(long exp, Map<String, Object> ext){
JwtBuilder jwt = Jwts.builder()
.claim("user_id","43FE6476-CD7B-493B-8044-C7E3149D0876")
.claim("scope","perm")
.claim("client_id","console")
.claim("username","admin");
if(ext != null){
for (Entry<String, Object> entry : ext.entrySet()){
jwt.claim(entry.getKey(),entry.getValue());
}
}
jwt.setExpiration(new Date(exp));
return jwt;
}
示例2: processAuthPermissions
import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
private static void processAuthPermissions(JwtBuilder builder, Authentication authentication) {
builder.claim(AuthenticationClaims.CLAIM_NAME_ROOT, Boolean.valueOf(authentication.isRoot()));
Collection<Permission> permissions = authentication.getPermissions();
if (permissions != null && !permissions.isEmpty()) {
Collection<String> ps = new ArrayList<>(permissions.size());
for (Permission permission : permissions) {
permission.getPermission().ifPresent(p -> ps.add(p));
}
if (!ps.isEmpty()) {
builder.claim(AuthenticationClaims.CLAIM_NAME_PERMISSIONS, ps);
}
}
}
示例3: createJwtToken
import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
private String createJwtToken(String subject, LocalDateTime tokenExpirationDateTime, boolean isRefreshToken) {
JwtBuilder jwtBuilder = Jwts.builder()
.setSubject(subject)
.signWith(SignatureAlgorithm.HS512, privateKey)
.setExpiration(toDate(tokenExpirationDateTime));
if (isRefreshToken) {
jwtBuilder.claim(REFRESH_TOKEN_CLAIM_KEY, true);
}
return jwtBuilder.compact();
}
示例4: createToken
import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
@Override
public String createToken(Authentication authentication, Boolean rememberMe) {
Optional<Authentication> auth = Optional.ofNullable(authentication);
String authorities = extractAuthorities(auth.map(Authentication::getAuthorities).orElseThrow(IllegalArgumentException::new));
Date validity = provideValidityDate(rememberMe);
String subject = auth.map(Authentication::getName).orElseThrow(IllegalArgumentException::new);
JwtBuilder jwtBuilder = Jwts.builder()
.setSubject(subject)
.signWith(SignatureAlgorithm.HS256, jwtProperties.getToken().getSecret())
.setExpiration(validity);
if (!"".equals(authorities.trim())) {
jwtBuilder.claim(jwtProperties.getToken().getPayload().getAuthoritiesKey(), authorities);
}
return jwtBuilder.compact();
}