com.nimbusds.jose.Payload类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(185)

本文整理了Java中com.nimbusds.jose.Payload类的一些代码示例,展示了Payload类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Payload类的具体详情如下:
包路径:com.nimbusds.jose.Payload
类名称:Payload

Payload介绍

[英]Payload of an unsecured (plain), JSON Web Signature (JWS) or JSON Web Encryption (JWE) object. Supports JSON object, string, byte array, Base64URL, JWS object and signed JWT payload representations. This class is immutable.

UTF-8 is the character set for all conversions between strings and byte arrays.

Conversion relations:

JSONObject <=> String <=> Base64URL 
<=> byte[] 
<=> JWSObject 
<=> SignedJWT

[中]不安全(普通)、JSON Web签名(JWS)或JSON Web加密(JWE)对象的有效负载。支持JSON对象、字符串、字节数组、Base64URL、JWS对象和签名JWT有效负载表示。这个类是不变的。
UTF-8是字符串和字节数组之间所有转换的字符集。
转换关系:

JSONObject <=> String <=> Base64URL 
<=> byte[] 
<=> JWSObject 
<=> SignedJWT

代码示例

代码示例来源:origin: google/data-transfer-project

@Override
 public AuthDataPair decrypt(String encrypted, PrivateKey privateKey) {
  try {
   RSADecrypter decrypter = new RSADecrypter(privateKey);
   JWEObject object = JWEObject.parse(encrypted);
   object.decrypt(decrypter);
   return objectMapper.readValue(object.getPayload().toString(), AuthDataPair.class);
  } catch (IOException | ParseException | JOSEException e) {
   throw new SecurityException("Error decrypting auth tokens", e);
  }
 }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Creates a new unsecured (plain) JSON Web Token (JWT) with the
 * specified header and claims set.
 *
 * @param header    The unsecured header. Must not be {@code null}.
 * @param claimsSet The JWT claims set. Must not be {@code null}.
 */
public PlainJWT(final PlainHeader header, final JWTClaimsSet claimsSet) {
  super(header, new Payload(claimsSet.toJSONObject()));
}

代码示例来源:origin: com.atlassian.jwt/jwt-core

