本文整理汇总了Java中io.jsonwebtoken.JwsHeader类的典型用法代码示例。如果您正苦于以下问题:Java JwsHeader类的具体用法?Java JwsHeader怎么用?Java JwsHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JwsHeader类属于io.jsonwebtoken包,在下文中一共展示了JwsHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseTokenFromBase64EncodedString
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
private Jws<Claims> parseTokenFromBase64EncodedString(final String base64EncodedToken) throws JwtException {
try {
return Jwts.parser().setSigningKeyResolver(new SigningKeyResolverAdapter() {
@Override
public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) {
final String identity = claims.getSubject();
// Get the key based on the key id in the claims
final String keyId = claims.get(KEY_ID_CLAIM, String.class);
final Key key = keyService.getKey(keyId);
// Ensure we were able to find a key that was previously issued by this key service for this user
if (key == null || key.getKey() == null) {
throw new UnsupportedJwtException("Unable to determine signing key for " + identity + " [kid: " + keyId + "]");
}
return key.getKey().getBytes(StandardCharsets.UTF_8);
}
}).parseClaimsJws(base64EncodedToken);
} catch (final MalformedJwtException | UnsupportedJwtException | SignatureException | ExpiredJwtException | IllegalArgumentException e) {
// TODO: Exercise all exceptions to ensure none leak key material to logs
final String errorMessage = "Unable to validate the access token.";
throw new JwtException(errorMessage, e);
}
}
示例2: signClaims
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
static private String signClaims(Claims claims)
{
// Header
Map<String, Object> header = new HashMap<>();
header.put(Header.TYPE, Header.JWT_TYPE);
header.put(JwsHeader.ALGORITHM, signatureAlgorithm);
// Signature key
Key key = new SecretKeySpec(getSecretKey(),
signatureAlgorithm.getJcaName());
String ret = Jwts.builder().
setHeader(header).
setClaims(claims).
signWith(signatureAlgorithm, key).
compact();
return ret;
}
示例3: CreateAssertionToken
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
public String CreateAssertionToken() {
Date now = new Date();
// no need to have a long-lived token (clock skew should be accounted for on the server-side)
Date expires = new Date(now.getTime() + 10000 /* 10 seconds */);
return Jwts.builder()
.setHeaderParam("typ", "JWT")
.setHeaderParam(JwsHeader.X509_CERT_SHA1_THUMBPRINT, thumbprint)
.setHeaderParam(JwsHeader.KEY_ID, thumbprint)
.setIssuer(clientId)
.setSubject(clientId)
.setAudience(tokenEndpointUri)
.setId(UUID.randomUUID().toString())
.setIssuedAt(now)
.setNotBefore(now)
.setExpiration(expires)
.signWith(SignatureAlgorithm.RS256, key)
.compact();
}
示例4: getRegistrationRequest
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
@SuppressWarnings("serial")
protected String getRegistrationRequest(final KeyPair userKey, final String nonce, final String agreement, final String[] contacts) {
return Jwts.builder()
.setHeaderParam(NONCE_KEY, nonce)
.setHeaderParam(JwsHeader.JSON_WEB_KEY, JWKUtils.getWebKey(userKey.getPublic()))
.setClaims(new TreeMap<String, Object>(){{
put(RESOURCE_KEY, RESOURCE_NEW_REG);
if (contacts != null && contacts.length > 0){
put(CONTACT_KEY, contacts);
}
if (agreement != null){
put(AGREEMENT_KEY, agreement);
}
}})
.signWith(getJWSSignatureAlgorithm(), userKey.getPrivate())
.compact();
}
示例5: getBody
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
private static Claims getBody(String jwt) {
return Jwts.parser()
.setSigningKeyResolver(new SigningKeyResolverAdapter() {
@Override
public Key resolveSigningKey(JwsHeader header, Claims claims) {
String subject = claims.getSubject();
if (subject == null || subject.isEmpty())
throw new MissingClaimException(header, claims, "Subject is not provided in JWT.");
if (!userToKeyMap.containsKey(subject))
throw new SignatureException("Signing key is not reqistred for the subject.");
return userToKeyMap.get(subject);
}})
.parseClaimsJws(jwt)
.getBody();
}
示例6: generateJwt
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
private String generateJwt() throws GeneralSecurityException {
PrivateKey privateKey = SecurityKeyUtils.parseRSAPrivateKey(TEST_PRIVATE_KEY);
Map<String, String> userInfo = buildUserInfo();
return Jwts.builder()
.setHeaderParam(JwsHeader.TYPE, JwsHeader.JWT_TYPE)
.claim(Claims.ISSUER, "Symphony Communication Services LLC.")
.claim(Claims.SUBJECT, "symphony-user-id")
.claim(Claims.AUDIENCE, "app-id")
.claim("user", userInfo)
.claim(Claims.EXPIRATION, System.currentTimeMillis() + 10000)
.signWith(SignatureAlgorithm.RS512, privateKey)
.compact();
}
示例7: generateUnsignedJwt
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
private String generateUnsignedJwt() throws GeneralSecurityException {
Map<String, String> userInfo = buildUserInfo();
return Jwts.builder()
.setHeaderParam(JwsHeader.TYPE, JwsHeader.JWT_TYPE)
.claim(Claims.ISSUER, "Symphony Communication Services LLC.")
.claim(Claims.SUBJECT, "symphony-user-id")
.claim(Claims.AUDIENCE, "app-id")
.claim("user", userInfo)
.claim(Claims.EXPIRATION, System.currentTimeMillis() + 10000)
.compact();
}
示例8: resolveSigningKey
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
@Override
public Key resolveSigningKey(JwsHeader header, Claims claims) {
Key result = delegate.resolveSigningKey(header, claims);
if (result == null) {
result = this.fallbackKey;
}
return result;
}
示例9: resolveSigningKeyBytes
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
@Override
public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) {
final SignatureAlgorithm inputAlgorithm = SignatureAlgorithm.forName(header.getAlgorithm());
if (!this.requiredAlgorithm.equals(inputAlgorithm)) {
throw new UnsupportedJwtException("Invalid algorithm");
}
return signatureKey;
}
示例10: getExpiration
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
/**
* Gets the value of the <em>exp</em> claim of a JWT.
*
* @param token The token.
* @return The expiration.
* @throws NullPointerException if the token is {@code null}.
* @throws IllegalArgumentException if the given token contains no <em>exp</em> claim.
*/
public static final Date getExpiration(final String token) {
if (token == null) {
throw new NullPointerException("token must not be null");
}
final AtomicReference<Date> result = new AtomicReference<>();
try {
Jwts.parser().setSigningKeyResolver(new SigningKeyResolverAdapter() {
@SuppressWarnings("rawtypes")
@Override
public Key resolveSigningKey(JwsHeader header, Claims claims) {
Date exp = claims.getExpiration();
if (exp != null) {
result.set(exp);
}
return DUMMY_KEY;
}
}).parse(token);
} catch (JwtException e) {
// expected since we do not know the signing key
}
if (result.get() == null) {
throw new IllegalArgumentException("token contains no exp claim");
} else {
return result.get();
}
}
示例11: getAuthorizationRequest
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
@SuppressWarnings("serial")
protected String getAuthorizationRequest(final KeyPair userKey, final String nextNonce, final String domain) {
return Jwts.builder()
.setHeaderParam(NONCE_KEY, nextNonce)
.setHeaderParam(JwsHeader.JSON_WEB_KEY, JWKUtils.getWebKey(userKey.getPublic()))
.setClaims(new TreeMap<String, Object>(){{
put(RESOURCE_KEY, RESOURCE_NEW_AUTHZ);
put(IDENTIFIER_KEY, new TreeMap<String, Object>(){{
put(IDENTIFIER_TYPE_KEY, IDENTIFIER_TYPE_DNS);
put(IDENTIFIER_VALUE_KEY, domain);
}});
}})
.signWith(getJWSSignatureAlgorithm(), userKey.getPrivate())
.compact();
}
示例12: getNewCertificateRequest
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
@SuppressWarnings("serial")
protected String getNewCertificateRequest(final KeyPair userKey, final String nonce, final PKCS10CertificationRequest csr) throws IOException {
return Jwts.builder()
.setHeaderParam(NONCE_KEY, nonce)
.setHeaderParam(JwsHeader.JSON_WEB_KEY, JWKUtils.getWebKey(userKey.getPublic()))
.setClaims(new TreeMap<String, Object>(){{
put(RESOURCE_KEY, RESOURCE_NEW_CERT);
put(CSR_KEY, TextCodec.BASE64URL.encode(csr.getEncoded()));
}})
.signWith(getJWSSignatureAlgorithm(), userKey.getPrivate())
.compact();
}
示例13: getHTTP01ChallengeRequest
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
@SuppressWarnings("serial")
protected String getHTTP01ChallengeRequest(final KeyPair userKey, final String token, final String nonce) {
return Jwts.builder()
.setHeaderParam(NONCE_KEY, nonce)
.setHeaderParam(JwsHeader.JSON_WEB_KEY, JWKUtils.getWebKey(userKey.getPublic()))
.setClaims(new TreeMap<String, Object>(){{
put(RESOURCE_KEY, RESOURCE_CHALLENGE);
put(CHALLENGE_TYPE_KEY, CHALLENGE_TYPE_HTTP_01);
put(CHALLENGE_TLS_KEY, true);
put(CHALLENGE_KEY_AUTHORIZATION_KEY, getHTTP01ChallengeContent(userKey, token));
put(CHALLENGE_TOKEN_KEY, token);
}})
.signWith(getJWSSignatureAlgorithm(), userKey.getPrivate())
.compact();
}
示例14: getUpdateRegistrationRequest
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
@SuppressWarnings("serial")
protected String getUpdateRegistrationRequest(final KeyPair userKey, final String nonce, final String agreement, final String[] contacts) {
return Jwts.builder()
.setHeaderParam(NONCE_KEY, nonce)
.setHeaderParam(JwsHeader.JSON_WEB_KEY, JWKUtils.getWebKey(userKey.getPublic()))
.setClaims(new TreeMap<String, Object>(){{
put(RESOURCE_KEY, RESOURCE_UPDATE_REGISTRATION);
if (contacts != null && contacts.length > 0){
put(CONTACT_KEY, contacts);
}
put(AGREEMENT_KEY, agreement);
}})
.signWith(getJWSSignatureAlgorithm(), userKey.getPrivate())
.compact();
}
示例15: DefaultJws
import io.jsonwebtoken.JwsHeader; //导入依赖的package包/类
public DefaultJws(JwsHeader header, B body, String signature) {
this.header = header;
this.body = body;
this.signature = signature;
}