com.nimbusds.jwt.JWT.serialize()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(268)

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

JWT.serialize介绍

[英]Serialises the JSON Web Token (JWT) to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters.
[中]将JSON Web令牌(JWT)序列化为压缩格式,该格式由Base64URL编码的部分组成,这些部分由句点('.')字符分隔。

代码示例

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

@Override
public String convertToDatabaseColumn(JWT attribute) {
  if (attribute != null) {
    return attribute.serialize();
  } else {
    return null;
  }
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

/**
 * Get the JWT-encoded value of this token
 */
@Override
@Transient
public String getValue() {
  return jwt.serialize();
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

/**
 * Get the string-encoded value of this access token.
 */
@Override
@Transient
public String getValue() {
  return jwtValue.serialize();
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

private void writeObject(ObjectOutputStream out) throws IOException {
  out.defaultWriteObject();
  if (idToken == null) {
    out.writeObject(null);
  } else {
    out.writeObject(idToken.serialize());
  }
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException, ParseException {

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

/**
   * Add the ID Token to the additionalInformation map for a token response.
   * @param idToken
   */
  @Transient
  public void setIdToken(JWT idToken) {
    if (idToken != null) {
      additionalInformation.put(ID_TOKEN_FIELD_NAME, idToken.serialize());
    }
  }
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

private void writeObject(ObjectOutputStream out) throws IOException {
  out.defaultWriteObject();
  if (idToken == null) {
    out.writeObject(null);
  } else {
    out.writeObject(idToken.serialize());
  }
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException, ParseException {

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

/**
 * Compute the SHA hash of a token
 *
 * @param signingAlg
 * @param token
 * @return
 */
public static Base64URL getAccessTokenHash(JWSAlgorithm signingAlg, OAuth2AccessTokenEntity token) {
  byte[] tokenBytes = token.getJwt().serialize().getBytes();
  return getHash(signingAlg, tokenBytes);
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

@Override
@Transactional(value="defaultTransactionManager")
public void clearDuplicateAccessTokens() {
  Query query = manager.createQuery("select a.jwt, count(1) as c from OAuth2AccessTokenEntity a GROUP BY a.jwt HAVING count(1) > 1");
  @SuppressWarnings("unchecked")
  List<Object[]> resultList = query.getResultList();
  List<JWT> values = new ArrayList<>();
  for (Object[] r : resultList) {
    logger.warn("Found duplicate access tokens: {}, {}", ((JWT)r[0]).serialize(), r[1]);
    values.add((JWT) r[0]);
  }
  if (values.size() > 0) {
    CriteriaBuilder cb = manager.getCriteriaBuilder();
    CriteriaDelete<OAuth2AccessTokenEntity> criteriaDelete = cb.createCriteriaDelete(OAuth2AccessTokenEntity.class);
    Root<OAuth2AccessTokenEntity> root = criteriaDelete.from(OAuth2AccessTokenEntity.class);
    criteriaDelete.where(root.get("jwt").in(values));
    int result = manager.createQuery(criteriaDelete).executeUpdate();
    logger.warn("Deleted {} duplicate access tokens", result);
  }
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

@Override
@Transactional(value="defaultTransactionManager")
public void clearDuplicateRefreshTokens() {
  Query query = manager.createQuery("select a.jwt, count(1) as c from OAuth2RefreshTokenEntity a GROUP BY a.jwt HAVING count(1) > 1");
  @SuppressWarnings("unchecked")
  List<Object[]> resultList = query.getResultList();
  List<JWT> values = new ArrayList<>();
  for (Object[] r : resultList) {
    logger.warn("Found duplicate refresh tokens: {}, {}", ((JWT)r[0]).serialize(), r[1]);
    values.add((JWT) r[0]);
  }
  if (values.size() > 0) {
    CriteriaBuilder cb = manager.getCriteriaBuilder();
    CriteriaDelete<OAuth2RefreshTokenEntity> criteriaDelete = cb.createCriteriaDelete(OAuth2RefreshTokenEntity.class);
    Root<OAuth2RefreshTokenEntity> root = criteriaDelete.from(OAuth2RefreshTokenEntity.class);
    criteriaDelete.where(root.get("jwt").in(values));
    int result = manager.createQuery(criteriaDelete).executeUpdate();
    logger.warn("Deleted {} duplicate refresh tokens", result);
  }
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

writer.name(SOFTWARE_ID).value(client.getSoftwareId());
writer.name(SOFTWARE_VERSION).value(client.getSoftwareVersion());
writer.name(SOFTWARE_STATEMENT).value(client.getSoftwareStatement() != null ? client.getSoftwareStatement().serialize() : null);
writer.name(CREATION_DATE).value(toUTCString(client.getCreatedAt()));
writer.endObject();

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

o.addProperty(SOFTWARE_STATEMENT, c.getSoftwareStatement().serialize());

代码示例来源:origin: org.mitre/openid-connect-server

/**
 * Compute the SHA hash of a token
 *
 * @param signingAlg
 * @param token
 * @return
 */
public static Base64URL getAccessTokenHash(JWSAlgorithm signingAlg, OAuth2AccessTokenEntity token) {
  byte[] tokenBytes = token.getJwt().serialize().getBytes();
  return getHash(signingAlg, tokenBytes);
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

/**
 * sign JWT token from RSA algorithm
 *
 * @param jwtClaimsSet           contains JWT body
 * @param authzReqMessageContext
 * @return signed JWT token
 * @throws IdentityOAuth2Exception
 */
@Deprecated
protected String signJWTWithRSA(JWTClaimsSet jwtClaimsSet,
                OAuthAuthzReqMessageContext authzReqMessageContext) throws IdentityOAuth2Exception {
  String signingTenantDomain = getSigningTenantDomain(authzReqMessageContext);
  return OAuth2Util.signJWTWithRSA(jwtClaimsSet, signatureAlgorithm, signingTenantDomain).serialize();
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

/**
 * sign JWT token from RSA algorithm
 *
 * @param jwtClaimsSet           contains JWT body
 * @param tokenReqMessageContext
 * @return signed JWT token
 * @throws IdentityOAuth2Exception
 */
@Deprecated
protected String signJWTWithRSA(JWTClaimsSet jwtClaimsSet,
                OAuthTokenReqMessageContext tokenReqMessageContext) throws IdentityOAuth2Exception {
  String tenantDomain = getSigningTenantDomain(tokenReqMessageContext);
  return OAuth2Util.signJWTWithRSA(jwtClaimsSet, signatureAlgorithm, tenantDomain).serialize();
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

private String getIDToken(String clientId, String spTenantDomain, JWTClaimsSet jwtClaimsSet, OAuthAppDO oAuthAppDO,
             String signingTenantDomain) throws IdentityOAuth2Exception {
  if (oAuthAppDO.isIdTokenEncryptionEnabled()) {
    setupEncryptionAlgorithms(oAuthAppDO, clientId);
    return OAuth2Util.encryptJWT(jwtClaimsSet, encryptionAlgorithm, encryptionMethod, spTenantDomain,
        clientId).serialize();
  } else {
    return OAuth2Util.signJWT(jwtClaimsSet, signatureAlgorithm, signingTenantDomain).serialize();
  }
}

代码示例来源:origin: org.mitre/openid-connect-server

@Override
@Transactional(value="defaultTransactionManager")
public void clearDuplicateAccessTokens() {
  Query query = manager.createQuery("select a.jwt, count(1) as c from OAuth2AccessTokenEntity a GROUP BY a.jwt HAVING count(1) > 1");
  @SuppressWarnings("unchecked")
  List<Object[]> resultList = query.getResultList();
  List<JWT> values = new ArrayList<>();
  for (Object[] r : resultList) {
    logger.warn("Found duplicate access tokens: {}, {}", ((JWT)r[0]).serialize(), r[1]);
    values.add((JWT) r[0]);
  }
  if (values.size() > 0) {
    CriteriaBuilder cb = manager.getCriteriaBuilder();
    CriteriaDelete<OAuth2AccessTokenEntity> criteriaDelete = cb.createCriteriaDelete(OAuth2AccessTokenEntity.class);
    Root<OAuth2AccessTokenEntity> root = criteriaDelete.from(OAuth2AccessTokenEntity.class);
    criteriaDelete.where(root.get("jwt").in(values));
    int result = manager.createQuery(criteriaDelete).executeUpdate();
    logger.warn("Deleted {} duplicate access tokens", result);
  }
}

代码示例来源:origin: org.mitre/openid-connect-server

@Override
@Transactional(value="defaultTransactionManager")
public void clearDuplicateRefreshTokens() {
  Query query = manager.createQuery("select a.jwt, count(1) as c from OAuth2RefreshTokenEntity a GROUP BY a.jwt HAVING count(1) > 1");
  @SuppressWarnings("unchecked")
  List<Object[]> resultList = query.getResultList();
  List<JWT> values = new ArrayList<>();
  for (Object[] r : resultList) {
    logger.warn("Found duplicate refresh tokens: {}, {}", ((JWT)r[0]).serialize(), r[1]);
    values.add((JWT) r[0]);
  }
  if (values.size() > 0) {
    CriteriaBuilder cb = manager.getCriteriaBuilder();
    CriteriaDelete<OAuth2RefreshTokenEntity> criteriaDelete = cb.createCriteriaDelete(OAuth2RefreshTokenEntity.class);
    Root<OAuth2RefreshTokenEntity> root = criteriaDelete.from(OAuth2RefreshTokenEntity.class);
    criteriaDelete.where(root.get("jwt").in(values));
    int result = manager.createQuery(criteriaDelete).executeUpdate();
    logger.warn("Deleted {} duplicate refresh tokens", result);
  }
}

代码示例来源:origin: org.hspconsortium.client/hspc-java-client

public ClientCredentialsAccessTokenRequest(String clientId, T clientCredentials, Scopes scopes) {
  super(clientId, clientCredentials, AccessTokenGrantType.CLIENT_CREDENTIALS);
  Validate.notNull(scopes, "Scopes must not be null");
  this.tokenRequestParams.put("scope", scopes.asParamValue());
  if (clientCredentials instanceof JWTCredentials) {
    Validate.notNull(((JWTCredentials) clientCredentials).getIssuer(), "Issuer/Client ID must not ne null");
    Validate.notNull(((JWTCredentials) clientCredentials).getSubject(), "Subject/Client ID must not ne null");
    Validate.notNull(((JWTCredentials) clientCredentials).getAudience(), "Authorization server's token URL must not ne null");
    Validate.notNull(((JWTCredentials) clientCredentials).getDuration(), "Expiration time must not ne null");
    this.tokenRequestParams.put("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
    this.tokenRequestParams.put("client_assertion", ((JWTCredentials) clientCredentials).getCredentials().serialize());
  }
}

代码示例来源:origin: org.hspconsortium/hsp-java-client

public ClientCredentialsAccessTokenRequest(String clientId, T clientCredentials, Scopes scopes) {
  super(clientId, clientCredentials, AccessTokenGrantType.CLIENT_CREDENTIALS);
  Validate.notNull(scopes, "Scopes must not be null");
  this.tokenRequestParams.put("scope", scopes.asParamValue());
  if (clientCredentials instanceof JWTCredentials) {
    Validate.notNull(((JWTCredentials) clientCredentials).getIssuer(), "Issuer/Client ID must not ne null");
    Validate.notNull(((JWTCredentials) clientCredentials).getSubject(), "Subject/Client ID must not ne null");
    Validate.notNull(((JWTCredentials) clientCredentials).getAudience(), "Authorization server's token URL must not ne null");
    Validate.notNull(((JWTCredentials) clientCredentials).getDuration(), "Expiration time must not ne null");
    this.tokenRequestParams.put("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
    this.tokenRequestParams.put("client_assertion", ((JWTCredentials) clientCredentials).getCredentials().serialize());
  }
}

代码示例来源:origin: org.pac4j/pac4j-jwt

/**
 * Generate a JWT from a claims set.
 *
 * @param claimsSet the claims set
 * @return the JWT
 */
protected String internalGenerate(final JWTClaimsSet claimsSet) {
  JWT jwt;
  // signature?
  if (signatureConfiguration == null) {
    jwt = new PlainJWT(claimsSet);
  } else {
    jwt = signatureConfiguration.sign(claimsSet);
  }
  // encryption?
  if (encryptionConfiguration != null) {
    return encryptionConfiguration.encrypt(jwt);
  } else {
    return jwt.serialize();
  }
}

相关文章