@Nonnull
@Override
public Jwt parse(String jwt) throws JwtParseException
{
  JWSObject jwsObject = parseJWSObject(jwt);
  try
  {
    JWTClaimsSet claims = JWTClaimsSet.parse(jwsObject.getPayload().toJSONObject());
    return new SimpleJwt(claims.getIssuer(), claims.getSubject(), jwsObject.getPayload().toString());
  }
  catch (ParseException e)
  {
    throw new JwtParseException(e);
  }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Returns a byte array representation of this payload.
 *
 * @return The byte array representation.
 */
public byte[] toBytes() {
  if (bytes != null) {
    return bytes;
  }
  // Convert
  if (base64URL != null) {
    return base64URL.decode();
  }
  return stringToByteArray(toString());
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

@Override
public JWTClaimsSet getJWTClaimsSet()
  throws ParseException {
  JSONObject json = getPayload().toJSONObject();
  if (json == null) {
    
    throw new ParseException("Payload of unsecured JOSE object is not a valid JSON object", 0);
  }
  return JWTClaimsSet.parse(json);
}

代码示例来源:origin: io.gravitee.management.idp/gravitee-management-api-idp-core

public IdentityReference deserialize(String token) throws Exception {
    String sToken = new String(Base64.getDecoder().decode(token));

    // Parse the JWE string
    JWEObject jweObject = JWEObject.parse(sToken);

    // Decrypt with shared key
    jweObject.decrypt(new DirectDecrypter(secretKey.getEncoded()));

    // Extract payload
    SignedJWT signedJWT = jweObject.getPayload().toSignedJWT();

    // Check the HMAC
    signedJWT.verify(new MACVerifier(secretKey.getEncoded()));

    // Retrieve the JWT claims
    return new IdentityReference(signedJWT.getJWTClaimsSet().getIssuer(), signedJWT.getJWTClaimsSet().getSubject());
  }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Returns a Base64URL representation of this payload.
 *
 * @return The Base64URL representation.
 */
public Base64URL toBase64URL() {
  if (base64URL != null) {
    return base64URL;
  }
  // Convert
  return Base64URL.encode(toBytes());
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Creates a new to-be-encrypted JSON Web Token (JWT) with the specified
 * header and claims set. The initial state will be 
 * {@link com.nimbusds.jose.JWEObject.State#UNENCRYPTED unencrypted}.
 *
 * @param header    The JWE header. Must not be {@code null}.
 * @param claimsSet The JWT claims set. Must not be {@code null}.
 */
public EncryptedJWT(final JWEHeader header, final JWTClaimsSet claimsSet) {
  super(header, new Payload(claimsSet.toJSONObject()));
}

代码示例来源:origin: com.atlassian.jwt/jwt-core

public SimpleUnverifiedJwt parse(String jwt) throws JwtParseException
{
  JWSObject jwsObject = parseJWSObject(jwt);
  try
  {
    JWTClaimsSet claims = JWTClaimsSet.parse(jwsObject.getPayload().toJSONObject());
    return new SimpleUnverifiedJwt(jwsObject.getHeader().getAlgorithm().getName(), claims.getIssuer(), claims.getSubject(), jwsObject.getPayload().toString());
  }
  catch (ParseException e)
  {
    throw new JwtParseException(e);
  }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

@Override
public JWTClaimsSet getJWTClaimsSet()
  throws ParseException {
  JSONObject json = getPayload().toJSONObject();
  if (json == null) {
    throw new ParseException("Payload of JWS object is not a valid JSON object", 0);
  }
  return JWTClaimsSet.parse(json);
}

代码示例来源:origin: gravitee-io/gravitee-management-rest-api

public IdentityReference deserialize(String token) throws Exception {
    String sToken = new String(Base64.getDecoder().decode(token));

    // Parse the JWE string
    JWEObject jweObject = JWEObject.parse(sToken);

    // Decrypt with shared key
    jweObject.decrypt(new DirectDecrypter(secretKey.getEncoded()));

    // Extract payload
    SignedJWT signedJWT = jweObject.getPayload().toSignedJWT();

    // Check the HMAC
    signedJWT.verify(new MACVerifier(secretKey.getEncoded()));

    // Retrieve the JWT claims
    return new IdentityReference(signedJWT.getJWTClaimsSet().getIssuer(), signedJWT.getJWTClaimsSet().getSubject());
  }
}

代码示例来源:origin: de.adorsys.psd2/consent-management-lib

@Override
public Optional<DecryptedData> decryptData(byte[] data, String password) {
  try {
    SecretKey key = getSecretKey(password);
    JWEObject jweObject = JWEObject.parse(new String(data));
    JWEDecrypter decrypter = new AESDecrypter(key.getEncoded());
    jweObject.decrypt(decrypter);
    return Optional.of(new DecryptedData(jweObject.getPayload().toBytes()));
  } catch (Exception e) {
    log.error("Error encryption data. Data can't be parsed : {}", e);
  }
  return Optional.empty();
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Creates a new to-be-signed JSON Web Token (JWT) with the specified
 * header and claims set. The initial state will be 
 * {@link com.nimbusds.jose.JWSObject.State#UNSIGNED unsigned}.
 *
 * @param header    The JWS header. Must not be {@code null}.
 * @param claimsSet The JWT claims set. Must not be {@code null}.
 */
public SignedJWT(final JWSHeader header, final JWTClaimsSet claimsSet) {
  super(header, new Payload(claimsSet.toJSONObject()));
}

代码示例来源:origin: apache/knox

@Override
public String getPayload() {
 Payload payload = jwt.getPayload();
 return payload.toString();
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

@Override
public JWTClaimsSet getJWTClaimsSet()
  throws ParseException {
  Payload payload = getPayload();
  if (payload == null) {
    return null;
  }
  JSONObject json = payload.toJSONObject();
  if (json == null) {
    throw new ParseException("Payload of JWE object is not a valid JSON object", 0);
  }
  return JWTClaimsSet.parse(json);
}

代码示例来源:origin: de.adorsys.oauth/oauth-server

public static JWTClaimsSet deserialize(String serializedToken, byte[] key) {
    try {
      JWEObject jweObject = JWEObject.parse(serializedToken);
      jweObject.decrypt(new DirectDecrypter(key));
      SignedJWT signedJWT = jweObject.getPayload().toSignedJWT();
      signedJWT.verify(new MACVerifier(key));
      JWTClaimsSet jwtClaimsSet = signedJWT.getJWTClaimsSet();
      return jwtClaimsSet;
    } catch (ParseException e) {
      throw new IllegalStateException(e);
    } catch (JOSEException e) {
      throw new IllegalStateException(e);
    }
  }
}

代码示例来源:origin: adorsys/xs2a

@Override
public Optional<DecryptedData> decryptData(byte[] data, String password) {
  try {
    SecretKey key = getSecretKey(password);
    JWEObject jweObject = JWEObject.parse(new String(data));
    JWEDecrypter decrypter = new AESDecrypter(key.getEncoded());
    jweObject.decrypt(decrypter);
    return Optional.of(new DecryptedData(jweObject.getPayload().toBytes()));
  } catch (Exception e) {
    log.error("Error encryption data. Data can't be parsed : {}", e);
  }
  return Optional.empty();
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Creates a new unsecured (plain) JSON Web Token (JWT) with a default
 * {@link com.nimbusds.jose.PlainHeader} and the specified claims 
 * set.
 *
 * @param claimsSet The JWT claims set. Must not be {@code null}.
 */
public PlainJWT(final JWTClaimsSet claimsSet) {
  super(new Payload(claimsSet.toJSONObject()));
}

代码示例来源:origin: org.apache.knox/gateway-spi

@Override
public String getPayload() {
 Payload payload = jwt.getPayload();
 return payload.toString();
}

代码示例来源:origin: rancher/cattle

private Map<String, Object> getJSONObject(JOSEObject jose, boolean encrypted) throws TokenException {
  Long exp = (Long) jose.getPayload().toJSONObject().get("exp");
  if (exp != null && exp * 1000 <= System.currentTimeMillis()) {
    throw new TokenException("Expired Token");
  }
  return jose.getPayload().toJSONObject();
}

相关文章