001package com.nimbusds.openid.connect.sdk.claims; 002 003 004import net.jcip.annotations.Immutable; 005 006import com.nimbusds.jose.JWSAlgorithm; 007 008import com.nimbusds.oauth2.sdk.token.AccessToken; 009 010 011/** 012 * Access token hash ({@code at_hash}). 013 * 014 * <p>Related specifications: 015 * 016 * <ul> 017 * <li>OpenID Connect Core 1.0, section 3.1.3.6. 018 * </ul> 019 */ 020@Immutable 021public final class AccessTokenHash extends HashClaim { 022 023 024 /** 025 * Creates a new access token hash with the specified value. 026 * 027 * @param value The access token hash value. Must not be {@code null}. 028 */ 029 public AccessTokenHash(final String value) { 030 031 super(value); 032 } 033 034 035 /** 036 * Computes the hash for the specified access token and reference JSON 037 * Web Signature (JWS) algorithm. 038 * 039 * @param accessToken The access token. Must not be {@code null}. 040 * @param alg The reference JWS algorithm. Must not be 041 * {@code null}. 042 * 043 * @return The access token hash, or {@code null} if the JWS algorithm 044 * is not supported. 045 */ 046 public static AccessTokenHash compute(final AccessToken accessToken, final JWSAlgorithm alg) { 047 048 String value = computeValue(accessToken, alg); 049 050 if (value == null) 051 return null; 052 053 return new AccessTokenHash(value); 054 } 055 056 057 @Override 058 public boolean equals(final Object object) { 059 060 return object instanceof AccessTokenHash && 061 this.toString().equals(object.toString()); 062 } 063}