当前位置: 首页>>代码示例>>Java>>正文


Java Jws.getBody方法代码示例

本文整理汇总了Java中io.jsonwebtoken.Jws.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java Jws.getBody方法的具体用法?Java Jws.getBody怎么用?Java Jws.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.jsonwebtoken.Jws的用法示例。


在下文中一共展示了Jws.getBody方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseRefreshToken

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
public SecurityUser parseRefreshToken(RawAccessJwtToken rawAccessToken) {
  Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
  Claims claims = jwsClaims.getBody();
  String subject = claims.getSubject();
  List<String> scopes = claims.get(SCOPES, List.class);
  if (scopes == null || scopes.isEmpty()) {
    throw new IllegalArgumentException("Refresh Token doesn't have any scopes");
  }
  if (!scopes.get(0).equals(Authority.REFRESH_TOKEN.name())) {
    throw new IllegalArgumentException("Invalid Refresh Token scope");
  }
  boolean isPublic = claims.get(IS_PUBLIC, Boolean.class);
  UserPrincipal principal = new UserPrincipal(isPublic ? UserPrincipal.Type.PUBLIC_ID : UserPrincipal.Type.USER_NAME,
      subject);
  SecurityUser securityUser = new SecurityUser(new UserId(UUID.fromString(claims.get(USER_ID, String.class))));
  securityUser.setUserPrincipal(principal);
  return securityUser;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:19,代码来源:JwtTokenFactory.java

示例2: tokenFromStringJwt

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
public JwtAuthenticationToken tokenFromStringJwt(String rawJwt) {
    DefaultJwtParser parser = ((DefaultJwtParser) Jwts.parser());
    parser.setSigningKey(signingSecret);

    try {
        Jws<Claims> jws = parser.parseClaimsJws(rawJwt);
        Claims claims = jws.getBody();


        UUID userId = UUID.fromString((String) claims.get("user_id"));
        String email = ((String) claims.get("email"));
        Collection<? extends GrantedAuthority> roles = parseRolesFromClaims(claims);

        return new JwtAuthenticationToken(userId, email, roles);
    } catch (Exception e) {
        log.info(String.format("Exception occurred parsing JWT [%s].\nException message: %s", rawJwt, e.getMessage()));
        return null;
    }
}
 
开发者ID:rpmartz,项目名称:booktrackr,代码行数:20,代码来源:JwtUtil.java

示例3: parseRefreshToken

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
public SecurityUser parseRefreshToken(RawAccessJwtToken rawAccessToken) {
    Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
    Claims claims = jwsClaims.getBody();
    String subject = claims.getSubject();
    List<String> scopes = claims.get(SCOPES, List.class);
    if (scopes == null || scopes.isEmpty()) {
        throw new IllegalArgumentException("Refresh Token doesn't have any scopes");
    }
    if (!scopes.get(0).equals(Authority.REFRESH_TOKEN.name())) {
        throw new IllegalArgumentException("Invalid Refresh Token scope");
    }
    boolean isPublic = claims.get(IS_PUBLIC, Boolean.class);
    UserPrincipal principal = new UserPrincipal(isPublic ? UserPrincipal.Type.PUBLIC_ID : UserPrincipal.Type.USER_NAME, subject);
    SecurityUser securityUser = new SecurityUser(new UserId(UUID.fromString(claims.get(USER_ID, String.class))));
    securityUser.setUserPrincipal(principal);
    return securityUser;
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:18,代码来源:JwtTokenFactory.java

示例4: hasValidSessionCookie

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public boolean hasValidSessionCookie() {
    decrypt();

    boolean valid = false;
    if (StringUtils.isNotBlank(this.value)) {
        try {
            Jws<Claims> jwsClaims = Jwts.parser()
                    .setSigningKey(this.secret)
                    .parseClaimsJws(this.value);
                
            Claims claims = jwsClaims.getBody();
            Date expiration = claims.getExpiration();
            if (expiration != null) {
                this.sessionValues = claims.get(ClaimKey.DATA.toString(), Map.class);
                this.authenticityToken = claims.get(ClaimKey.AUTHENTICITY.toString(), String.class); 
                this.expiresDate = dateToLocalDateTime(expiration); 
                valid = true;
            } 
        } catch (Exception e) { //NOSONAR
            LOG.error("Failed to parse JWS for seesion cookie", e);
        }
    }
    
    return valid;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:27,代码来源:CookieParser.java

示例5: hasValidAuthenticationCookie

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
public boolean hasValidAuthenticationCookie() {
    decrypt();

    boolean valid = false;
    if (StringUtils.isNotBlank(this.value)) {
        try {
            Jws<Claims> jwsClaims = Jwts.parser()
                    .setSigningKey(this.secret)
                    .parseClaimsJws(this.value);
                
            Claims claims = jwsClaims.getBody();
            Date expiration = claims.getExpiration();
            if (expiration != null) {
                this.authenticatedUser = claims.getSubject();
                this.twoFactor = claims.get(ClaimKey.TWO_FACTOR.toString(), Boolean.class);
                this.expiresDate = dateToLocalDateTime(expiration);
                valid = true;                        
            }  
        } catch (Exception e) { //NOSONAR
            LOG.error("Failed to parse JWS for authentication cookie", e);
        }
    }

    return valid;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:26,代码来源:CookieParser.java

示例6: parseAccessJwtToken

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
public SecurityUser parseAccessJwtToken(RawAccessJwtToken rawAccessToken) {
  Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
  Claims claims = jwsClaims.getBody();
  String subject = claims.getSubject();
  List<String> scopes = claims.get(SCOPES, List.class);
  if (scopes == null || scopes.isEmpty()) {
    throw new IllegalArgumentException("JWT Token doesn't have any scopes");
  }

  SecurityUser securityUser = new SecurityUser(new UserId(UUID.fromString(claims.get(USER_ID, String.class))));
  securityUser.setEmail(subject);
  securityUser.setAuthority(Authority.parse(scopes.get(0)));
  securityUser.setFirstName(claims.get(FIRST_NAME, String.class));
  securityUser.setLastName(claims.get(LAST_NAME, String.class));
  securityUser.setEnabled(claims.get(ENABLED, Boolean.class));
  boolean isPublic = claims.get(IS_PUBLIC, Boolean.class);
  UserPrincipal principal = new UserPrincipal(isPublic ? UserPrincipal.Type.PUBLIC_ID : UserPrincipal.Type.USER_NAME,
      subject);
  securityUser.setUserPrincipal(principal);
  String tenantId = claims.get(TENANT_ID, String.class);
  if (tenantId != null) {
    securityUser.setTenantId(new TenantId(UUID.fromString(tenantId)));
  }
  String customerId = claims.get(CUSTOMER_ID, String.class);
  if (customerId != null) {
    securityUser.setCustomerId(new CustomerId(UUID.fromString(customerId)));
  }

  return securityUser;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:31,代码来源:JwtTokenFactory.java

示例7: HonoUserImpl

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
private HonoUserImpl(final Jws<Claims> expandedToken, final String token) {
    Objects.requireNonNull(expandedToken);
    Objects.requireNonNull(token);
    if (expandedToken.getBody() == null) {
        throw new IllegalArgumentException("token has no claims");
    }
    this.token = token;
    this.expandedToken = expandedToken;
    this.authorities = AuthoritiesImpl.from(expandedToken.getBody());
}
 
开发者ID:eclipse,项目名称:hono,代码行数:11,代码来源:HonoSaslAuthenticatorFactory.java

示例8: parseAccessJwtToken

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
public SecurityUser parseAccessJwtToken(RawAccessJwtToken rawAccessToken) {
    Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
    Claims claims = jwsClaims.getBody();
    String subject = claims.getSubject();
    List<String> scopes = claims.get(SCOPES, List.class);
    if (scopes == null || scopes.isEmpty()) {
        throw new IllegalArgumentException("JWT Token doesn't have any scopes");
    }

    SecurityUser securityUser = new SecurityUser(new UserId(UUID.fromString(claims.get(USER_ID, String.class))));
    securityUser.setEmail(subject);
    securityUser.setAuthority(Authority.parse(scopes.get(0)));
    securityUser.setFirstName(claims.get(FIRST_NAME, String.class));
    securityUser.setLastName(claims.get(LAST_NAME, String.class));
    securityUser.setEnabled(claims.get(ENABLED, Boolean.class));
    boolean isPublic = claims.get(IS_PUBLIC, Boolean.class);
    UserPrincipal principal = new UserPrincipal(isPublic ? UserPrincipal.Type.PUBLIC_ID : UserPrincipal.Type.USER_NAME, subject);
    securityUser.setUserPrincipal(principal);
    String tenantId = claims.get(TENANT_ID, String.class);
    if (tenantId != null) {
        securityUser.setTenantId(new TenantId(UUID.fromString(tenantId)));
    }
    String customerId = claims.get(CUSTOMER_ID, String.class);
    if (customerId != null) {
        securityUser.setCustomerId(new CustomerId(UUID.fromString(customerId)));
    }

    return securityUser;
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:30,代码来源:JwtTokenFactory.java

示例9: decodeJwt

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
/**
 * Decodes a java web token into the DawgJwt, which can be used to retrieve the {@link DawgCreds}
 * @param jwt The jwt to decode
 * @return
 */
public DawgJwt decodeJwt(String jwt) {
    Jws<Claims> token = Jwts.parser()         
            .setSigningKey(jwtSecret.getBytes())
            .parseClaimsJws(jwt);
    Claims claims =  token.getBody();
    if (claims.containsKey(DawgJwt.JWT_FIELD_CREDS)) {
        DawgCreds serializedUser = mapper.convertValue(claims.get(DawgJwt.JWT_FIELD_CREDS, Map.class), DawgCreds.class);
        claims.put(DawgJwt.JWT_FIELD_CREDS, serializedUser);
    }
    return new DawgJwt(claims);
}
 
开发者ID:Comcast,项目名称:dawg,代码行数:17,代码来源:DawgJwtEncoder.java

示例10: getFlashCookie

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
/**
 * Retrieves the flash cookie from the current
 *
 * @param exchange The Undertow HttpServerExchange
 */
@SuppressWarnings("unchecked")
protected Flash getFlashCookie(HttpServerExchange exchange) {
    Flash flash = null;
    final String cookieValue = getCookieValue(exchange, this.config.getFlashCookieName());
    
    if (StringUtils.isNotBlank(cookieValue)) {
        try {
            Jws<Claims> jwsClaims = Jwts.parser()
                    .setSigningKey(this.config.getApplicationSecret())
                    .parseClaimsJws(cookieValue);

            Claims claims = jwsClaims.getBody();
            final Map<String, String> values = claims.get(ClaimKey.DATA.toString(), Map.class);

            if (claims.containsKey(ClaimKey.FORM.toString())) {
                this.form = CodecUtils.deserializeFromBase64(claims.get(ClaimKey.FORM.toString(), String.class));
            } 
            
            flash = new Flash(values);
            flash.setDiscard(true); 
        } catch (Exception e) { //NOSONAR
            LOG.error("Failed to parse JWT for flash cookie", e);
        }
    }
    
    return flash == null ? new Flash() : flash;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:33,代码来源:InboundCookiesHandler.java

示例11: onClaimsJws

import io.jsonwebtoken.Jws; //导入方法依赖的package包/类
@Override
public Map<String, Object> onClaimsJws(Jws<Claims> jws) {
    return jws.getBody();
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:5,代码来源:ConfigCheckingJwtHandler.java


注:本文中的io.jsonwebtoken.Jws.getBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。